Skip to content

Commit

Permalink
Add a test to cover #6426.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuhood committed Sep 7, 2018
1 parent bd00946 commit 1a035e6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tests/python/pants_test/pantsd/pantsd_integration_test_base.py
Expand Up @@ -84,15 +84,15 @@ def pantsd_test_context(self, log_level='info', extra_config=None, expected_runs
recursively_update(pantsd_config, extra_config)
print('>>> config: \n{}\n'.format(pantsd_config))
checker = PantsDaemonMonitor(pid_dir)
self.assert_success_runner(workdir, pantsd_config, ['kill-pantsd'])
self.assert_runner(workdir, pantsd_config, ['kill-pantsd'])
try:
yield workdir, pantsd_config, checker
finally:
banner('BEGIN pantsd.log')
for line in read_pantsd_log(workdir):
print(line)
banner('END pantsd.log')
self.assert_success_runner(
self.assert_runner(
workdir,
pantsd_config,
['kill-pantsd'],
Expand All @@ -101,14 +101,20 @@ def pantsd_test_context(self, log_level='info', extra_config=None, expected_runs
checker.assert_stopped()

@contextmanager
def pantsd_successful_run_context(self, log_level='info', extra_config=None, extra_env=None):
def pantsd_successful_run_context(self, *args, **kwargs):
with self.pantsd_run_context(*args, success=True, **kwargs) as context:
yield context

@contextmanager
def pantsd_run_context(self, log_level='info', extra_config=None, extra_env=None, success=True):
with self.pantsd_test_context(log_level, extra_config) as (workdir, pantsd_config, checker):
yield (
functools.partial(
self.assert_success_runner,
self.assert_runner,
workdir,
pantsd_config,
extra_env=extra_env,
success=success,
),
checker,
workdir,
Expand All @@ -122,7 +128,7 @@ def _run_count(self, workdir):
else:
return 0

def assert_success_runner(self, workdir, config, cmd, extra_config={}, extra_env={}, expected_runs=1):
def assert_runner(self, workdir, config, cmd, extra_config={}, extra_env={}, expected_runs=1, success=True):
combined_config = config.copy()
recursively_update(combined_config, extra_config)
print(bold(cyan('\nrunning: ./pants {} (config={}) (extra_env={})'
Expand All @@ -149,5 +155,8 @@ def assert_success_runner(self, workdir, config, cmd, extra_config={}, extra_env
runs_created,
)
)
self.assert_success(run)
if success:
self.assert_success(run)
else:
self.assert_failure(run)
return run
19 changes: 19 additions & 0 deletions tests/python/pants_test/pantsd/test_pantsd_integration.py
Expand Up @@ -370,6 +370,25 @@ def test_pantsd_invalidation_stale_sources(self):
finally:
rm_rf(test_path)

def test_pantsd_parse_exception_success(self):
# This test covers the case described in #6426, where a run that is failing fast due to an
# exception can race other completing work. We expect all runs to fail due to the error
# that has been introduced, but none of them should hang.
test_path = 'testprojects/3rdparty/this_is_definitely_not_a_valid_directory'
test_build_file = os.path.join(test_path, 'BUILD')
invalid_symbol = 'this_is_definitely_not_a_valid_symbol'

try:
safe_mkdir(test_path, clean=True)
safe_file_dump(test_build_file, "{}()".format(invalid_symbol), binary_mode=False)
for _ in range(3):
with self.pantsd_run_context(success=False) as (pantsd_run, checker, _, _):
result = pantsd_run(['list', 'testprojects::'])
checker.assert_started()
self.assertIn(invalid_symbol, result.stderr_data)
finally:
rm_rf(test_path)

def test_pantsd_multiple_parallel_runs(self):
with self.pantsd_test_context() as (workdir, config, checker):
file_to_make = os.path.join(workdir, 'some_magic_file')
Expand Down

0 comments on commit 1a035e6

Please sign in to comment.