Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make ExecutorStatus variable names more consistent #619

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __init__(self):

def add_test_job(
self,
exec_state,
executor_state,
job_state,
status_code=StatusCode.CREATED,
message="message",
Expand All @@ -149,26 +149,24 @@ def add_test_job(
"""Create and track a db job object."""

job = job_factory(state=job_state, status_code=status_code, **kwargs)
if exec_state != ExecutorState.UNKNOWN:
self.set_job_state(job, exec_state, message)
if executor_state != ExecutorState.UNKNOWN:
self.set_job_state(job, executor_state, message)
return job

# TODO: rename to set_job_executor_state
# and rename state param to executor_state
def set_job_state(
self, job_definition, state, message="message", timestamp_ns=None
self, job_definition, executor_state, message="message", timestamp_ns=None
):
"""Directly set a job state."""
"""Directly set a job state from an ExecutorState."""
# handle the synchronous state meaning the state has completed
if timestamp_ns is None:
timestamp_ns = time.time_ns()
synchronous = getattr(self, "synchronous_transitions", [])
if state in synchronous:
if state == ExecutorState.PREPARING:
state = ExecutorState.PREPARED
if state == ExecutorState.FINALIZING:
state = ExecutorState.FINALIZED
self.state[job_definition.id] = JobStatus(state, message, timestamp_ns)
if executor_state in synchronous:
if executor_state == ExecutorState.PREPARING:
executor_state = ExecutorState.PREPARED
if executor_state == ExecutorState.FINALIZING:
executor_state = ExecutorState.FINALIZED
self.state[job_definition.id] = JobStatus(executor_state, message, timestamp_ns)

def set_job_transition(
self, job_definition, state, message="executor message", hook=None
Expand Down
10 changes: 5 additions & 5 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,24 +452,24 @@ def test_handle_job_waiting_on_db_workers(monkeypatch, db):


@pytest.mark.parametrize(
"exec_state,job_state,code,tracker",
"executor_state,job_state,code,tracker",
[
(ExecutorState.UNKNOWN, State.PENDING, StatusCode.CREATED, "prepare"),
(ExecutorState.PREPARED, State.RUNNING, StatusCode.PREPARED, "execute"),
(ExecutorState.EXECUTED, State.RUNNING, StatusCode.EXECUTED, "finalize"),
],
)
def test_handle_job_waiting_on_workers_via_executor(
exec_state, job_state, code, tracker, db
executor_state, job_state, code, tracker, db
):
api = StubExecutorAPI()
job = api.add_test_job(exec_state, job_state, code)
api.set_job_transition(job, exec_state)
job = api.add_test_job(executor_state, job_state, code)
api.set_job_transition(job, executor_state)

run.handle_job(job, api)

assert job.id in api.tracker[tracker]
assert api.get_status(job).state == exec_state
assert api.get_status(job).state == executor_state

assert job.state == job_state
assert job.status_message == "Waiting on available resources"
Expand Down