diff -r 077dce5c4196 Lib/test/_test_multiprocessing.py --- a/Lib/test/_test_multiprocessing.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/_test_multiprocessing.py Thu Mar 13 14:15:22 2014 +0100 @@ -296,7 +296,7 @@ class _TestProcess(BaseTestCase): self.assertEqual(p.is_alive(), True) # XXX maybe terminating too soon causes the problems on Gentoo... - time.sleep(1) + time.sleep(test.support.TEST_SLEEP) p.terminate() @@ -965,7 +965,7 @@ class _TestCondition(BaseTestCase): self.assertEqual(state.value, 0) for i in range(4): - time.sleep(0.01) + time.sleep(test.support.TEST_SHORT_SLEEP) with cond: state.value += 1 cond.notify() @@ -1002,7 +1002,7 @@ class _TestCondition(BaseTestCase): # Only increment 3 times, so state == 4 is never reached. for i in range(3): - time.sleep(0.01) + time.sleep(test.support.TEST_SHORT_SLEEP) with cond: state.value += 1 cond.notify() @@ -1014,7 +1014,7 @@ class _TestCondition(BaseTestCase): def _test_wait_result(cls, c, pid): with c: c.notify() - time.sleep(1) + time.sleep(test.support.TEST_SLEEP) if pid is not None: os.kill(pid, signal.SIGINT) @@ -1114,7 +1114,7 @@ class _DummyList(object): def _wait(): # A crude wait/yield function not relying on synchronization primitives. - time.sleep(0.01) + time.sleep(test.support.TEST_SHORT_SLEEP) class Bunch(object): @@ -1286,7 +1286,7 @@ class _TestBarrier(BaseTestCase): if i == cls.N//2: # Wait until the other threads are all in the barrier. while barrier.n_waiting < cls.N-1: - time.sleep(0.001) + time.sleep(test.support.TEST_SHORT_SLEEP) barrier.reset() else: try: @@ -1353,9 +1353,9 @@ class _TestBarrier(BaseTestCase): i = barrier.wait() if i == cls.N//2: # One thread is late! - time.sleep(1.0) + time.sleep(test.support.TEST_SLEEP * 2) try: - barrier.wait(0.5) + barrier.wait(test.support.TEST_SLEEP) except threading.BrokenBarrierError: results.append(True) @@ -1372,7 +1372,7 @@ class _TestBarrier(BaseTestCase): i = barrier.wait(cls.defaultTimeout) if i == cls.N//2: # One thread is later than the default timeout - time.sleep(1.0) + time.sleep(test.support.TEST_SLEEP * 2) try: barrier.wait() except threading.BrokenBarrierError: @@ -1382,7 +1382,7 @@ class _TestBarrier(BaseTestCase): """ Test the barrier's default timeout """ - barrier = self.Barrier(self.N, timeout=0.5) + barrier = self.Barrier(self.N, timeout=test.support.TEST_SLEEP) results = self.DummyList() self.run_threads(self._test_default_timeout_f, (barrier, results)) self.assertEqual(len(results), barrier.parties) @@ -2083,7 +2083,7 @@ class _TestManagerRestart(BaseTestCase): raise # Retry after some time, in case the old socket was lingering # (sporadic failure on buildbots) - time.sleep(1.0) + time.sleep(test.support.TEST_SLEEP) manager = QueueManager( address=addr, authkey=authkey, serializer=SERIALIZER) manager.shutdown() @@ -2161,7 +2161,7 @@ class _TestConnection(BaseTestCase): self.assertTimingAlmostEqual(poll.elapsed, TIMEOUT1) conn.send(None) - time.sleep(.1) + time.sleep(test.support.TEST_SHORT_SLEEP) self.assertEqual(poll(TIMEOUT1), True) self.assertTimingAlmostEqual(poll.elapsed, 0) @@ -2406,7 +2406,7 @@ class _TestListenerClient(BaseTestCase): p = self.Process(target=self._test, args=(l.address,)) p.daemon = True p.start() - time.sleep(1) + time.sleep(test.support.TEST_SLEEP) # On Windows the client process should by now have connected, # written data and closed the pipe handle by now. This causes # ConnectNamdedPipe() to fail with ERROR_NO_DATA. See Issue @@ -2442,7 +2442,7 @@ class _TestPoll(BaseTestCase): @classmethod def _child_strings(cls, conn, strings): for s in strings: - time.sleep(0.1) + time.sleep(test.support.TEST_SHORT_SLEEP) conn.send_bytes(s) conn.close() @@ -2454,7 +2454,7 @@ class _TestPoll(BaseTestCase): for s in strings: for i in range(200): - if a.poll(0.01): + if a.poll(test.support.TEST_SHORT_SLEEP): break x = a.recv_bytes() self.assertEqual(s, x) @@ -2473,7 +2473,7 @@ class _TestPoll(BaseTestCase): r, w = self.Pipe(False) p = self.Process(target=self._child_boundaries, args=(r,)) p.start() - time.sleep(2) + time.sleep(test.support.TEST_SLEEP) L = [b"first", b"second"] for obj in L: w.send_bytes(obj) @@ -2947,7 +2947,7 @@ class _TestPollEintr(BaseTestCase): @classmethod def _killer(cls, pid): - time.sleep(0.1) + time.sleep(test.support.TEST_SLEEP) os.kill(pid, signal.SIGUSR1) @unittest.skipUnless(hasattr(signal, 'SIGUSR1'), 'requires SIGUSR1') @@ -3355,7 +3355,7 @@ class TestFlags(unittest.TestCase): class TestTimeouts(unittest.TestCase): @classmethod def _test_timeout(cls, child, address): - time.sleep(1) + time.sleep(test.support.TEST_SLEEP) child.send(123) child.close() conn = multiprocessing.connection.Client(address) @@ -3522,15 +3522,15 @@ class TestIgnoreEINTR(unittest.TestCase) p.start() child_conn.close() self.assertEqual(conn.recv(), 'ready') - time.sleep(0.1) + time.sleep(test.support.TEST_SLEEP) os.kill(p.pid, signal.SIGUSR1) - time.sleep(0.1) + time.sleep(test.support.TEST_SLEEP) conn.send(1234) self.assertEqual(conn.recv(), 1234) - time.sleep(0.1) + time.sleep(test.support.TEST_SLEEP) os.kill(p.pid, signal.SIGUSR1) self.assertEqual(conn.recv_bytes(), b'x'*(1024*1024)) - time.sleep(0.1) + time.sleep(test.support.TEST_SLEEP) p.join() finally: conn.close() @@ -3555,9 +3555,9 @@ class TestIgnoreEINTR(unittest.TestCase) p.start() child_conn.close() address = conn.recv() - time.sleep(0.1) + time.sleep(test.support.TEST_SLEEP) os.kill(p.pid, signal.SIGUSR1) - time.sleep(0.1) + time.sleep(test.support.TEST_SLEEP) client = multiprocessing.connection.Client(address) self.assertEqual(client.recv(), 'welcome') p.join() @@ -3815,7 +3815,7 @@ def install_tests_in_module_dict(remote_ def tearDownModule(): multiprocessing.set_start_method(old_start_method[0], force=True) # pause a bit so we don't get warning about dangling threads/processes - time.sleep(0.5) + time.sleep(test.support.TEST_SLEEP) multiprocessing.process._cleanup() gc.collect() tmp = set(multiprocessing.process._dangling) - set(dangling[0]) diff -r 077dce5c4196 Lib/test/fork_wait.py --- a/Lib/test/fork_wait.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/fork_wait.py Thu Mar 13 14:15:22 2014 +0100 @@ -13,8 +13,8 @@ import os, sys, time, unittest import test.support as support _thread = support.import_module('_thread') -LONGSLEEP = 2 -SHORTSLEEP = 0.5 +LONGSLEEP = support.TEST_SLEEP * 4 +SHORTSLEEP = support.TEST_SLEEP NUM_THREADS = 4 class ForkWait(unittest.TestCase): @@ -38,7 +38,7 @@ class ForkWait(unittest.TestCase): spid, status = os.waitpid(cpid, os.WNOHANG) if spid == cpid: break - time.sleep(2 * SHORTSLEEP) + time.sleep(SHORTSLEEP) self.assertEqual(spid, cpid) self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) diff -r 077dce5c4196 Lib/test/lock_tests.py --- a/Lib/test/lock_tests.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/lock_tests.py Thu Mar 13 14:15:22 2014 +0100 @@ -13,7 +13,7 @@ from test import support def _wait(): # A crude wait/yield function not relying on synchronization primitives. - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) class Bunch(object): """ @@ -159,7 +159,7 @@ class BaseLockTests(BaseTestCase): # target function has finished running, but the Thread is still # alive and registered. Avoid spurious failures by waiting a # bit more (seen on a buildbot). - time.sleep(0.4) + time.sleep(support.TEST_SLEEP) self.assertEqual(n, len(threading.enumerate())) def test_timeout(self): @@ -378,7 +378,7 @@ class EventTests(BaseTestCase): results.append(evt.wait(1)) b = Bunch(f, N) b.wait_for_started() - time.sleep(0.5) + time.sleep(support.TEST_SLEEP) evt.set() evt.clear() b.wait_for_finished() @@ -521,7 +521,7 @@ class ConditionTests(BaseTestCase): b = Bunch(f, 1) b.wait_for_started() for i in range(4): - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) with cond: state += 1 cond.notify() @@ -543,7 +543,7 @@ class ConditionTests(BaseTestCase): b.wait_for_started() # Only increment 3 times, so state == 4 is never reached. for i in range(3): - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) with cond: state += 1 cond.notify() @@ -810,7 +810,7 @@ class BarrierTests(BaseTestCase): if i == self.N//2: # Wait until the other threads are all in the barrier. while self.barrier.n_waiting < self.N-1: - time.sleep(0.001) + time.sleep(support.TEST_SHORT_SLEEP) self.barrier.reset() else: try: @@ -870,10 +870,10 @@ class BarrierTests(BaseTestCase): i = self.barrier.wait() if i == self.N // 2: # One thread is late! - time.sleep(1.0) + time.sleep(support.TEST_SLEEP * 2) # Default timeout is 2.0, so this is shorter. self.assertRaises(threading.BrokenBarrierError, - self.barrier.wait, 0.5) + self.barrier.wait, support.TEST_SLEEP) self.run_threads(f) def test_default_timeout(self): @@ -881,12 +881,12 @@ class BarrierTests(BaseTestCase): Test the barrier's default timeout """ # create a barrier with a low default timeout - barrier = self.barriertype(self.N, timeout=0.3) + barrier = self.barriertype(self.N, timeout=support.TEST_SLEEP) def f(): i = barrier.wait() if i == self.N // 2: - # One thread is later than the default timeout of 0.3s. - time.sleep(1.0) + # One thread is later than the default timeout. + time.sleep(support.TEST_SLEEP * 2) self.assertRaises(threading.BrokenBarrierError, barrier.wait) self.run_threads(f) diff -r 077dce5c4196 Lib/test/regrtest.py --- a/Lib/test/regrtest.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/regrtest.py Thu Mar 13 14:15:22 2014 +0100 @@ -322,6 +322,11 @@ def _create_parser(): group.add_argument('-F', '--forever', action='store_true', help='run the specified tests in a loop, until an ' 'error happens') + group.add_argument('--test-sleep', type=float, + help='delay in seconds used in tests requiring a sleep ' + 'to wait for an event (50 ms by default); ' + 'check_time_delta() adds TEST_SLEEP * 2 ' + 'to the maximum delta (1 ms by default)') parser.add_argument('args', nargs=argparse.REMAINDER, help=argparse.SUPPRESS) @@ -420,6 +425,12 @@ def _parse_args(args, **kwargs): ns.use_resources.append(r) if ns.random_seed is not None: ns.randomize = True + if ns.test_sleep is not None: + if ns.test_sleep <= 1e-9: + parser.error("--test-sleep must be > 1e-9") + support.TEST_SLEEP = ns.test_sleep + support.TEST_SHORT_SLEEP = ns.test_sleep / 50 + support.check_time_delta.test_sleep = ns.test_sleep * 2 return ns diff -r 077dce5c4196 Lib/test/support/__init__.py --- a/Lib/test/support/__init__.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/support/__init__.py Thu Mar 13 14:15:22 2014 +0100 @@ -2174,3 +2174,70 @@ def run_in_subinterp(code): "memory allocations") import _testcapi return _testcapi.run_in_subinterp(code) + +def _format_time_delta(dt): + abs_dt = abs(dt) + if abs_dt < 1e-9: + # abs(dt) < 1e-9 + return '%.1f ns' % (dt * 1e9) + if abs_dt < 1e-6: + # 1e-9 < abs(dt) < 1e-6 + return '%.1f ns' % (dt * 1e9) + if abs_dt < 1e-3: + # 1e-6 < abs(dt) < 1e-3 + return '%.1f us' % (dt * 1e6) + if abs_dt < 1.0: + # 1e-3 < abs(dt) < 1.0 + return '%.1f ms' % (dt * 1e3) + # 1.0 < abs(dt) + return '%.0f sec' % dt + +# Some tests need to call time.sleep() to wait an event. This variable +# is used to configure the sleep depending on the speed of the buildbot. +# Low value makes the test faster, high value makes the test more reliable. +# The value must be > 0.0. +TEST_SLEEP = 0.050 + +# Similar to TEST_SLEEP, but shorter. It is usually used to "yield" the process +# to give the CPU to another process or another thread. +TEST_SHORT_SLEEP = 0.001 + +def check_time_delta(min_dt, dt, max_dt, *, clock='time', resolution=None): + if max_dt < min_dt: + raise ValueError("check_time_delta requires max_dt >= min_dt") + + if min_dt <= dt <= max_dt: + return + + if resolution is not None: + message = ("use a resolution of %s" + % (clock, _format_time_delta(resolution))) + else: + clock_info = time.get_clock_info(clock) + resolution = clock_info.resolution + message = ("the clock %r has a resolution of %s" + % (clock, _format_time_delta(resolution))) + + message = ("%s; tolerate %s seconds" + % (message, + _format_time_delta(check_time_delta.slow_buildbot))) + + min_dt2 = min_dt - resolution + max_dt2 = max_dt + resolution + check_time_delta.slow_buildbot + if min_dt2 <= dt <= max_dt2: + return + + if dt <= max_dt2: + # dt < min_dt <= max_dt + raise AssertionError("timing %s seconds < min timing %s seconds; %s" + % (_format_time_delta(dt), + _format_time_delta(min_dt), + message)) + else: + # min_dt <= max_dt < dt + raise AssertionError("timing %s seconds > max timing %s seconds; %s" + % (_format_time_delta(dt), + _format_time_delta(max_dt), + message)) + +check_time_delta.slow_buildbot = 0.001 diff -r 077dce5c4196 Lib/test/test_asynchat.py --- a/Lib/test/test_asynchat.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_asynchat.py Thu Mar 13 14:15:22 2014 +0100 @@ -56,7 +56,7 @@ if threading: # the client closes the channel when it's done sending while self.buffer: n = conn.send(self.buffer[:self.chunk_size]) - time.sleep(0.001) + time.sleep(support.TEST_SHORT_SLEEP) self.buffer = self.buffer[n:] except: pass @@ -96,7 +96,7 @@ if threading: s.start() event.wait() event.clear() - time.sleep(0.01) # Give server time to start accepting. + time.sleep(support.TEST_SHORT_SLEEP) # Give server time to start accepting. return s, event @@ -117,7 +117,7 @@ class TestAsynchat(unittest.TestCase): s.start() event.wait() event.clear() - time.sleep(0.01) # Give server time to start accepting. + time.sleep(support.TEST_SHORT_SLEEP) # Give server time to start accepting. c = echo_client(term, s.port) c.push(b"hello ") c.push(b"world" + term) diff -r 077dce5c4196 Lib/test/test_asyncio/test_base_events.py --- a/Lib/test/test_asyncio/test_base_events.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_asyncio/test_base_events.py Thu Mar 13 14:15:22 2014 +0100 @@ -7,7 +7,7 @@ import sys import time import unittest from unittest import mock -from test.support import IPV6_ENABLED +from test.support import IPV6_ENABLED, check_time_delta import asyncio from asyncio import base_events @@ -130,11 +130,7 @@ class BaseEventLoopTests(unittest.TestCa self.loop.run_forever() dt = self.loop.time() - t0 - # 50 ms: maximum granularity of the event loop - self.assertGreaterEqual(dt, delay - 0.050, dt) - # tolerate a difference of +800 ms because some Python buildbots - # are really slow - self.assertLessEqual(dt, 0.9, dt) + check_time_delta(delay, dt, delay + 0.1, clock='monotonic') def test_run_once_in_executor_handle(self): def cb(): diff -r 077dce5c4196 Lib/test/test_asyncore.py --- a/Lib/test/test_asyncore.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_asyncore.py Thu Mar 13 14:15:22 2014 +0100 @@ -83,7 +83,7 @@ def capture_server(evt, buf, serv): buf.write(data.replace(b'\n', b'')) if b'\n' in data: break - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) conn.close() finally: @@ -373,7 +373,7 @@ class DispatcherWithSendTests(unittest.T try: # wait a little longer for the server to initialize (it sometimes # refuses connections on slow machines without this wait) - time.sleep(0.2) + time.sleep(support.TEST_SLEEP) data = b"Suppose there isn't a 16-ton weight?" d = dispatcherwithsend_noread() @@ -381,7 +381,7 @@ class DispatcherWithSendTests(unittest.T d.connect((HOST, port)) # give time for socket to connect - time.sleep(0.1) + time.sleep(support.TEST_SLEEP / 5) d.send(data) d.send(data) diff -r 077dce5c4196 Lib/test/test_capi.py --- a/Lib/test/test_capi.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_capi.py Thu Mar 13 14:15:22 2014 +0100 @@ -447,7 +447,7 @@ class TestThreadState(unittest.TestCase) _testcapi._test_thread_state(callback) a = b = callback - time.sleep(1) + time.sleep(support.TEST_SLEEP) # Check our main thread is in the list exactly 3 times. self.assertEqual(idents.count(threading.get_ident()), 3, "Couldn't find main thread correctly in the list") diff -r 077dce5c4196 Lib/test/test_concurrent_futures.py --- a/Lib/test/test_concurrent_futures.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_concurrent_futures.py Thu Mar 13 14:15:22 2014 +0100 @@ -624,7 +624,7 @@ class FutureTests(unittest.TestCase): # TODO(brian@sweetapp.com): This test is timing dependant. def notification(): # Wait until the main thread is waiting for the result. - time.sleep(1) + time.sleep(test.support.TEST_SLEEP) f1.set_result(42) f1 = create_future(state=PENDING) @@ -637,7 +637,7 @@ class FutureTests(unittest.TestCase): # TODO(brian@sweetapp.com): This test is timing dependant. def notification(): # Wait until the main thread is waiting for the result. - time.sleep(1) + time.sleep(test.support.TEST_SLEEP) f1.cancel() f1 = create_future(state=PENDING) @@ -662,7 +662,7 @@ class FutureTests(unittest.TestCase): def test_exception_with_success(self): def notification(): # Wait until the main thread is waiting for the exception. - time.sleep(1) + time.sleep(test.support.TEST_SLEEP) with f1._condition: f1._state = FINISHED f1._exception = OSError() diff -r 077dce5c4196 Lib/test/test_docxmlrpc.py --- a/Lib/test/test_docxmlrpc.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_docxmlrpc.py Thu Mar 13 14:15:22 2014 +0100 @@ -89,7 +89,7 @@ class DocXMLRPCHTTPGETServer(unittest.Te # wait for port to be assigned n = 1000 while n > 0 and PORT is None: - time.sleep(0.001) + time.sleep(support.TEST_SHORT_SLEEP) n -= 1 self.client = http.client.HTTPConnection("localhost:%d" % PORT) diff -r 077dce5c4196 Lib/test/test_faulthandler.py --- a/Lib/test/test_faulthandler.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_faulthandler.py Thu Mar 13 14:15:22 2014 +0100 @@ -17,7 +17,7 @@ try: except ImportError: HAVE_THREADS = False -TIMEOUT = 0.5 +TIMEOUT = support.TEST_SLEEP def expected_traceback(lineno1, lineno2, header, min_count=1): regex = header diff -r 077dce5c4196 Lib/test/test_file_eintr.py --- a/Lib/test/test_file_eintr.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_file_eintr.py Thu Mar 13 14:15:22 2014 +0100 @@ -56,7 +56,7 @@ class TestFileIOSignalInterrupt(unittest after killing it to gather additional output. """ if self._process.poll() is None: - time.sleep(0.1) # give it time to finish printing the error. + time.sleep(support.TEST_SLEEP) # give it time to finish printing the error. try: self._process.terminate() # Ensure it dies. except OSError: diff -r 077dce5c4196 Lib/test/test_fork1.py --- a/Lib/test/test_fork1.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_fork1.py Thu Mar 13 14:15:22 2014 +0100 @@ -8,6 +8,7 @@ import sys import time from test.fork_wait import ForkWait +from test import support from test.support import (run_unittest, reap_children, get_attribute, import_module, verbose) @@ -24,7 +25,7 @@ class ForkTest(ForkWait): spid, status = os.waitpid(cpid, os.WNOHANG) if spid == cpid: break - time.sleep(1.0) + time.sleep(support.TEST_SLEEP) self.assertEqual(spid, cpid) self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) @@ -39,7 +40,7 @@ class ForkTest(ForkWait): imp.acquire_lock() sys.modules[fake_module_name] = partial_module import_started.set() - time.sleep(0.01) # Give the other thread time to try and acquire. + time.sleep(support.TEST_SHORT_SLEEP) # Give the other thread time to try and acquire. sys.modules[fake_module_name] = complete_module imp.release_lock() t = threading.Thread(target=importer) diff -r 077dce5c4196 Lib/test/test_ftplib.py --- a/Lib/test/test_ftplib.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_ftplib.py Thu Mar 13 14:15:22 2014 +0100 @@ -729,7 +729,7 @@ class TestFTPClass(TestCase): self.fail('Exception not raised') # needed to give the threaded server some time to set the attribute # which otherwise would still be == 'noop' - time.sleep(0.1) + time.sleep(support.TEST_SLEEP) self.assertEqual(self.server.handler_instance.last_received_cmd, 'quit') self.assertFalse(is_client_connected()) diff -r 077dce5c4196 Lib/test/test_gc.py --- a/Lib/test/test_gc.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_gc.py Thu Mar 13 14:15:22 2014 +0100 @@ -1,4 +1,5 @@ import unittest +from test import support from test.support import (verbose, refcount_test, run_unittest, strip_python_stderr, cpython_only) from test.script_helper import assert_python_ok, make_script, temp_dir @@ -361,7 +362,7 @@ class GCTests(unittest.TestCase): try: yield finally: - time.sleep(0.000001) + time.sleep(support.TEST_SHORT_SLEEP) class C(list): # Appending to a list is atomic, which avoids the use of a lock. @@ -404,7 +405,7 @@ class GCTests(unittest.TestCase): threads.append(t) for t in threads: t.start() - time.sleep(1.0) + time.sleep(support.TEST_SLEEP) exit = True for t in threads: t.join() diff -r 077dce5c4196 Lib/test/test_io.py --- a/Lib/test/test_io.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_io.py Thu Mar 13 14:15:22 2014 +0100 @@ -998,7 +998,7 @@ class BufferedReaderTest(unittest.TestCa threads = [threading.Thread(target=f) for x in range(20)] for t in threads: t.start() - time.sleep(0.02) # yield + time.sleep(support.TEST_SHORT_SLEEP) # yield for t in threads: t.join() self.assertFalse(errors, @@ -1321,7 +1321,7 @@ class BufferedWriterTest(unittest.TestCa threads = [threading.Thread(target=f) for x in range(20)] for t in threads: t.start() - time.sleep(0.02) # yield + time.sleep(support.TEST_SHORT_SLEEP) # yield for t in threads: t.join() self.assertFalse(errors, @@ -2559,7 +2559,7 @@ class TextIOWrapperTest(unittest.TestCas for x in range(20)] for t in threads: t.start() - time.sleep(0.02) + time.sleep(support.TEST_SHORT_SLEEP) event.set() for t in threads: t.join() diff -r 077dce5c4196 Lib/test/test_kqueue.py --- a/Lib/test/test_kqueue.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_kqueue.py Thu Mar 13 14:15:22 2014 +0100 @@ -135,7 +135,7 @@ class TestKQueue(unittest.TestCase): events = kq.control(None, 4, 1) if len(events) == 4: break - time.sleep(1.0) + time.sleep(support.TEST_SLEEP) else: self.fail('timeout waiting for event notifications') diff -r 077dce5c4196 Lib/test/test_logging.py --- a/Lib/test/test_logging.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_logging.py Thu Mar 13 14:15:22 2014 +0100 @@ -40,6 +40,7 @@ import struct import sys import tempfile from test.script_helper import assert_python_ok +from test import support from test.support import (captured_stdout, run_with_locale, run_unittest, patch, requires_zlib, TestHandler, Matcher) import textwrap @@ -592,7 +593,7 @@ class HandlerTest(BaseTest): self.deletion_time = time.time() except OSError: pass - time.sleep(0.004 * random.randint(0, 4)) + time.sleep(support.TEST_SHORT_SLEEP * random.randint(0, 4)) del_count = 500 log_count = 500 @@ -611,7 +612,7 @@ class HandlerTest(BaseTest): h.setFormatter(f) try: for _ in range(log_count): - time.sleep(0.005) + time.sleep(support.TEST_SHORT_SLEEP) r = logging.makeLogRecord({'msg': 'testing' }) try: self.handle_time = time.time() diff -r 077dce5c4196 Lib/test/test_os.py --- a/Lib/test/test_os.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_os.py Thu Mar 13 14:15:22 2014 +0100 @@ -1498,7 +1498,7 @@ class Win32KillTests(unittest.TestCase): if buf.value: self.assertEqual(msg, buf.value.decode()) break - time.sleep(0.1) + time.sleep(support.TEST_SLEEP) count += 1 else: self.fail("Did not receive communication from the subprocess") @@ -1528,7 +1528,7 @@ class Win32KillTests(unittest.TestCase): while count < max and proc.poll() is None: if m[0] == 1: break - time.sleep(0.1) + time.sleep(support.TEST_SLEEP) count += 1 else: # Forcefully kill the process if we weren't able to signal it. @@ -1537,7 +1537,7 @@ class Win32KillTests(unittest.TestCase): os.kill(proc.pid, event) # proc.send_signal(event) could also be done here. # Allow time for the signal to be passed and the process to exit. - time.sleep(0.5) + time.sleep(support.TEST_SLEEP) if not proc.poll(): # Forcefully kill the process if we weren't able to signal it. os.kill(proc.pid, signal.SIGINT) @@ -1895,7 +1895,7 @@ if threading is not None: def wait(self): # wait for handler connection to be closed, then stop the server while not getattr(self.handler_instance, "closed", False): - time.sleep(0.001) + time.sleep(support.TEST_SHORT_SLEEP) self.stop() # --- internals diff -r 077dce5c4196 Lib/test/test_poll.py --- a/Lib/test/test_poll.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_poll.py Thu Mar 13 14:15:22 2014 +0100 @@ -10,6 +10,7 @@ except ImportError: threading = None import time import unittest +from test import support from test.support import TESTFN, run_unittest, reap_threads, cpython_only try: @@ -196,7 +197,7 @@ class PollTests(unittest.TestCase): t = threading.Thread(target=pollster.poll) t.start() try: - time.sleep(0.5) + time.sleep(support.TEST_SLEEP) # trigger ufds array reallocation for fd in rfds: pollster.unregister(fd) diff -r 077dce5c4196 Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_pydoc.py Thu Mar 13 14:15:22 2014 +0100 @@ -755,7 +755,7 @@ class PydocServerTest(unittest.TestCase) timeout = 1 #seconds while serverthread.serving: - time.sleep(.01) + time.sleep(test.support.TEST_SHORT_SLEEP) if serverthread.serving and time.time() - starttime > timeout: serverthread.stop() break diff -r 077dce5c4196 Lib/test/test_queue.py --- a/Lib/test/test_queue.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_queue.py Thu Mar 13 14:15:22 2014 +0100 @@ -28,7 +28,7 @@ class _TriggerThread(threading.Thread): # sleep here (I aimed at 10 seconds for blocking functions -- # they should never actually wait that long - they should make # progress as soon as we call self.fn()). - time.sleep(0.1) + time.sleep(support.TEST_SLEEP) self.startedEvent.set() self.fn(*self.args) diff -r 077dce5c4196 Lib/test/test_random.py --- a/Lib/test/test_random.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_random.py Thu Mar 13 14:15:22 2014 +0100 @@ -20,7 +20,7 @@ class TestBasicOps: def test_autoseed(self): self.gen.seed() state1 = self.gen.getstate() - time.sleep(0.1) + time.sleep(support.TEST_SLEEP) self.gen.seed() # diffent seeds at different times state2 = self.gen.getstate() self.assertNotEqual(state1, state2) diff -r 077dce5c4196 Lib/test/test_resource.py --- a/Lib/test/test_resource.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_resource.py Thu Mar 13 14:15:22 2014 +0100 @@ -62,7 +62,7 @@ class ResourceTest(unittest.TestCase): # an attempt to ensure the file is really synced and # the exception raised. for i in range(5): - time.sleep(.1) + time.sleep(support.TEST_SLEEP) f.flush() except OSError: if not limit_set: diff -r 077dce5c4196 Lib/test/test_signal.py --- a/Lib/test/test_signal.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_signal.py Thu Mar 13 14:15:22 2014 +0100 @@ -90,7 +90,7 @@ class InterProcessSignalTests(unittest.T if child: self.wait(child) if not self.a_called: - time.sleep(1) # Give the signal time to be delivered. + time.sleep(support.TEST_SLEEP) # Give the signal time to be delivered. self.assertTrue(self.a_called) self.assertFalse(self.b_called) self.a_called = False @@ -103,7 +103,7 @@ class InterProcessSignalTests(unittest.T child = subprocess.Popen(['kill', '-USR1', str(pid)]) # This wait should be interrupted by the signal's exception. self.wait(child) - time.sleep(1) # Give the signal time to be delivered. + time.sleep(support.TEST_SLEEP) # Give the signal time to be delivered. self.fail('HandlerBCalled exception not raised') except HandlerBCalled: self.assertTrue(self.b_called) @@ -121,7 +121,7 @@ class InterProcessSignalTests(unittest.T signal.pause() # But if another signal arrives before the alarm, pause # may return early. - time.sleep(1) + time.sleep(support.TEST_SLEEP) except KeyboardInterrupt: pass except: diff -r 077dce5c4196 Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_smtplib.py Thu Mar 13 14:15:22 2014 +0100 @@ -151,7 +151,7 @@ def debugging_server(serv, serv_evt, cli finally: if not client_evt.is_set(): # allow some time for the client to read the result - time.sleep(0.5) + time.sleep(support.TEST_SLEEP) serv.close() asyncore.close_all() serv_evt.set() @@ -285,7 +285,7 @@ class DebuggingServerTests(unittest.Test # XXX(nnorwitz): this test is flaky and dies with a bad file descriptor # in asyncore. This sleep might help, but should really be fixed # properly by using an Event variable. - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) smtp.quit() self.client_evt.set() @@ -299,7 +299,7 @@ class DebuggingServerTests(unittest.Test smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.sendmail('John', 'Sally', m) # XXX (see comment in testSend) - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) smtp.quit() self.client_evt.set() @@ -314,7 +314,7 @@ class DebuggingServerTests(unittest.Test smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.sendmail('John', 'Sally', m) # XXX (see comment in testSend) - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) smtp.quit() self.client_evt.set() @@ -328,7 +328,7 @@ class DebuggingServerTests(unittest.Test smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.sendmail('<>', 'Sally', m) # XXX (see comment in testSend) - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) smtp.quit() self.client_evt.set() @@ -345,7 +345,7 @@ class DebuggingServerTests(unittest.Test smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.send_message(m, from_addr='John', to_addrs='Sally') # XXX (see comment in testSend) - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) smtp.quit() self.client_evt.set() @@ -365,7 +365,7 @@ class DebuggingServerTests(unittest.Test smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.send_message(m) # XXX (see comment in testSend) - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) smtp.quit() # make sure the Bcc header is still in the message. self.assertEqual(m['Bcc'], 'John Root , "Dinsdale" ' @@ -397,7 +397,7 @@ class DebuggingServerTests(unittest.Test smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.send_message(m) # XXX (see comment in testSend) - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) smtp.quit() self.client_evt.set() @@ -423,7 +423,7 @@ class DebuggingServerTests(unittest.Test smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.send_message(m, from_addr='joe@example.com', to_addrs='foo@example.net') # XXX (see comment in testSend) - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) smtp.quit() self.client_evt.set() @@ -452,7 +452,7 @@ class DebuggingServerTests(unittest.Test smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.send_message(m) # XXX (see comment in testSend) - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) smtp.quit() self.client_evt.set() @@ -483,7 +483,7 @@ class DebuggingServerTests(unittest.Test smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.send_message(m) # XXX (see comment in testSend) - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) smtp.quit() self.client_evt.set() diff -r 077dce5c4196 Lib/test/test_socket.py --- a/Lib/test/test_socket.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_socket.py Thu Mar 13 14:15:22 2014 +0100 @@ -3694,7 +3694,7 @@ class TCPCloserTest(ThreadedTCPSocketTes def _testClose(self): self.cli.connect((HOST, self.port)) - time.sleep(1.0) + time.sleep(support.TEST_SLEEP) @unittest.skipUnless(hasattr(socket, 'socketpair'), 'test needs socket.socketpair()') @@ -3803,9 +3803,9 @@ class NonBlockingTCPTests(ThreadedTCPSoc self.serv.settimeout(None) def _testInheritFlags(self): - time.sleep(0.1) + time.sleep(support.TEST_SLEEP) self.cli.connect((HOST, self.port)) - time.sleep(0.5) + time.sleep(support.TEST_SLEEP) self.cli.send(MSG) def testAccept(self): @@ -3825,7 +3825,7 @@ class NonBlockingTCPTests(ThreadedTCPSoc self.fail("Error trying to do accept after select.") def _testAccept(self): - time.sleep(0.1) + time.sleep(support.TEST_SLEEP) self.cli.connect((HOST, self.port)) def testConnect(self): @@ -3857,7 +3857,7 @@ class NonBlockingTCPTests(ThreadedTCPSoc def _testRecv(self): self.cli.connect((HOST, self.port)) - time.sleep(0.1) + time.sleep(support.TEST_SLEEP) self.cli.send(MSG) @unittest.skipUnless(thread, 'Threading required for this test.') @@ -4195,7 +4195,7 @@ class UnbufferedFileObjectClassTestCase( first_seg = self.read_file.read(len(self.read_msg) - 3) if first_seg is None: # Data not arrived (can happen under Windows), wait a bit - time.sleep(0.5) + time.sleep(support.TEST_SLEEP) first_seg = self.read_file.read(len(self.read_msg) - 3) buf = bytearray(10) n = self.read_file.readinto(buf) @@ -4794,7 +4794,7 @@ class TIPCThreadableTest(unittest.TestCa # The is a hittable race between serverExplicitReady() and the # accept() call; sleep a little while to avoid it, otherwise # we could get an exception - time.sleep(0.1) + time.sleep(support.TEST_SLEEP) self.cli = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM) self.addCleanup(self.cli.close) addr = (socket.TIPC_ADDR_NAME, TIPC_STYPE, diff -r 077dce5c4196 Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_subprocess.py Thu Mar 13 14:15:22 2014 +0100 @@ -1029,7 +1029,7 @@ class ProcessTestCase(BaseTestCase): def open_fds(): for i in range(20): fds.extend(os.pipe()) - time.sleep(0.001) + time.sleep(support.TEST_SHORT_SLEEP) t = threading.Thread(target=open_fds) t.start() try: @@ -1463,7 +1463,7 @@ class POSIXProcessTestCase(BaseTestCase) # sending any signal. p.stdout.read(1) # The process should end after this - time.sleep(1) + time.sleep(support.TEST_SLEEP) # This shouldn't raise even though the child is now dead getattr(p, method)(*args) p.communicate() @@ -2022,7 +2022,7 @@ class POSIXProcessTestCase(BaseTestCase) # let some time for the process to exit, and create a new Popen: this # should trigger the wait() of p - time.sleep(0.2) + time.sleep(support.TEST_SLEEP) with self.assertRaises(OSError) as c: with subprocess.Popen(['nonexisting_i_hope'], stdout=subprocess.PIPE, @@ -2161,7 +2161,7 @@ class Win32ProcessTestCase(BaseTestCase) # sending any signal. p.stdout.read(1) # The process should end after this - time.sleep(1) + time.sleep(support.TEST_SLEEP) # This shouldn't raise even though the child is now dead getattr(p, method)(*args) _, stderr = p.communicate() diff -r 077dce5c4196 Lib/test/test_thread.py --- a/Lib/test/test_thread.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_thread.py Thu Mar 13 14:15:22 2014 +0100 @@ -110,7 +110,7 @@ class ThreadRunningTests(BasicThreadTest mut.release() thread.start_new_thread(task, ()) while not started: - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) self.assertEqual(thread._count(), orig + 1) # Allow the task to finish. mut.release() @@ -121,7 +121,7 @@ class ThreadRunningTests(BasicThreadTest wr = weakref.ref(task, lambda _: done.append(None)) del task while not done: - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) self.assertEqual(thread._count(), orig) def test_save_exception_state_on_error(self): @@ -144,7 +144,7 @@ class ThreadRunningTests(BasicThreadTest thread.start_new_thread(task, ()) started.acquire() while thread._count() > c: - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) self.assertIn("Traceback", stderr.getvalue()) diff -r 077dce5c4196 Lib/test/test_threaded_import.py --- a/Lib/test/test_threaded_import.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_threaded_import.py Thu Mar 13 14:15:22 2014 +0100 @@ -12,6 +12,7 @@ import sys import time import shutil import unittest +from test import support from test.support import ( verbose, import_module, run_unittest, TESTFN, reap_threads, forget, unlink) threading = import_module('threading') @@ -73,7 +74,7 @@ class Finder: with self.lock: self.numcalls += 1 x = self.x - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) self.x = x + 1 class FlushingFinder: diff -r 077dce5c4196 Lib/test/test_threading.py --- a/Lib/test/test_threading.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_threading.py Thu Mar 13 14:15:22 2014 +0100 @@ -221,7 +221,7 @@ class ThreadTests(BaseTestCase): try: while True: worker_started.set() - time.sleep(0.1) + time.sleep(test.support.TEST_SHORT_SLEEP) except AsyncExc: self.finished = True worker_saw_exception.set() @@ -547,7 +547,7 @@ class ThreadTests(BaseTestCase): def f(): started.release() finish.acquire() - time.sleep(0.01) + time.sleep(test.support.TEST_SHORT_SLEEP) # The tstate lock is None until the thread is started t = threading.Thread(target=f) self.assertIs(t._tstate_lock, None) @@ -595,7 +595,7 @@ class ThreadTests(BaseTestCase): for i in range(500): if LOOKING_FOR in repr(t): break - time.sleep(0.01) + time.sleep(test.support.TEST_SHORT_SLEEP) self.assertIn(LOOKING_FOR, repr(t)) # we waited at least 5 seconds def test_BoundedSemaphore_limit(self): @@ -804,7 +804,7 @@ class ThreadJoinOnShutdown(BaseTestCase) # start a bunch of threads threads = [] for i in range(16): - t = threading.Thread(target=lambda : time.sleep(0.3)) + t = threading.Thread(target=lambda : time.sleep(test.support.TEST_SLEEP)) threads.append(t) t.start() diff -r 077dce5c4196 Lib/test/test_threading_local.py --- a/Lib/test/test_threading_local.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_threading_local.py Thu Mar 13 14:15:22 2014 +0100 @@ -56,7 +56,7 @@ class BaseLocalTest: import time class Local(self._local): def __init__(self): - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) local = Local() def f(i): diff -r 077dce5c4196 Lib/test/test_threadsignals.py --- a/Lib/test/test_threadsignals.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_threadsignals.py Thu Mar 13 14:15:22 2014 +0100 @@ -4,6 +4,7 @@ import unittest import signal import os import sys +from test import support from test.support import run_unittest, import_module thread = import_module('_thread') import time @@ -119,7 +120,7 @@ class ThreadSignals(unittest.TestCase): # Wait until we can't acquire it without blocking... while rlock.acquire(blocking=False): rlock.release() - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) signal.alarm(1) t1 = time.time() self.assertRaises(KeyboardInterrupt, rlock.acquire, timeout=5) @@ -141,17 +142,17 @@ class ThreadSignals(unittest.TestCase): lock.acquire() # Wait until the main thread is blocked in the lock acquire, and # then wake it up with this. - time.sleep(0.5) + time.sleep(support.TEST_SLEEP) os.kill(process_pid, signal.SIGUSR1) # Let the main thread take the interrupt, handle it, and retry # the lock acquisition. Then we'll let it run. - time.sleep(0.5) + time.sleep(support.TEST_SHORT_SLEEP) lock.release() thread.start_new_thread(other_thread, ()) # Wait until we can't acquire it without blocking... while lock.acquire(blocking=False): lock.release() - time.sleep(0.01) + time.sleep(support.TEST_SHORT_SLEEP) result = lock.acquire() # Block while we receive a signal. self.assertTrue(self.sig_recvd) self.assertTrue(result) @@ -189,7 +190,7 @@ class ThreadSignals(unittest.TestCase): self.end = time.time() def send_signals(): for _ in range(40): - time.sleep(0.02) + time.sleep(support.TEST_SHORT_SLEEP) os.kill(process_pid, signal.SIGUSR1) done.release() diff -r 077dce5c4196 Lib/test/test_time.py --- a/Lib/test/test_time.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_time.py Thu Mar 13 14:15:22 2014 +0100 @@ -85,7 +85,7 @@ class TimeTestCase(unittest.TestCase): def test_sleep(self): self.assertRaises(ValueError, time.sleep, -2) self.assertRaises(ValueError, time.sleep, -1) - time.sleep(1.2) + time.sleep(0.001) def test_strftime(self): tt = time.gmtime(self.t) @@ -394,7 +394,7 @@ class TimeTestCase(unittest.TestCase): dt = t2 - t1 self.assertGreater(t2, t1) # Issue #20101: On some Windows machines, dt may be slightly low - self.assertTrue(0.45 <= dt <= 1.0, dt) + support.check_time_delta(0.5, dt, 0.5, clock='monotonic') # monotonic() is a monotonic but non adjustable clock info = time.get_clock_info('monotonic') @@ -406,12 +406,10 @@ class TimeTestCase(unittest.TestCase): def test_process_time(self): # process_time() should not include time spend during a sleep - start = time.process_time() + t0 = time.process_time() time.sleep(0.100) - stop = time.process_time() - # use 20 ms because process_time() has usually a resolution of 15 ms - # on Windows - self.assertLess(stop - start, 0.020) + dt = time.process_time() - t0 + support.check_time_delta(0.0, dt, 0.010, clock='process_time') info = time.get_clock_info('process_time') self.assertTrue(info.monotonic) diff -r 077dce5c4196 Lib/test/test_urllib2net.py --- a/Lib/test/test_urllib2net.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_urllib2net.py Thu Mar 13 14:15:22 2014 +0100 @@ -247,7 +247,7 @@ class OtherNetworkTests(unittest.TestCas print("" % url, file=sys.stderr) f.close() debug("******** next url coming up...") - time.sleep(0.1) + time.sleep(support.TEST_SLEEP) def _extra_handlers(self): handlers = [] diff -r 077dce5c4196 Lib/test/test_wait3.py --- a/Lib/test/test_wait3.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_wait3.py Thu Mar 13 14:15:22 2014 +0100 @@ -5,6 +5,7 @@ import os import time import unittest from test.fork_wait import ForkWait +from test import support from test.support import run_unittest, reap_children if not hasattr(os, 'fork'): @@ -18,13 +19,14 @@ class Wait3Test(ForkWait): # 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): + deadline = time.monotonic() + 3.0 + while time.monotonic() <= deadline: # 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(0.1) + time.sleep(support.TEST_SHORT_SLEEP) self.assertEqual(spid, cpid) self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) diff -r 077dce5c4196 Lib/test/test_wait4.py --- a/Lib/test/test_wait4.py Thu Mar 13 10:58:03 2014 +0100 +++ b/Lib/test/test_wait4.py Thu Mar 13 14:15:22 2014 +0100 @@ -5,6 +5,7 @@ import os import time import sys from test.fork_wait import ForkWait +from test import support from test.support import run_unittest, reap_children, get_attribute # If either of these do not exist, skip this test. @@ -19,13 +20,14 @@ class Wait4Test(ForkWait): # Issue #11185: wait4 is broken on AIX and will always return 0 # with WNOHANG. option = 0 - for i in range(10): + deadline = time.monotonic() + 10.0 + while time.monotonic() <= deadline: # wait4() 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.wait4(cpid, option) if spid == cpid: break - time.sleep(1.0) + time.sleep(support.TEST_SHORT_SLEEP) self.assertEqual(spid, cpid) self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) self.assertTrue(rusage) diff -r 077dce5c4196 Makefile.pre.in --- a/Makefile.pre.in Thu Mar 13 10:58:03 2014 +0100 +++ b/Makefile.pre.in Thu Mar 13 14:15:22 2014 +0100 @@ -921,6 +921,7 @@ TESTOPTS= $(EXTRATESTOPTS) TESTPYTHON= $(RUNSHARED) ./$(BUILDPYTHON) $(TESTPYTHONOPTS) TESTRUNNER= $(TESTPYTHON) $(srcdir)/Tools/scripts/run_tests.py TESTTIMEOUT= 3600 +TEST_SLEEP= 0.5 # Run a basic set of regression tests. # This excludes some tests that are particularly resource-intensive. @@ -958,7 +959,7 @@ buildbottest: all platform -@if which pybuildbot.identify >/dev/null 2>&1; then \ pybuildbot.identify "CC='$(CC)'" "CXX='$(CXX)'"; \ fi - $(TESTRUNNER) -j 1 -u all -W --timeout=$(TESTTIMEOUT) $(TESTOPTS) + $(TESTRUNNER) -j 1 -u all -W --timeout=$(TESTTIMEOUT) --test-sleep=$(TEST_SLEEP) $(TESTOPTS) QUICKTESTOPTS= $(TESTOPTS) -x test_subprocess test_io test_lib2to3 \ test_multibytecodec test_urllib2_localnet test_itertools \ diff -r 077dce5c4196 Tools/buildbot/test-amd64.bat --- a/Tools/buildbot/test-amd64.bat Thu Mar 13 10:58:03 2014 +0100 +++ b/Tools/buildbot/test-amd64.bat Thu Mar 13 14:15:22 2014 +0100 @@ -1,3 +1,3 @@ @rem Used by the buildbot "test" step. cd PCbuild -call rt.bat -d -q -x64 -uall -rwW -n --timeout=3600 %1 %2 %3 %4 %5 %6 %7 %8 %9 +call rt.bat -d -q -x64 -uall -rwW -n --timeout=3600 --test-sleep=0.5 %1 %2 %3 %4 %5 %6 %7 %8 %9 diff -r 077dce5c4196 Tools/buildbot/test.bat --- a/Tools/buildbot/test.bat Thu Mar 13 10:58:03 2014 +0100 +++ b/Tools/buildbot/test.bat Thu Mar 13 14:15:22 2014 +0100 @@ -1,3 +1,3 @@ @rem Used by the buildbot "test" step. cd PCbuild -call rt.bat -d -q -uall -rwW -n --timeout=3600 %1 %2 %3 %4 %5 %6 %7 %8 %9 +call rt.bat -d -q -uall -rwW -n --timeout=3600 --test-sleep=0.5 %1 %2 %3 %4 %5 %6 %7 %8 %9