Skip to content

Commit c3230f3

Browse files
iterating
1 parent 4d8f056 commit c3230f3

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

tests/tag/test_tagmanager.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from .http.httpclienttestbase import HttpClientTestBase, MockResponse
1313
from ..anyorderlist import AnyOrderList
1414

15-
1615
def _wait_for_call_count(mock_obj, expected: int, *, timeout: float = 3.0, min_elapsed: Optional[float] = None):
16+
1717
"""Wait until mock_obj.call_count >= expected or timeout.
1818
1919
Args:
@@ -2420,12 +2420,15 @@ def test__create_writer_with_buffer_time__sends_when_timer_elapsed(self):
24202420
writer.write(path, tbase.DataType.INT32, value, timestamp=timestamp)
24212421
self._client.all_requests.assert_not_called()
24222422

2423-
# Warm wait: allow timer thread to start; > configured buffer time but small overall.
2424-
time.sleep(buffer_ms / 1000 * 1.5)
2425-
# Should still not have flushed yet (some jitter allowed). If it has, test still passes but we note it.
2423+
warm = buffer_ms / 1000 * 2.5 # generous warm period for slow CI start
2424+
time.sleep(warm)
24262425
if self._client.all_requests.call_count == 0:
2427-
# Now wait until call observed or timeout, enforcing not too early flush (<20ms) to catch regressions.
2428-
_wait_for_call_count(self._client.all_requests, 1, timeout=3.0, min_elapsed=0.02)
2426+
_wait_for_call_count(
2427+
self._client.all_requests,
2428+
1,
2429+
timeout=5.0,
2430+
min_elapsed=buffer_ms / 1000 * 0.4, # at least 40% of interval to avoid racey early flush
2431+
)
24292432

24302433
utctime = (
24312434
datetime.fromtimestamp(timestamp.timestamp(), timezone.utc)
@@ -2495,11 +2498,16 @@ def test__create_writer_with_buffer_size_and_timer__obeys_both_settings(self):
24952498
)
24962499

24972500
writer2.write(path, tbase.DataType.INT32, value3, timestamp=timestamp)
2498-
assert 1 == self._client.all_requests.call_count # still only size-based flush so far
2499-
# Warm wait beyond buffer time; only after this should timer flush occur.
2500-
time.sleep(buffer_ms / 1000 * 1.5)
2501+
assert 1 == self._client.all_requests.call_count
2502+
# Use longer warm period in CI to allow thread scheduling
2503+
time.sleep(buffer_ms / 1000 * 2.5)
25012504
if self._client.all_requests.call_count == 1:
2502-
_wait_for_call_count(self._client.all_requests, 2, timeout=3.0, min_elapsed=0.02)
2505+
_wait_for_call_count(
2506+
self._client.all_requests,
2507+
2,
2508+
timeout=5.0,
2509+
min_elapsed=buffer_ms / 1000 * 0.4,
2510+
)
25032511
assert 2 == self._client.all_requests.call_count
25042512
assert self._client.all_requests.call_args_list[1] == mock.call(
25052513
"POST",

0 commit comments

Comments
 (0)