summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavide Rizzo <sorcio@gmail.com>2023-09-21 21:20:29 (GMT)
committerGitHub <noreply@github.com>2023-09-21 21:20:29 (GMT)
commit608c1f3083ea1e06d383ef1a9878a9758903de4b (patch)
treec4d378bf0ffa4931175c38a85b4800c98d9243ee
parent2aceb21ae61b4648b47afd9f8fdba8c106a745d0 (diff)
downloadcpython-608c1f3083ea1e06d383ef1a9878a9758903de4b.zip
cpython-608c1f3083ea1e06d383ef1a9878a9758903de4b.tar.gz
cpython-608c1f3083ea1e06d383ef1a9878a9758903de4b.tar.bz2
gh-109582: test_fork_signal_handling should wait for event (#109605)
Sometimes the child_handled event was missing because either the child quits before it gets a chance to handle the signal, or the parent asserts before the event notification is delivered via IPC. Synchronize explicitly to avoid this.
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index cdf3eaa..7322be5 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -11,9 +11,11 @@ import socket
import stat
import sys
import threading
+import time
import unittest
from unittest import mock
import warnings
+from test import support
from test.support import os_helper
from test.support import socket_helper
from test.support import wait_process
@@ -1911,8 +1913,14 @@ class TestFork(unittest.IsolatedAsyncioTestCase):
parent_handled = manager.Event()
def child_main():
- signal.signal(signal.SIGTERM, lambda *args: child_handled.set())
+ def on_sigterm(*args):
+ child_handled.set()
+ sys.exit()
+
+ signal.signal(signal.SIGTERM, on_sigterm)
child_started.set()
+ while True:
+ time.sleep(1)
async def main():
loop = asyncio.get_running_loop()
@@ -1922,7 +1930,7 @@ class TestFork(unittest.IsolatedAsyncioTestCase):
process.start()
child_started.wait()
os.kill(process.pid, signal.SIGTERM)
- process.join()
+ process.join(timeout=support.SHORT_TIMEOUT)
async def func():
await asyncio.sleep(0.1)
@@ -1933,6 +1941,7 @@ class TestFork(unittest.IsolatedAsyncioTestCase):
asyncio.run(main())
+ child_handled.wait(timeout=support.SHORT_TIMEOUT)
self.assertFalse(parent_handled.is_set())
self.assertTrue(child_handled.is_set())