Skip to content

Commit 4d0eba1

Browse files
committed
Add test for fail-fast flag
1 parent ab03030 commit 4d0eba1

4 files changed

Lines changed: 48 additions & 8 deletions

File tree

planemo/commands/cmd_workflow_test_on_invocation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def cli(ctx, path, invocation_id, test_index, **kwds):
3333
), f"Selected test case {test_index}, but only found {len(test_cases)} test case(s)."
3434
test_case = test_cases[test_index - 1]
3535
# Hardcode fail_fast, no need to expose the option to the user IMO.
36-
run_response = invocation_to_run_response(ctx, user_gi=config.user_gi, runnable=runnable, invocation=invocation, fail_fast=True)
36+
run_response = invocation_to_run_response(
37+
ctx, user_gi=config.user_gi, runnable=runnable, invocation=invocation, fail_fast=True
38+
)
3739
structured_data = test_case.structured_test_data(run_response)
3840
test_data = {
3941
"version": "0.1",

planemo/galaxy/invocations/polling.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ def summarize(invocation_id: str):
129129

130130

131131
def workflow_in_error_message(
132-
ctx, invocation_id, last_exception, last_invocation, last_invocation_jobs, fail_fast=False,
132+
ctx,
133+
invocation_id,
134+
last_exception,
135+
last_invocation,
136+
last_invocation_jobs,
137+
fail_fast=False,
133138
) -> Optional[str]:
134139
"""Return an error message if workflow is in an error state."""
135140

planemo/options.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,11 +1830,7 @@ def test_output_options():
18301830

18311831

18321832
def test_options():
1833-
return _compose(
1834-
paste_test_data_paths_option(),
1835-
test_output_options(),
1836-
fail_fast_option()
1837-
)
1833+
return _compose(paste_test_data_paths_option(), test_output_options(), fail_fast_option())
18381834

18391835

18401836
def _compose(*functions):

tests/test_invocation_polling.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,43 @@ def test_polling_without_invocation_as_full_subpanel():
109109
assert not error_message
110110

111111

112-
def run_workflow_simulation(yaml_str: str, display_configuration: Optional[DisplayConfiguration] = None):
112+
def test_fail_fast_enabled_with_job_failure():
113+
"""Test that fail_fast=True returns error when a job fails."""
114+
final_invocation_state, job_state, error_message = run_workflow_simulation(
115+
SCENARIO_1, fail_fast=True
116+
)
117+
# Invocation should still be scheduled (workflow scheduling succeeded)
118+
assert final_invocation_state == "scheduled"
119+
assert job_state == "failed"
120+
# fail_fast should detect the failed job and return error message
121+
assert error_message
122+
assert "Failed to run workflow, at least one job is in [failed] state." in error_message
123+
124+
125+
def test_fail_fast_disabled_with_job_failure():
126+
"""Test that fail_fast=False does not report job failures as errors."""
127+
final_invocation_state, job_state, error_message = run_workflow_simulation(
128+
SCENARIO_1, fail_fast=False
129+
)
130+
# Invocation should be scheduled (workflow scheduling succeeded)
131+
assert final_invocation_state == "scheduled"
132+
assert job_state == "failed"
133+
# Without fail_fast, job failures shouldn't cause error messages
134+
# (unless invocation itself fails, which it doesn't in this case)
135+
assert error_message is None
136+
137+
138+
def test_fail_fast_enabled_with_successful_workflow():
139+
"""Test that fail_fast=True works normally when no jobs fail."""
140+
final_invocation_state, job_state, error_message = run_workflow_simulation(
141+
SCENARIO_MULTIPLE_OK_SUBWORKFLOWS, fail_fast=True
142+
)
143+
assert final_invocation_state == "scheduled"
144+
assert job_state == "ok"
145+
assert not error_message
146+
147+
148+
def run_workflow_simulation(yaml_str: str, display_configuration: Optional[DisplayConfiguration] = None, fail_fast: bool = False):
113149
simulation = parse_workflow_simulation_from_string(yaml_str)
114150
invocation_id = simulation.id
115151
invocation_api = SimulatedApi(simulation)
@@ -122,6 +158,7 @@ def run_workflow_simulation(yaml_str: str, display_configuration: Optional[Displ
122158
invocation_api,
123159
polling_tracker,
124160
display,
161+
fail_fast=fail_fast,
125162
)
126163

127164

0 commit comments

Comments
 (0)