Skip to content

Commit

Permalink
Make pytest fail when tasks are running after a test
Browse files Browse the repository at this point in the history
When pressing ctrl-c in pytest, prior to this PR, it would hang as
wait_for_task_completion would be called in the unwinding of the
fixture stack. However, because ctrl-c was pressed, tasks wouldn't be
expected to all complete.

This PR changes that to assert that all tasks are completed, rather
than *waiting* for all tasks to complete.

A non-finished task now gives a test error - which is arguably better
anyway because it more aggressively flushes out tests that do not perform
a complete shutdown.

This means that pressing ctrl-C in a pytest leads to an assertion error;
when previously it led to a hang.

One recently introduced test is fixed to

This is part of safe-shutdown work.
  • Loading branch information
benclifford authored and khk-globus committed Nov 1, 2023
1 parent 70b176a commit 488aa37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions parsl/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def setup_data(tmpd_cwd):


@pytest.fixture(autouse=True, scope='function')
def wait_for_task_completion(pytestconfig):
def assert_no_outstanding_tasks(pytestconfig):
"""If we're in a config-file based mode, wait for task completion between
each test. This will detect early on (by hanging) if particular test
tasks are not finishing, rather than silently falling off the end of
Expand All @@ -254,7 +254,11 @@ def wait_for_task_completion(pytestconfig):
config = pytestconfig.getoption('config')[0]
yield
if config != 'local':
parsl.dfk().wait_for_current_tasks()
logger.info("Checking no outstanding tasks")
for task_record in parsl.dfk().tasks.values():
fut = task_record['app_fu']
assert fut.done(), f"Incomplete task found, task id {task_record['id']}"
logger.info("No outstanding tasks found")


def pytest_make_collect_report(collector):
Expand Down
4 changes: 3 additions & 1 deletion parsl/tests/test_python_apps/test_lifted.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ def test_returns_a_class_instance():

def test_returns_a_class_instance_no_underscores():
# test that _underscore attribute references are not lifted
f = returns_a_class_instance()
with pytest.raises(AttributeError):
returns_a_class_instance()._nosuchattribute.result()
f._nosuchattribute.result()
f.exception() # wait for f to complete before the test ends


@pytest.mark.skip("returning classes is not supported in WorkQueue or Task Vine - see issue #2908")
Expand Down

0 comments on commit 488aa37

Please sign in to comment.