Skip to content

Commit d9ea6ef

Browse files
committed
test: make completion-gating probe fail on regression and pod names unique
1 parent 9e62712 commit d9ea6ef

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

tests/integration/conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from collections.abc import Callable, Iterator
1313
from dataclasses import dataclass
1414
from pathlib import Path
15+
from uuid import uuid4
1516

1617
import pytest
1718

@@ -56,7 +57,6 @@ def run_pod(tmp_path: Path) -> Iterator[Callable[..., PodRun]]:
5657
case the script's own EXIT trap did not fire (timeout kill or early crash).
5758
"""
5859
created: list[str] = []
59-
counter = 0
6060

6161
def _run(
6262
compose: dict,
@@ -66,9 +66,7 @@ def _run(
6666
project_dir: "str | Path | None" = None,
6767
timeout: int = 180,
6868
) -> PodRun:
69-
nonlocal counter
70-
counter += 1
71-
pod = f"c2p-it-{counter}"
69+
pod = f"c2p-it-{uuid4().hex[:8]}"
7270
created.append(pod)
7371
options = EmitOptions(
7472
target=target,
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
"""service_completed_successfully ordering: a one-shot must finish before the target."""
1+
"""service_completed_successfully: the target observably requires the one-shot's output.
2+
3+
The one-shot sleeps, then writes a flag to a shared bind mount; the target reads it.
4+
If completion-gating regressed (one-shot backgrounded instead of run blocking), the
5+
target would run during the sleep, cat a missing file, exit non-zero, and fail the
6+
script under `set -e` -- so exit 0 + the flag content genuinely proves ordering.
7+
"""
28

39
from collections.abc import Callable
10+
from pathlib import Path
411

512
from tests.integration.conftest import PodRun
613

714

8-
def test_completion_gating_orders_one_shot(run_pod: Callable[..., PodRun]) -> None:
15+
def test_completion_gating_orders_one_shot(run_pod: Callable[..., PodRun], tmp_path: Path) -> None:
16+
(tmp_path / "shared").mkdir()
917
compose = {
1018
"services": {
11-
"init": {"image": "busybox:1.36", "command": ["sh", "-c", "exit 0"]},
19+
"init": {
20+
"image": "busybox:1.36",
21+
"volumes": ["./shared:/shared"],
22+
"command": ["sh", "-c", "sleep 2; echo done > /shared/flag"],
23+
},
1224
"app": {
1325
"image": "busybox:1.36",
26+
"volumes": ["./shared:/shared"],
1427
"depends_on": {"init": {"condition": "service_completed_successfully"}},
15-
"command": ["echo", "ready"],
28+
"command": ["sh", "-c", "cat /shared/flag"],
1629
},
1730
},
1831
}
19-
run = run_pod(compose, target="app")
20-
# The one-shot runs blocking (`podman run --rm`) before the target; under
21-
# `set -e` a non-zero init would abort the script. Exit 0 + "ready" proves order.
32+
run = run_pod(compose, target="app", project_dir=tmp_path)
2233
assert run.returncode == 0, run.stderr
23-
assert "ready" in run.stdout
34+
assert "done" in run.stdout

0 commit comments

Comments
 (0)