]> granicus.if.org Git - python/commitdiff
bpo-35601: Alleviate race condition when waiting for SIGALRM in test_asyncio (GH...
authorPablo Galindo <Pablogsal@gmail.com>
Sat, 29 Dec 2018 01:40:21 +0000 (01:40 +0000)
committerGitHub <noreply@github.com>
Sat, 29 Dec 2018 01:40:21 +0000 (01:40 +0000)
There is a race condition regarding signal delivery in test_signal_handling_args for
test_asyncio.test_events.KqueueEventLoopTests. The signal can be received at any moment outside the time window provided in the test. The fix is to wait for the signal to be received instead with a bigger timeout.

Lib/test/test_asyncio/test_events.py

index 9311a209f23e32838ee608e8c16ea7ef6cc25012..a2b954eec4ad792751d66b452e660b49306948a0 100644 (file)
@@ -475,6 +475,7 @@ class EventLoopTestsMixin:
         self.loop.add_signal_handler(signal.SIGALRM, my_handler)
 
         signal.setitimer(signal.ITIMER_REAL, 0.01, 0)  # Send SIGALRM once.
+        self.loop.call_later(60, self.loop.stop)
         self.loop.run_forever()
         self.assertEqual(caught, 1)
 
@@ -487,11 +488,12 @@ class EventLoopTestsMixin:
             nonlocal caught
             caught += 1
             self.assertEqual(args, some_args)
+            self.loop.stop()
 
         self.loop.add_signal_handler(signal.SIGALRM, my_handler, *some_args)
 
         signal.setitimer(signal.ITIMER_REAL, 0.1, 0)  # Send SIGALRM once.
-        self.loop.call_later(0.5, self.loop.stop)
+        self.loop.call_later(60, self.loop.stop)
         self.loop.run_forever()
         self.assertEqual(caught, 1)