From 6f270a08b69924a48ca7f91fa5ab58820e9a83bc Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sun, 29 Jun 2025 13:21:44 +0100 Subject: [PATCH 1/2] Make TC_POOLING_INTERVAL/sleep_time a float This config variable gets passed into `time.sleep`, which can work with ints and floats. Making this a float type allows polling intervals under a second, which can reduce startup times for containers that spin up very quickly. --- core/testcontainers/core/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/testcontainers/core/config.py b/core/testcontainers/core/config.py index e521bd4d..0c419604 100644 --- a/core/testcontainers/core/config.py +++ b/core/testcontainers/core/config.py @@ -97,7 +97,7 @@ def read_tc_properties() -> dict[str, str]: @dataclass class TestcontainersConfiguration: max_tries: int = int(environ.get("TC_MAX_TRIES", "120")) - sleep_time: int = int(environ.get("TC_POOLING_INTERVAL", "1")) + sleep_time: float = float(environ.get("TC_POOLING_INTERVAL", "1")) ryuk_image: str = environ.get("RYUK_CONTAINER_IMAGE", "testcontainers/ryuk:0.8.1") ryuk_privileged: bool = get_bool_env("TESTCONTAINERS_RYUK_PRIVILEGED") ryuk_disabled: bool = get_bool_env("TESTCONTAINERS_RYUK_DISABLED") From a243ff04d8d72712927316f171ba8664a18e017e Mon Sep 17 00:00:00 2001 From: David Ankin Date: Thu, 7 Aug 2025 08:57:01 -0400 Subject: [PATCH 2/2] fix mypy --- core/testcontainers/core/config.py | 2 +- core/testcontainers/core/waiting_utils.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/testcontainers/core/config.py b/core/testcontainers/core/config.py index 0c419604..9eac25e0 100644 --- a/core/testcontainers/core/config.py +++ b/core/testcontainers/core/config.py @@ -130,7 +130,7 @@ def tc_properties_get_tc_host(self) -> Union[str, None]: return self.tc_properties.get("tc.host") @property - def timeout(self) -> int: + def timeout(self) -> float: return self.max_tries * self.sleep_time @property diff --git a/core/testcontainers/core/waiting_utils.py b/core/testcontainers/core/waiting_utils.py index d83101d0..7775fce9 100644 --- a/core/testcontainers/core/waiting_utils.py +++ b/core/testcontainers/core/waiting_utils.py @@ -73,15 +73,15 @@ class WaitStrategy(ABC): """Base class for all wait strategies.""" def __init__(self) -> None: - self._startup_timeout: int = config.timeout + self._startup_timeout: float = config.timeout self._poll_interval: float = config.sleep_time def with_startup_timeout(self, timeout: Union[int, timedelta]) -> "WaitStrategy": """Set the maximum time to wait for the container to be ready.""" if isinstance(timeout, timedelta): - self._startup_timeout = int(timeout.total_seconds()) + self._startup_timeout = float(int(timeout.total_seconds())) else: - self._startup_timeout = timeout + self._startup_timeout = float(timeout) return self def with_poll_interval(self, interval: Union[float, timedelta]) -> "WaitStrategy":