Skip to content

Commit

Permalink
Repair pytest timeout tests. (pantsbuild#4972)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwlzn authored Oct 17, 2017
1 parent b4fa68c commit ae5c9af
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
3 changes: 3 additions & 0 deletions src/python/pants/task/testrunner_task_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ def kill_if_not_terminated():
try:
return process_handler.wait(timeout=timeout)
except subprocess.TimeoutExpired as e:
# Since we no longer surface the actual underlying exception, we log.error here
# to ensure the output indicates why the test has suddenly failed.
self.context.log.error('FAILURE: Timeout of {} seconds reached.'.format(timeout))
raise ErrorWhileTesting(str(e), failed_targets=test_targets)
finally:
maybe_terminate(wait_time=self.get_options().timeout_terminate_wait)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def test_within_timeout():


def test_exceeds_timeout():
time.sleep(120)
time.sleep(1000)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def signal_term_handler(signal, frame):
pass

signal.signal(signal.SIGTERM, signal_term_handler)
time.sleep(120)
time.sleep(1000)

# We need a second sleep because the SIGTERM will interrupt the first sleep.
time.sleep(120)
time.sleep(1000)
2 changes: 1 addition & 1 deletion tests/python/pants_test/backend/jvm/tasks/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ python_tests(
'tests/python/pants_test:int-test',
],
tags = {'integration'},
timeout = 240,
timeout = 600
)

python_tests(
Expand Down
3 changes: 2 additions & 1 deletion tests/python/pants_test/backend/python/tasks2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ python_tests(
'src/python/pants/util:process_handler',
'tests/python/pants_test:int-test',
],
tags = {'integration'},
tags={'integration'},
timeout=600
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import os
import time
import unittest

from pants.util.contextutil import temporary_dir
from pants_test.pants_run_integration_test import PantsRunIntegrationTest
Expand All @@ -28,52 +27,51 @@ def test_pytest_run_conftest_succeeds(self):
'testprojects/tests/python/pants/conf_test'])
self.assert_success(pants_run)

@unittest.skip('https://github.com/pantsbuild/pants/issues/3255')
def test_pytest_run_timeout_fails(self):
start = time.time()
pants_run = self.run_pants(['clean-all',
'test.pytest',
'--test-pytest-coverage=auto',
'--test-pytest-options=-k exceeds_timeout',
'--timeout-default=1',
'--test-pytest-timeout-default=1',
'--cache-test-pytest-ignore',
'testprojects/tests/python/pants/timeout:exceeds_timeout'])
end = time.time()
self.assert_failure(pants_run)

# Ensure that the failure took less than 20 seconds to run.
self.assertLess(end - start, 20)
# Ensure that the failure took less than 100 seconds to run to allow for test overhead.
self.assertLess(end - start, 100)

# Ensure that a warning about coverage reporting was emitted.
self.assertIn("No .coverage file was found! Skipping coverage reporting", pants_run.stderr_data)
self.assertIn("No .coverage file was found! Skipping coverage reporting", pants_run.stdout_data)

# Ensure that the timeout message triggered.
self.assertIn(" timed out after 1 seconds", pants_run.stdout_data)
self.assertIn("FAILURE: Timeout of 1 seconds reached.", pants_run.stdout_data)

@unittest.skip('https://github.com/pantsbuild/pants/issues/3255')
def test_pytest_run_timeout_cant_terminate(self):
start = time.time()
terminate_wait = 2
pants_run = self.run_pants(['clean-all',
'test.pytest',
'--test-pytest-timeout-terminate-wait=2',
'--test-pytest-timeout-default=1',
'--test-pytest-coverage=auto',
'--test-pytest-timeout-terminate-wait=%d' % terminate_wait,
'--timeout-default=1',
'--cache-test-pytest-ignore',
'testprojects/tests/python/pants/timeout:ignores_terminate'])
end = time.time()
self.assert_failure(pants_run)

# Ensure that the failure took less than 20 seconds to run.
self.assertLess(end - start, 20)
# Ensure that the failure took less than 100 seconds to run to allow for test overhead.
self.assertLess(end - start, 100)

# Ensure that a warning about coverage reporting was emitted.
self.assertIn("No .coverage file was found! Skipping coverage reporting", pants_run.stderr_data)
self.assertIn("No .coverage file was found! Skipping coverage reporting", pants_run.stdout_data)

# Ensure that the timeout message triggered.
self.assertIn("FAILURE: Timeout of 1 seconds reached", pants_run.stdout_data)
self.assertIn("FAILURE: Timeout of 1 seconds reached.", pants_run.stdout_data)

# Ensure that the warning about killing triggered.
self.assertIn("WARN] Timed out test did not terminate gracefully after {} seconds, "
"killing...".format(terminate_wait), pants_run.stderr_data)
self.assertIn("WARN] Timed out test did not terminate gracefully after 2 seconds, "
"killing...", pants_run.stderr_data)

def test_pytest_explicit_coverage(self):
with temporary_dir(cleanup=False) as coverage_dir:
Expand Down

0 comments on commit ae5c9af

Please sign in to comment.