diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-31 19:46:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-31 19:46:40 (GMT) |
commit | 27c6231f5827fe17c6cb6f097391931f30b511ec (patch) | |
tree | b0f36e377cd2f3a0c7f2b9c08e26eaa51047fdb5 /Lib/test/test_fork1.py | |
parent | 278c1e159c970da6cd6683d18c6211f5118674cc (diff) | |
download | cpython-27c6231f5827fe17c6cb6f097391931f30b511ec.zip cpython-27c6231f5827fe17c6cb6f097391931f30b511ec.tar.gz cpython-27c6231f5827fe17c6cb6f097391931f30b511ec.tar.bz2 |
bpo-40094: Enhance fork and wait tests (GH-19259)
* test_fork1: remove duplicated wait_impl() method: reuse
fork_wait.py implementation instead.
* Use exit code different than 0 to ensure that we executed the
expected code path.
Diffstat (limited to 'Lib/test/test_fork1.py')
-rw-r--r-- | Lib/test/test_fork1.py | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/Lib/test/test_fork1.py b/Lib/test/test_fork1.py index ce0a05a..a2f7cfe 100644 --- a/Lib/test/test_fork1.py +++ b/Lib/test/test_fork1.py @@ -17,19 +17,6 @@ from test import support support.get_attribute(os, 'fork') class ForkTest(ForkWait): - def wait_impl(self, cpid): - deadline = time.monotonic() + support.SHORT_TIMEOUT - while time.monotonic() <= deadline: - # waitpid() shouldn't hang, but some of the buildbots seem to hang - # in the forking tests. This is an attempt to fix the problem. - spid, status = os.waitpid(cpid, os.WNOHANG) - if spid == cpid: - break - time.sleep(0.1) - - self.assertEqual(spid, cpid) - self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) - def test_threaded_import_lock_fork(self): """Check fork() in main thread works while a subthread is doing an import""" import_started = threading.Event() @@ -46,6 +33,7 @@ class ForkTest(ForkWait): t = threading.Thread(target=importer) t.start() import_started.wait() + exitcode = 42 pid = os.fork() try: # PyOS_BeforeFork should have waited for the import to complete @@ -54,7 +42,7 @@ class ForkTest(ForkWait): if not pid: m = __import__(fake_module_name) if m == complete_module: - os._exit(0) + os._exit(exitcode) else: if support.verbose > 1: print("Child encountered partial module") @@ -64,7 +52,7 @@ class ForkTest(ForkWait): # Exitcode 1 means the child got a partial module (bad.) No # exitcode (but a hang, which manifests as 'got pid 0') # means the child deadlocked (also bad.) - self.wait_impl(pid) + self.wait_impl(pid, exitcode=exitcode) finally: try: os.kill(pid, signal.SIGKILL) @@ -74,6 +62,7 @@ class ForkTest(ForkWait): def test_nested_import_lock_fork(self): """Check fork() in main thread works while the main thread is doing an import""" + exitcode = 42 # Issue 9573: this used to trigger RuntimeError in the child process def fork_with_import_lock(level): release = 0 @@ -95,8 +84,8 @@ class ForkTest(ForkWait): os._exit(1) raise if in_child: - os._exit(0) - self.wait_impl(pid) + os._exit(exitcode) + self.wait_impl(pid, exitcode=exitcode) # Check this works with various levels of nested # import in the main thread |