Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c9a5e4

Browse files
committed
Fixed Python tests
1 parent 39cdf6d commit 4c9a5e4

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

tests/test_journal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def collect_ids():
348348
def test_restore_dependencies1(hq_env: HqEnv, tmp_path):
349349
journal_path = os.path.join(tmp_path, "my.journal")
350350
hq_env.start_server(args=["--journal", journal_path])
351-
hq_env.start_worker()
351+
hq_env.start_worker(cpus=2)
352352
tmp_path.joinpath("sleep_time").write_text("100")
353353
tmp_path.joinpath("job.toml").write_text(
354354
"""

tests/test_worker.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def test_deploy_ssh_error(hq_env: HqEnv):
317317
with hq_env.mock.mock_program_with_code(
318318
"ssh",
319319
"""
320-
exit(42)
320+
exit(42)
321321
""",
322322
):
323323
nodefile = prepare_localhost_nodefile()
@@ -351,8 +351,8 @@ def test_deploy_ssh_wait_for_worker(hq_env: HqEnv):
351351
with hq_env.mock.mock_program_with_code(
352352
"ssh",
353353
"""
354-
import time
355-
time.sleep(1)
354+
import time
355+
time.sleep(1)
356356
""",
357357
):
358358
nodefile = prepare_localhost_nodefile()
@@ -364,12 +364,12 @@ def test_deploy_ssh_multiple_workers(hq_env: HqEnv):
364364
with hq_env.mock.mock_program_with_code(
365365
"ssh",
366366
"""
367-
import os
367+
import os
368368
369-
os.makedirs("workers", exist_ok=True)
370-
with open(f"workers/{os.getpid()}", "w") as f:
371-
f.write(str(os.getpid()))
372-
""",
369+
os.makedirs("workers", exist_ok=True)
370+
with open(f"workers/{os.getpid()}", "w") as f:
371+
f.write(str(os.getpid()))
372+
""",
373373
):
374374
nodefile = prepare_localhost_nodefile(count=3)
375375
hq_env.command(["worker", "deploy-ssh", nodefile])
@@ -381,8 +381,8 @@ def test_deploy_ssh_show_output(hq_env: HqEnv):
381381
with hq_env.mock.mock_program_with_code(
382382
"ssh",
383383
"""
384-
print("FOOBAR")
385-
""",
384+
print("FOOBAR")
385+
""",
386386
):
387387
nodefile = prepare_localhost_nodefile(count=3)
388388
output = hq_env.command(["worker", "deploy-ssh", "--show-output", nodefile])
@@ -424,15 +424,15 @@ def test_worker_state_info(hq_env: HqEnv):
424424
wait_for_job_state(hq_env, 1, "RUNNING")
425425
table = hq_env.command(["worker", "info", "1"], as_table=True)
426426
table.check_row_value("State", "RUNNING")
427-
assert "Job: 1;" in table.get_row_value("Last task started")
427+
assert "1@" in table.get_row_value("Last task started")
428428
table.check_row_value("Runtime Info", "assigned tasks: 2; running tasks: 1")
429429
hq_env.start_worker()
430430
hq_env.command(["submit", "--nodes=2", "--", "sleep", "1"])
431431
wait_for_job_state(hq_env, 2, "RUNNING")
432432
table = hq_env.command(["worker", "info", "1"], as_table=True)
433433
a = table.get_row_value("Runtime Info")
434-
assert "Job: 2;" in table.get_row_value("Last task started")
434+
assert "2@0" in table.get_row_value("Last task started")
435435
table = hq_env.command(["worker", "info", "2"], as_table=True)
436436
b = table.get_row_value("Runtime Info")
437-
assert "Job: 2;" in table.get_row_value("Last task started")
437+
assert "2@0" in table.get_row_value("Last task started")
438438
assert {a, b} == {"running multinode task; main node", "running multinode task; secondary node"}

tests/utils/wait.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,17 @@ def wait_for_task_state(env, job_id: int, task_ids: Union[int, List[int]], state
9090

9191
ids = ",".join(str(t) for t in task_ids)
9292
states = [s.lower() for s in states]
93+
result = None
9394

9495
def check():
96+
nonlocal result
9597
result = env.command(["--output-mode=json", "task", "info", str(job_id), ids], as_json=True)
9698
return [r["state"] for r in result] == states
9799

98-
wait_until(check, **kwargs)
100+
def on_timeout():
101+
return f"most recent output:\n{result}"
102+
103+
wait_until(check, on_timeout=on_timeout, **kwargs)
99104

100105

101106
def wait_for_pid_exit(pid: int):

0 commit comments

Comments
 (0)