summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2004-10-13 03:43:40 (GMT)
committerTim Peters <tim.peters@gmail.com>2004-10-13 03:43:40 (GMT)
commit29b6b4f7c75121a69e260753e1b8befaee3b06df (patch)
tree04a2b62533aa512927c1248ae77ba573ad37606a /Lib
parent4052fe5a9bb5de0e142f138c00a263d2fe44f552 (diff)
downloadcpython-29b6b4f7c75121a69e260753e1b8befaee3b06df.zip
cpython-29b6b4f7c75121a69e260753e1b8befaee3b06df.tar.gz
cpython-29b6b4f7c75121a69e260753e1b8befaee3b06df.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/output/test_subprocess2
-rw-r--r--Lib/test/test_subprocess.py17
2 files changed, 11 insertions, 8 deletions
diff --git a/Lib/test/output/test_subprocess b/Lib/test/output/test_subprocess
deleted file mode 100644
index effbcf0..0000000
--- a/Lib/test/output/test_subprocess
+++ /dev/null
@@ -1,2 +0,0 @@
-test_subprocess
-......... \ No newline at end of file
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 6f498b8..c4bc3d0 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -56,7 +56,7 @@ class ProcessTestCase(unittest.TestCase):
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 @@ class ProcessTestCase(unittest.TestCase):
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)