Skip to content

Commit

Permalink
Add test for timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Dec 13, 2024
1 parent fbd90ac commit 18397b9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
55 changes: 46 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,49 @@ def wg_engine(decorated_add, add_code) -> WorkGraph:


@pytest.fixture
def finished_process_node():
"""Return a finished process node."""

node = WorkflowNode()
node.set_process_state("finished")
node.set_exit_status(0)
node.seal()
node.store()
return node
def create_process_node():
"""Return a process node."""

def process_node(state="finished", exit_status=0):
"""Return a finished process node."""

node = WorkflowNode()
node.set_process_state(state)
node.set_exit_status(exit_status)
node.seal()
node.store()
return node

return process_node


@pytest.fixture
def create_workgraph_process_node():
"""Return a process node."""

def process_node(state="finished", exit_status=0):
"""Return a finished process node."""
from aiida_workgraph.engine.workgraph import WorkGraphEngine

process = WorkGraphEngine(
inputs={
"wg": {
"name": "test",
"uuid": "",
"tasks": {},
"links": [],
"ctrl_links": [],
"state": "",
"error_handlers": {},
"context": {},
}
}
)
node = process.node
node.set_process_state(state)
node.set_exit_status(exit_status)
node.seal()
node.store()
return node

return process_node
4 changes: 2 additions & 2 deletions tests/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def test_pause_play_task(wg_calcjob):
assert wg.tasks.add2.outputs.sum.value == 9


def test_pause_play_error_handler(wg_calcjob, finished_process_node):
def test_pause_play_error_handler(wg_calcjob, create_process_node):
wg = wg_calcjob
wg.name = "test_pause_play_error_handler"
wg.process = finished_process_node
wg.process = create_process_node(state="finished", exit_status=0)
try:
wg.pause_tasks(["add1"])
except Exception as e:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_workgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,14 @@ def test_workgraph_group_outputs(decorated_add):
wg.run()
assert wg.process.outputs.sum.value == 5
# assert wg.process.outputs.add1.result.value == 5


@pytest.mark.usefixtures("started_daemon_client")
def test_wait_timeout(create_workgraph_process_node):
wg = WorkGraph()
wg.process = create_workgraph_process_node(state="running")
with pytest.raises(
TimeoutError,
match="Timeout reached after 1 seconds while waiting for the WorkGraph:",
):
wg.wait(timeout=1, interval=1)

0 comments on commit 18397b9

Please sign in to comment.