Skip to content

Commit

Permalink
Tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
spirali committed Sep 12, 2024
1 parent 547ca7c commit 87399c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion tests/test_jobfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import collections
import os

from .conftest import HqEnv
from .utils import wait_for_job_state
Expand All @@ -22,10 +23,11 @@ def test_job_file_submit_minimal(hq_env: HqEnv, tmp_path):
def test_job_file_submit_maximal(hq_env: HqEnv, tmp_path):
hq_env.start_server()
hq_env.start_workers(3, cpus=4, args=["--resource", "gpus=[0,1]"])
os.mkdir("output")
tmp_path.joinpath("job.toml").write_text(
"""
name = "test-job"
stream_log = "output.log"
stream = "output"
max_fails = 11
[[task]]
Expand Down
16 changes: 9 additions & 7 deletions tests/test_placeholders.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ def test_task_resolve_worker_placeholders(hq_env: HqEnv):

def test_stream_submit_placeholder(hq_env: HqEnv):
hq_env.start_server()
hq_env.command(["submit", "--log", "log-%{JOB_ID}", "--", "bash", "-c", "echo Hello"])
os.mkdir("log-1")
hq_env.command(["submit", "--stream", "log-%{JOB_ID}", "--", "bash", "-c", "echo Hello"])
hq_env.start_workers(1)
wait_for_job_state(hq_env, 1, "FINISHED")

lines = set(hq_env.command(["log", "log-1", "show"], as_lines=True))
assert "0:0> Hello" in lines
assert "0: > stream closed" in lines
lines = set(hq_env.command(["read", "log-1", "show"], as_lines=True))
assert "1.0:0> Hello" in lines


def test_server_uid_placeholder(hq_env: HqEnv, tmp_path):
Expand All @@ -149,6 +149,8 @@ def test_server_uid_placeholder(hq_env: HqEnv, tmp_path):
server_info = hq_env.command(["server", "--output-mode=json", "info"], as_json=True)
server_uid = server_info["server_uid"]

os.mkdir(f"log-{server_uid}-2")

hq_env.command(
[
"submit",
Expand All @@ -163,7 +165,7 @@ def test_server_uid_placeholder(hq_env: HqEnv, tmp_path):
hq_env.command(
[
"submit",
"--log",
"--stream",
"log-%{SERVER_UID}-%{JOB_ID}",
"--",
"bash",
Expand All @@ -174,7 +176,7 @@ def test_server_uid_placeholder(hq_env: HqEnv, tmp_path):
wait_for_job_state(hq_env, [1, 2], "FINISHED")

check_file_contents(os.path.join(tmp_path, f"out-{server_uid}-1"), "Hello\n")
assert os.path.isfile(os.path.join(tmp_path, f"log-{server_uid}-2"))
assert len(os.listdir(os.path.join(tmp_path, f"log-{server_uid}-2"))) == 1

table = hq_env.command(["job", "info", "1"], as_table=True)
table.check_row_value("Stdout", f"{os.getcwd()}/out-{server_uid}-1")
Expand Down Expand Up @@ -213,7 +215,7 @@ def test_unknown_placeholder(hq_env: HqEnv):
output = hq_env.command(
[
"submit",
"--log",
"--stream",
"log-%{FOO}",
"--stdout",
"dir/%{BAR}/%{BAZ}",
Expand Down
1 change: 0 additions & 1 deletion tests/test_restore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import time

from .utils.wait import wait_until
from .utils.cmd import python
from .autoalloc.mock.mock import MockJobManager
from .autoalloc.mock.slurm import SlurmManager, adapt_slurm
Expand Down

0 comments on commit 87399c7

Please sign in to comment.