summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_selectors.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_selectors.py')
-rw-r--r--Lib/test/test_selectors.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_selectors.py b/Lib/test/test_selectors.py
index 852b2fe..f2594a6 100644
--- a/Lib/test/test_selectors.py
+++ b/Lib/test/test_selectors.py
@@ -175,6 +175,33 @@ class BaseSelectorTestCase(unittest.TestCase):
self.assertFalse(s.register.called)
self.assertFalse(s.unregister.called)
+ def test_modify_unregister(self):
+ # Make sure the fd is unregister()ed in case of error on
+ # modify(): http://bugs.python.org/issue30014
+ if self.SELECTOR.__name__ == 'EpollSelector':
+ patch = unittest.mock.patch(
+ 'selectors.EpollSelector._selector_cls')
+ elif self.SELECTOR.__name__ == 'PollSelector':
+ patch = unittest.mock.patch(
+ 'selectors.PollSelector._selector_cls')
+ elif self.SELECTOR.__name__ == 'DevpollSelector':
+ patch = unittest.mock.patch(
+ 'selectors.DevpollSelector._selector_cls')
+ else:
+ raise self.skipTest("")
+
+ with patch as m:
+ m.return_value.modify = unittest.mock.Mock(
+ side_effect=ZeroDivisionError)
+ s = self.SELECTOR()
+ self.addCleanup(s.close)
+ rd, wr = self.make_socketpair()
+ s.register(rd, selectors.EVENT_READ)
+ self.assertEqual(len(s._map), 1)
+ with self.assertRaises(ZeroDivisionError):
+ s.modify(rd, selectors.EVENT_WRITE)
+ self.assertEqual(len(s._map), 0)
+
def test_close(self):
s = self.SELECTOR()
self.addCleanup(s.close)