From 92539daa992500d32a66ed07a6ed44d7d9cbf142 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 20 Jun 2013 15:17:10 -0400 Subject: [PATCH] Enforce timely test completion. (imported from commit f2e3ff32b7372cc916cc60ba04abcb90c39197e2) --- zephyr/tests.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/zephyr/tests.py b/zephyr/tests.py index cd4c429a1e..c1a0e992f8 100644 --- a/zephyr/tests.py +++ b/zephyr/tests.py @@ -2937,14 +2937,36 @@ def full_test_name(test): def get_test_method(test): return getattr(test, test._testMethodName) +def enforce_timely_test_completion(test_method, test_name, delay): + if hasattr(test_method, 'expected_run_time'): + # Allow for tests to run 50% slower than normal due + # to random variations. + max_delay = 1.5 * test_method.expected_run_time + else: + max_delay = 1 # 1 second + + # Further adjustments for slow laptops: + max_delay = max_delay * 3 + + if delay > max_delay: + print 'Test is TOO slow: %s (%.3f s)' % (test_name, delay) + sys.exit(1) + def run_test(test): test_method = get_test_method(test) test_name = full_test_name(test) print 'Running %s' % (test_name,) test._pre_setup() + + start_time = time.time() + test.setUp() test_method() test.tearDown() + + delay = time.time() - start_time + enforce_timely_test_completion(test_method, test_name, delay) + test._post_teardown() class Runner(DjangoTestSuiteRunner):