|
1 | 1 | import contextlib |
2 | 2 | import time |
3 | 3 |
|
4 | | -from python_on_whales.exceptions import DockerException |
5 | | - |
6 | 4 | from kloudkit.testshed.docker.container import Container |
7 | | -from kloudkit.testshed.docker.probes.http_probe import HttpProbe |
| 5 | +from kloudkit.testshed.docker.probes.probe import Probe |
8 | 6 |
|
9 | 7 | import pytest |
10 | 8 |
|
11 | 9 |
|
12 | 10 | class ReadinessCheck: |
13 | 11 | def __init__( |
14 | | - self, container: Container, probe: HttpProbe, *, container_logs=None |
| 12 | + self, container: Container, probe: Probe, *, container_logs=None |
15 | 13 | ): |
16 | 14 | self._container: Container = container |
17 | | - self._probe: HttpProbe = probe |
| 15 | + self._probe: Probe = probe |
18 | 16 | self._container_logs = container_logs |
19 | 17 |
|
20 | | - @property |
21 | | - def command(self) -> list[str]: |
22 | | - """Full probe test command.""" |
23 | | - |
24 | | - return [*self._probe.command.split(" "), self._probe.url] |
25 | | - |
26 | 18 | def wait(self) -> None: |
27 | | - """Wait until a container responds on the given endpoint.""" |
| 19 | + """Wait until a container passes the probe check.""" |
28 | 20 |
|
29 | 21 | deadline = time.time() + self._probe.timeout |
30 | 22 |
|
31 | | - failure_message = ( |
32 | | - f"URL [{self._probe.url}] was not reachable within {self._probe.timeout}s" |
33 | | - ) |
34 | | - |
35 | 23 | while time.time() < deadline: |
36 | 24 | try: |
37 | | - self._container.execute(self.command, raises=True) |
| 25 | + self._probe.check(self._container) |
38 | 26 |
|
39 | 27 | return |
40 | | - except DockerException: |
| 28 | + except Exception: |
41 | 29 | time.sleep(0.1) |
42 | 30 |
|
43 | 31 | if self._container_logs: |
44 | 32 | with contextlib.suppress(Exception): |
45 | 33 | self._container_logs(self._container.logs()) |
46 | 34 |
|
47 | | - pytest.fail(failure_message, pytrace=False) |
| 35 | + pytest.fail(self._probe.failure_message, pytrace=False) |
0 commit comments