MCPcopy Create free account
hub / github.com/It4innovations/hyperqueue / test_restore_partially_finished_task

Function test_restore_partially_finished_task

tests/test_journal.py:51–98  ·  view source on GitHub ↗
(hq_env: HqEnv, tmp_path)

Source from the content-addressed store, hash-verified

49
50
51def test_restore_partially_finished_task(hq_env: HqEnv, tmp_path):
52 journal_path = os.path.join(tmp_path, "my.journal")
53 hq_env.start_server(args=["--journal", journal_path])
54 hq_env.command(
55 [
56 "submit",
57 "--array=0-4",
58 "--",
59 *python(
60 "import os, time;"
61 f"open('{tmp_path}/task-marker' + os.environ.get('HQ_TASK_ID'), 'w').write(os.environ.get('HQ_INSTANCE_ID'));"
62 "time.sleep(1.5 if os.environ.get('HQ_TASK_ID') in ('1','3','4') else 0);",
63 ),
64 ]
65 )
66 hq_env.start_worker(cpus=5)
67 wait_for_job_state(hq_env, 1, "RUNNING")
68 time.sleep(0.2)
69
70 markers = sorted([name for name in os.listdir(tmp_path) if name.startswith("task-marker")])
71 assert markers == ["task-marker0", "task-marker1", "task-marker2", "task-marker3", "task-marker4"]
72 for marker in markers:
73 path = os.path.join(tmp_path, marker)
74 with open(path) as f:
75 assert f.read() == "0"
76 os.unlink(path)
77
78 out = hq_env.command(["--output-mode=json", "job", "info", "1"], as_json=True)
79 stats = out[0]["info"]["task_stats"]
80 assert stats["running"] == 3
81 assert stats["finished"] == 2
82 hq_env.stop_server()
83
84 hq_env.start_server(args=["--journal", journal_path])
85
86 out = hq_env.command(["--output-mode=json", "job", "info", "1"], as_json=True)
87 stats = out[0]["info"]["task_stats"]
88 assert stats["waiting"] == 3
89 assert stats["finished"] == 2
90
91 hq_env.start_worker(cpus=4)
92 wait_for_job_state(hq_env, [1], "FINISHED")
93 markers = sorted([name for name in os.listdir(tmp_path) if name.startswith("task-marker")])
94 assert markers == ["task-marker1", "task-marker3", "task-marker4"]
95 for marker in markers:
96 path = os.path.join(tmp_path, marker)
97 with open(path) as f:
98 assert f.read() == "1"
99
100
101def test_restore_partially_failed_task(hq_env: HqEnv, tmp_path):

Callers

nothing calls this directly

Calls 7

pythonFunction · 0.85
wait_for_job_stateFunction · 0.85
commandMethod · 0.80
sleepMethod · 0.80
start_serverMethod · 0.45
start_workerMethod · 0.45
stop_serverMethod · 0.45

Tested by

no test coverage detected