Skip to content

Commit a072f3f

Browse files
fix(core): Make TC_POOLING_INTERVAL/sleep_time a float (#839)
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. --------- Co-authored-by: David Ankin <[email protected]>
1 parent 003046b commit a072f3f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

core/testcontainers/core/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def read_tc_properties() -> dict[str, str]:
9797
@dataclass
9898
class TestcontainersConfiguration:
9999
max_tries: int = int(environ.get("TC_MAX_TRIES", "120"))
100-
sleep_time: int = int(environ.get("TC_POOLING_INTERVAL", "1"))
100+
sleep_time: float = float(environ.get("TC_POOLING_INTERVAL", "1"))
101101
ryuk_image: str = environ.get("RYUK_CONTAINER_IMAGE", "testcontainers/ryuk:0.8.1")
102102
ryuk_privileged: bool = get_bool_env("TESTCONTAINERS_RYUK_PRIVILEGED")
103103
ryuk_disabled: bool = get_bool_env("TESTCONTAINERS_RYUK_DISABLED")
@@ -130,7 +130,7 @@ def tc_properties_get_tc_host(self) -> Union[str, None]:
130130
return self.tc_properties.get("tc.host")
131131

132132
@property
133-
def timeout(self) -> int:
133+
def timeout(self) -> float:
134134
return self.max_tries * self.sleep_time
135135

136136
@property

core/testcontainers/core/waiting_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ class WaitStrategy(ABC):
7373
"""Base class for all wait strategies."""
7474

7575
def __init__(self) -> None:
76-
self._startup_timeout: int = config.timeout
76+
self._startup_timeout: float = config.timeout
7777
self._poll_interval: float = config.sleep_time
7878

7979
def with_startup_timeout(self, timeout: Union[int, timedelta]) -> "WaitStrategy":
8080
"""Set the maximum time to wait for the container to be ready."""
8181
if isinstance(timeout, timedelta):
82-
self._startup_timeout = int(timeout.total_seconds())
82+
self._startup_timeout = float(int(timeout.total_seconds()))
8383
else:
84-
self._startup_timeout = timeout
84+
self._startup_timeout = float(timeout)
8585
return self
8686

8787
def with_poll_interval(self, interval: Union[float, timedelta]) -> "WaitStrategy":

0 commit comments

Comments
 (0)