|
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 | +""" |
2 | 8 |
|
3 | 9 | from collections.abc import Callable |
| 10 | +from pathlib import Path |
4 | 11 |
|
5 | 12 | from tests.integration.conftest import PodRun |
6 | 13 |
|
7 | 14 |
|
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() |
9 | 17 | compose = { |
10 | 18 | "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 | + }, |
12 | 24 | "app": { |
13 | 25 | "image": "busybox:1.36", |
| 26 | + "volumes": ["./shared:/shared"], |
14 | 27 | "depends_on": {"init": {"condition": "service_completed_successfully"}}, |
15 | | - "command": ["echo", "ready"], |
| 28 | + "command": ["sh", "-c", "cat /shared/flag"], |
16 | 29 | }, |
17 | 30 | }, |
18 | 31 | } |
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) |
22 | 33 | assert run.returncode == 0, run.stderr |
23 | | - assert "ready" in run.stdout |
| 34 | + assert "done" in run.stdout |
0 commit comments