|
12 | 12 | from .http.httpclienttestbase import HttpClientTestBase, MockResponse |
13 | 13 | from ..anyorderlist import AnyOrderList |
14 | 14 |
|
15 | | - |
16 | 15 | def _wait_for_call_count(mock_obj, expected: int, *, timeout: float = 3.0, min_elapsed: Optional[float] = None): |
| 16 | + |
17 | 17 | """Wait until mock_obj.call_count >= expected or timeout. |
18 | 18 |
|
19 | 19 | Args: |
@@ -2420,12 +2420,15 @@ def test__create_writer_with_buffer_time__sends_when_timer_elapsed(self): |
2420 | 2420 | writer.write(path, tbase.DataType.INT32, value, timestamp=timestamp) |
2421 | 2421 | self._client.all_requests.assert_not_called() |
2422 | 2422 |
|
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) |
2426 | 2425 | 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 | + ) |
2429 | 2432 |
|
2430 | 2433 | utctime = ( |
2431 | 2434 | datetime.fromtimestamp(timestamp.timestamp(), timezone.utc) |
@@ -2495,11 +2498,16 @@ def test__create_writer_with_buffer_size_and_timer__obeys_both_settings(self): |
2495 | 2498 | ) |
2496 | 2499 |
|
2497 | 2500 | 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) |
2501 | 2504 | 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 | + ) |
2503 | 2511 | assert 2 == self._client.all_requests.call_count |
2504 | 2512 | assert self._client.all_requests.call_args_list[1] == mock.call( |
2505 | 2513 | "POST", |
|
0 commit comments