Skip to content
Merged
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
18 changes: 14 additions & 4 deletions app/tests/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,15 @@ class KeyCutShort(LocalHost):
a host alike."""
KEY, URL = "sk-cut-0123456789abcdef", "http://127.0.0.1:8000/v1"

def wait(self, ex, seconds=60): # a host run packs and copies the backend first: slow under load
return super().wait(ex, seconds)

def shm_name(self, base):
"""A run name of its own: the licence folder is /dev/shm/nullius-<name>, shared by every process on the machine."""
name = f"{base}-{self.tmp.name.rsplit('-', 1)[-1]}"
self.addCleanup(shutil.rmtree, f"/dev/shm/nullius-{name}", True)
return name

def cut_to(self, keep):
"""The command runner, the launcher's stdin cut to what ``keep`` leaves of it."""
def run(argv, timeout=600.0, stdin=None):
Expand Down Expand Up @@ -533,7 +542,7 @@ def test_a_standard_run_on_a_host_is_handed_its_benchmarks_licences_and_here_non
value, blob = "lic-0123456789abcdef", b"FAKE-LICENCE-FILE\n\x00bytes"
for target in ("here", "host"):
with self.subTest(target):
name = f"lic-{target}"; root = self.tmp / name; seen = root / "seen"
name = self.shm_name(f"lic-{target}"); root = self.tmp / name; seen = root / "seen"
script = (f'echo "line=${{#NULLIUS_LICENCES}} dir=${{NULLIUS_LICENCE_DIR:-none}}" > {seen}; '
f'[ -n "$NULLIUS_LICENCE_DIR" ] && mkdir -p "$NULLIUS_LICENCE_DIR" && echo x > "$NULLIUS_LICENCE_DIR/F"; '
f'echo "$NULLIUS_LICENCES" > {root}/line; echo "{value}"')
Expand All @@ -557,19 +566,20 @@ def test_a_standard_run_on_a_host_is_handed_its_benchmarks_licences_and_here_non
self.assertNotIn(blob.decode(errors="replace"), (root / name / "run.json").read_text())

def test_a_stopped_run_on_a_host_leaves_no_licence_file_behind(self):
name = "lic-stop"; root = self.tmp / name; ready = root / "ready"
name = self.shm_name("lic-stop"); root = self.tmp / name; ready = root / "ready"
script = f'mkdir -p "$NULLIUS_LICENCE_DIR" && echo x > "$NULLIUS_LICENCE_DIR/F"; touch {ready}; sleep 30'
plan = self.plan([{"id": "a", "label": "a", "script": script}], name)
plan.runner, plan.licences = execution.STANDARD, {"benchmark": "envbench", "names": ["F"]}
ex = execution.Execution(plan, root=str(root), key=self.KEY, url=self.URL, licences={"F": b"FAKE-LICENCE-FILE"}).start()
for _ in range(250):
for _ in range(3000): # 60 s: the part starts after the backend is copied
if ready.exists():
break
time.sleep(0.02)
self.assertTrue(ready.exists(), "the part never started")
self.assertTrue(os.path.exists(f"/dev/shm/nullius-{name}/F"))
ex.stop()
self.wait(ex)
self.assertEqual(ex.state, "stopped", ex.lines)
self.assertEqual((ex.state, ex.exit_code), ("stopped", 130), ex.lines) # killed, not a part that ran out its sleep
self.assertFalse(os.path.exists(f"/dev/shm/nullius-{name}"))

def test_a_launch_the_host_never_answered_is_asked_once_more_and_starts_once(self):
Expand Down
Loading