Skip to content

Commit eb3abb4

Browse files
committed
test: Pin READY_ENDING after a default exit that raises
This is the one behavior change in the otherwise behavior-neutral refactor in 716c90d, and this message replaces that commit's "behavior is unchanged" wording: a failed default exit_environment() now leaves the Session READY_ENDING instead of READY. exit_environment() without keep_session_running sets _ending_only before it stores RUNNING. If it raises in between, the Session used to report READY with the flag set, so a later run_task, enter_environment or run_subprocess was accepted and clear_ending_only() was refused. That is the same "READY while ending-only" drift the refactor removes. It now reports READY_ENDING: those three calls are refused, clear_ending_only() is accepted, and only exits and cleanup remain, which is what the exit asked for. Calls with correctly typed arguments don't raise in that window. Only wrongly typed arguments reach it through the public API, for example a resolved_symtab that isn't a SerializedSymbolTable, or os_env_vars with a non-string key. So the new test, test_default_exit_that_raises_leaves_ready_ending, injects the failure into _evaluate_current_session_env_vars, then checks that the stored state is READY, the state property reads READY_ENDING, and run_task, enter_environment and run_subprocess are refused. It fails at a299030, where the state reads READY. Full suite 1061 passed, 46 skipped, 16 xfailed; black, ruff and mypy pass. Signed-off-by: Mark Wiebe <399551+mwiebe@users.noreply.github.com>
1 parent 0e43153 commit eb3abb4

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎test/openjd/sessions_v0/test_brittle_session.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,3 +693,25 @@ def __setattr__(self, name: str, value: object) -> None:
693693
session._fail_action_before_start("setup failed")
694694
session.__class__ = Session
695695
assert writes == [("_ending_only", True), ("_state", SessionState.READY)]
696+
697+
def test_default_exit_that_raises_leaves_ready_ending(self, python_exe: str) -> None:
698+
# exit_environment without keep_session_running makes the Session
699+
# ending-only before it stores RUNNING. If it raises in between, the
700+
# Session reads READY_ENDING and refuses new work, as the exit asked.
701+
# (Before ending-only mode was stored only in the flag, it read READY
702+
# here and accepted run_task.) Calls with correctly typed arguments
703+
# don't raise there, so the failure is injected.
704+
with Session(session_id=uuid.uuid4().hex, job_parameter_values=_no_params()) as session:
705+
identifier = session.enter_environment(environment=_env("Env"))
706+
_wait(session)
707+
assert session.state == SessionState.READY
708+
709+
with patch.object(
710+
session, "_evaluate_current_session_env_vars", side_effect=RuntimeError("boom")
711+
):
712+
with pytest.raises(RuntimeError, match="^boom$"):
713+
session.exit_environment(identifier=identifier)
714+
715+
assert session._state == SessionState.READY
716+
assert session.state == SessionState.READY_ENDING
717+
_assert_refuses_new_actions(session, python_exe)

0 commit comments

Comments
 (0)