Skip to content

Commit 30bb8ec

Browse files
committed
fix: Measure the start_wait tests against a monotonic clock and a bound
1 parent 0047a65 commit 30bb8ec

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎ldclient/testing/test_ldclient_end_to_end.py‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,14 @@ def test_client_does_not_initialize_in_streaming_mode_with_401_error():
6262
stream_server.for_path('/all', BasicResponse(401))
6363
config = Config(sdk_key=sdk_key, stream_uri=stream_server.uri, send_events=False)
6464

65-
started = time.time()
66-
with LDClient(config=config, start_wait=0.5) as client:
67-
elapsed = time.time() - started
68-
assert elapsed >= 0.5
65+
start_wait = 0.5
66+
started = time.monotonic()
67+
with LDClient(config=config, start_wait=start_wait) as client:
68+
elapsed = time.monotonic() - started
69+
# A bound rather than the exact start_wait: Event.wait can return a
70+
# fraction early against a separate clock. Failing fast took
71+
# milliseconds, so this still catches it.
72+
assert elapsed >= start_wait / 2
6973
assert not client.is_initialized()
7074
assert client.variation(always_true_flag['key'], user, False) is False
7175

@@ -104,10 +108,12 @@ def test_client_does_not_initialize_in_polling_mode_with_401_error():
104108
poll_server.for_path('/sdk/latest-all', BasicResponse(401))
105109
config = Config(sdk_key=sdk_key, base_uri=poll_server.uri, stream=False, send_events=False)
106110

107-
started = time.time()
108-
with LDClient(config=config, start_wait=0.5) as client:
109-
elapsed = time.time() - started
110-
assert elapsed >= 0.5
111+
start_wait = 0.5
112+
started = time.monotonic()
113+
with LDClient(config=config, start_wait=start_wait) as client:
114+
elapsed = time.monotonic() - started
115+
# See the streaming case above: a bound, not the exact start_wait.
116+
assert elapsed >= start_wait / 2
111117
assert not client.is_initialized()
112118
assert client.variation(always_true_flag['key'], user, False) is False
113119

0 commit comments

Comments
 (0)