[Python-checkins] python/dist/src/Lib/test test_subprocess.py, 1.7, 1.8

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Wed Oct 13 05:43:42 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19774/Lib/test

Modified Files:
	test_subprocess.py 
Log Message:
Kill several problems at once:  test_poll() failed sometimes for me.
Turns out the mysterious "expected output" file contained exactly N dots,
because test_poll() has a loop that *usually* went around N times,
printing one dot on each loop trip.  But there's no guarantee of that,
because the exact value of N depended on the vagaries of scheduling
time.sleep()s across two different processes.  So stopped printing dots,
and got rid of the expected output file.  Add a loop counter instead,
and verify that the loop goes around at least a couple of times.  Also
cut the minimum time needed for this test from 4 seconds to 1.


Index: test_subprocess.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_subprocess.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- test_subprocess.py	13 Oct 2004 03:29:54 -0000	1.7
+++ test_subprocess.py	13 Oct 2004 03:43:40 -0000	1.8
@@ -56,7 +56,7 @@
 
     def test_stdout_none(self):
         # .stdout is None when not redirected
-        p = subprocess.Popen([sys.executable, "-c", 
+        p = subprocess.Popen([sys.executable, "-c",
                              'print "    this bit of output is from a '
                              'test of stdout in a different '
                              'process ..."'],
@@ -350,11 +350,16 @@
 
     def test_poll(self):
         p = subprocess.Popen([sys.executable,
-                          "-c", "import time; time.sleep(4)"])
-        while p.poll() == None:
-            sys.stdout.write(".")
-            sys.stdout.flush()
-            time.sleep(0.5)
+                          "-c", "import time; time.sleep(1)"])
+        count = 0
+        while p.poll() is None:
+            time.sleep(0.1)
+            count += 1
+        # We expect that the poll loop probably went around about 10 times,
+        # but, based on system scheduling we can't control, it's possible
+        # poll() never returned None.  It "should be" very rare that it
+        # didn't go around at least twice.
+        self.assert_(count >= 2)
         # Subsequent invocations should just return the returncode
         self.assertEqual(p.poll(), 0)
 



More information about the Python-checkins mailing list