Commit a5f91458 authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #12041: Make test_wait3 more robust.

parent 304d8437
...@@ -43,6 +43,7 @@ class ForkWait(unittest.TestCase): ...@@ -43,6 +43,7 @@ class ForkWait(unittest.TestCase):
self.assertEqual(spid, cpid) self.assertEqual(spid, cpid)
self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
@support.reap_threads
def test_wait(self): def test_wait(self):
for i in range(NUM_THREADS): for i in range(NUM_THREADS):
_thread.start_new(self.f, (i,)) _thread.start_new(self.f, (i,))
...@@ -69,7 +70,8 @@ class ForkWait(unittest.TestCase): ...@@ -69,7 +70,8 @@ class ForkWait(unittest.TestCase):
os._exit(n) os._exit(n)
else: else:
# Parent # Parent
self.wait_impl(cpid) try:
# Tell threads to die self.wait_impl(cpid)
self.stop = 1 finally:
time.sleep(2*SHORTSLEEP) # Wait for threads to die # Tell threads to die
self.stop = 1
...@@ -19,13 +19,16 @@ except AttributeError: ...@@ -19,13 +19,16 @@ except AttributeError:
class Wait3Test(ForkWait): class Wait3Test(ForkWait):
def wait_impl(self, cpid): def wait_impl(self, cpid):
for i in range(10): # This many iterations can be required, since some previously run
# tests (e.g. test_ctypes) could have spawned a lot of children
# very quickly.
for i in range(30):
# wait3() shouldn't hang, but some of the buildbots seem to hang # wait3() shouldn't hang, but some of the buildbots seem to hang
# in the forking tests. This is an attempt to fix the problem. # in the forking tests. This is an attempt to fix the problem.
spid, status, rusage = os.wait3(os.WNOHANG) spid, status, rusage = os.wait3(os.WNOHANG)
if spid == cpid: if spid == cpid:
break break
time.sleep(1.0) time.sleep(0.1)
self.assertEqual(spid, cpid) self.assertEqual(spid, cpid)
self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
......
...@@ -619,6 +619,8 @@ Extension Modules ...@@ -619,6 +619,8 @@ Extension Modules
Tests Tests
----- -----
- Issue #12041: Make test_wait3 more robust.
- Issue #11873: Change regex in test_compileall to fix occasional failures when - Issue #11873: Change regex in test_compileall to fix occasional failures when
when the randomly generated temporary path happened to match the regex. when the randomly generated temporary path happened to match the regex.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment