|
12 | 12 | from testcontainers.core.config import ConnectionMode
|
13 | 13 | from testcontainers.core.config import testcontainers_config as c
|
14 | 14 | from testcontainers.core.docker_client import DockerClient
|
15 |
| -from testcontainers.core.exceptions import ContainerStartException |
| 15 | +from testcontainers.core.exceptions import ContainerConnectException, ContainerStartException |
16 | 16 | from testcontainers.core.labels import LABEL_SESSION_ID, SESSION_ID
|
17 | 17 | from testcontainers.core.network import Network
|
18 | 18 | from testcontainers.core.utils import is_arm, setup_logger
|
@@ -228,15 +228,21 @@ def _create_instance(cls) -> "Reaper":
|
228 | 228 | .with_env("RYUK_RECONNECTION_TIMEOUT", c.ryuk_reconnection_timeout)
|
229 | 229 | .start()
|
230 | 230 | )
|
231 |
| - wait_for_logs(Reaper._container, r".* Started!") |
| 231 | + wait_for_logs(Reaper._container, r".* Started!", timeout=20, raise_on_exit=True) |
232 | 232 |
|
233 | 233 | container_host = Reaper._container.get_container_host_ip()
|
234 | 234 | container_port = int(Reaper._container.get_exposed_port(8080))
|
235 | 235 |
|
| 236 | + if not container_host or not container_port: |
| 237 | + raise ContainerConnectException( |
| 238 | + f"Could not obtain network details for {Reaper._container._container.id}. Host: {container_host} Port: {container_port}" |
| 239 | + ) |
| 240 | + |
236 | 241 | last_connection_exception: Optional[Exception] = None
|
237 | 242 | for _ in range(50):
|
238 | 243 | try:
|
239 | 244 | Reaper._socket = socket()
|
| 245 | + Reaper._socket.settimeout(1) |
240 | 246 | Reaper._socket.connect((container_host, container_port))
|
241 | 247 | last_connection_exception = None
|
242 | 248 | break
|
|
0 commit comments