[Python-checkins] cpython: Issue #12041: Make test_wait3 more robust.

antoine.pitrou python-checkins at python.org
Mon May 9 21:17:25 CEST 2011


http://hg.python.org/cpython/rev/9e473917cbfb
changeset:   69991:9e473917cbfb
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Mon May 09 21:17:02 2011 +0200
summary:
  Issue #12041: Make test_wait3 more robust.

files:
  Lib/test/fork_wait.py  |  10 ++++++----
  Lib/test/test_wait3.py |   7 +++++--
  Misc/NEWS              |   2 ++
  3 files changed, 13 insertions(+), 6 deletions(-)


diff --git a/Lib/test/fork_wait.py b/Lib/test/fork_wait.py
--- a/Lib/test/fork_wait.py
+++ b/Lib/test/fork_wait.py
@@ -43,6 +43,7 @@
         self.assertEqual(spid, cpid)
         self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
 
+    @support.reap_threads
     def test_wait(self):
         for i in range(NUM_THREADS):
             _thread.start_new(self.f, (i,))
@@ -69,7 +70,8 @@
             os._exit(n)
         else:
             # Parent
-            self.wait_impl(cpid)
-            # Tell threads to die
-            self.stop = 1
-            time.sleep(2*SHORTSLEEP) # Wait for threads to die
+            try:
+                self.wait_impl(cpid)
+            finally:
+                # Tell threads to die
+                self.stop = 1
diff --git a/Lib/test/test_wait3.py b/Lib/test/test_wait3.py
--- a/Lib/test/test_wait3.py
+++ b/Lib/test/test_wait3.py
@@ -19,13 +19,16 @@
 
 class Wait3Test(ForkWait):
     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
             # in the forking tests.  This is an attempt to fix the problem.
             spid, status, rusage = os.wait3(os.WNOHANG)
             if spid == cpid:
                 break
-            time.sleep(1.0)
+            time.sleep(0.1)
 
         self.assertEqual(spid, cpid)
         self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -619,6 +619,8 @@
 Tests
 -----
 
+- Issue #12041: Make test_wait3 more robust.
+
 - Issue #11873: Change regex in test_compileall to fix occasional failures when
   when the randomly generated temporary path happened to match the regex.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list