summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-03-31 10:18:35 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-03-31 10:18:35 (GMT)
commit80d84c89ee8f10cd3a5d1dfa2ea1cd51f810ec33 (patch)
treeeb155114bc072c4d0627a4e423b0aee4f6731ace /Lib/test
parentd5d818d40b9378488dc82150926e20e925acf7fe (diff)
parentb31017331994abcc6af3ce2febfc33593c3d7fec (diff)
downloadcpython-80d84c89ee8f10cd3a5d1dfa2ea1cd51f810ec33.zip
cpython-80d84c89ee8f10cd3a5d1dfa2ea1cd51f810ec33.tar.gz
cpython-80d84c89ee8f10cd3a5d1dfa2ea1cd51f810ec33.tar.bz2
Merge heads
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/eintrdata/eintr_tester.py26
-rw-r--r--Lib/test/test_selectors.py37
2 files changed, 58 insertions, 5 deletions
diff --git a/Lib/test/eintrdata/eintr_tester.py b/Lib/test/eintrdata/eintr_tester.py
index 0df9762..f755880 100644
--- a/Lib/test/eintrdata/eintr_tester.py
+++ b/Lib/test/eintrdata/eintr_tester.py
@@ -315,8 +315,8 @@ class SelectEINTRTest(EINTRBaseTest):
def test_select(self):
t0 = time.monotonic()
select.select([], [], [], self.sleep_time)
- self.stop_alarm()
dt = time.monotonic() - t0
+ self.stop_alarm()
self.assertGreaterEqual(dt, self.sleep_time)
@unittest.skipUnless(hasattr(select, 'poll'), 'need select.poll')
@@ -325,8 +325,8 @@ class SelectEINTRTest(EINTRBaseTest):
t0 = time.monotonic()
poller.poll(self.sleep_time * 1e3)
- self.stop_alarm()
dt = time.monotonic() - t0
+ self.stop_alarm()
self.assertGreaterEqual(dt, self.sleep_time)
@unittest.skipUnless(hasattr(select, 'epoll'), 'need select.epoll')
@@ -336,8 +336,30 @@ class SelectEINTRTest(EINTRBaseTest):
t0 = time.monotonic()
poller.poll(self.sleep_time)
+ dt = time.monotonic() - t0
+ self.stop_alarm()
+ self.assertGreaterEqual(dt, self.sleep_time)
+
+ @unittest.skipUnless(hasattr(select, 'kqueue'), 'need select.kqueue')
+ def test_kqueue(self):
+ kqueue = select.kqueue()
+ self.addCleanup(kqueue.close)
+
+ t0 = time.monotonic()
+ kqueue.control(None, 1, self.sleep_time)
+ dt = time.monotonic() - t0
self.stop_alarm()
+ self.assertGreaterEqual(dt, self.sleep_time)
+
+ @unittest.skipUnless(hasattr(select, 'devpoll'), 'need select.devpoll')
+ def test_devpoll(self):
+ poller = select.devpoll()
+ self.addCleanup(poller.close)
+
+ t0 = time.monotonic()
+ poller.poll(self.sleep_time * 1e3)
dt = time.monotonic() - t0
+ self.stop_alarm()
self.assertGreaterEqual(dt, self.sleep_time)
diff --git a/Lib/test/test_selectors.py b/Lib/test/test_selectors.py
index 9521481..454c17b 100644
--- a/Lib/test/test_selectors.py
+++ b/Lib/test/test_selectors.py
@@ -357,7 +357,35 @@ class BaseSelectorTestCase(unittest.TestCase):
@unittest.skipUnless(hasattr(signal, "alarm"),
"signal.alarm() required for this test")
- def test_select_interrupt(self):
+ def test_select_interrupt_exc(self):
+ s = self.SELECTOR()
+ self.addCleanup(s.close)
+
+ rd, wr = self.make_socketpair()
+
+ class InterruptSelect(Exception):
+ pass
+
+ def handler(*args):
+ raise InterruptSelect
+
+ orig_alrm_handler = signal.signal(signal.SIGALRM, handler)
+ self.addCleanup(signal.signal, signal.SIGALRM, orig_alrm_handler)
+ self.addCleanup(signal.alarm, 0)
+
+ signal.alarm(1)
+
+ s.register(rd, selectors.EVENT_READ)
+ t = time()
+ # select() is interrupted by a signal which raises an exception
+ with self.assertRaises(InterruptSelect):
+ s.select(30)
+ # select() was interrupted before the timeout of 30 seconds
+ self.assertLess(time() - t, 5.0)
+
+ @unittest.skipUnless(hasattr(signal, "alarm"),
+ "signal.alarm() required for this test")
+ def test_select_interrupt_noraise(self):
s = self.SELECTOR()
self.addCleanup(s.close)
@@ -371,8 +399,11 @@ class BaseSelectorTestCase(unittest.TestCase):
s.register(rd, selectors.EVENT_READ)
t = time()
- self.assertFalse(s.select(2))
- self.assertLess(time() - t, 2.5)
+ # select() is interrupted by a signal, but the signal handler doesn't
+ # raise an exception, so select() should by retries with a recomputed
+ # timeout
+ self.assertFalse(s.select(1.5))
+ self.assertGreaterEqual(time() - t, 1.0)
class ScalableSelectorMixIn: