11import threading
2+ import time
23from typing import List , Union
34from unittest .mock import patch
45
@@ -150,10 +151,15 @@ def test_logger_changes_should_cascade_to_evaluation_converter(provider: LaunchD
150151
151152
152153def test_provider_emits_ready_event_when_immediately_ready ():
154+ emission_count = 0
155+ lock = threading .Lock ()
153156 thread_event = threading .Event ()
154157
155158 def handle_status (details : EventDetails ):
156159 if details .provider_name == 'launchdarkly-openfeature-server' :
160+ nonlocal emission_count
161+ with lock :
162+ emission_count += 1
157163 thread_event .set ()
158164
159165 api .add_handler (ProviderEvent .PROVIDER_READY , handle_status )
@@ -162,15 +168,24 @@ def handle_status(details: EventDetails):
162168 api .set_provider (openfeature_provider )
163169
164170 assert thread_event .wait (timeout = 5 )
171+ time .sleep (0.1 )
172+
173+ with lock :
174+ assert emission_count == 1
165175
166176 api .shutdown ()
167177
168178
169179def test_provider_emits_error_event_immediately_failed ():
180+ emission_count = 0
181+ lock = threading .Lock ()
170182 thread_event = threading .Event ()
171183
172184 def handle_status (details : EventDetails ):
173185 if details .provider_name == 'launchdarkly-openfeature-server' :
186+ nonlocal emission_count
187+ with lock :
188+ emission_count += 1
174189 thread_event .set ()
175190
176191 api .add_handler (ProviderEvent .PROVIDER_ERROR , handle_status )
@@ -181,15 +196,24 @@ def handle_status(details: EventDetails):
181196 api .set_provider (openfeature_provider )
182197
183198 assert thread_event .wait (timeout = 5 )
199+ time .sleep (0.1 )
200+
201+ with lock :
202+ assert emission_count == 1
184203
185204 api .shutdown ()
186205
187206
188207def test_provider_emits_error_event_delayed_failure ():
208+ emission_count = 0
209+ lock = threading .Lock ()
189210 thread_event = threading .Event ()
190211
191212 def handle_status (details : EventDetails ):
192213 if details .provider_name == 'launchdarkly-openfeature-server' :
214+ nonlocal emission_count
215+ with lock :
216+ emission_count += 1
193217 thread_event .set ()
194218
195219 api .add_handler (ProviderEvent .PROVIDER_ERROR , handle_status )
@@ -200,6 +224,10 @@ def handle_status(details: EventDetails):
200224 api .set_provider (openfeature_provider )
201225
202226 assert thread_event .wait (timeout = 5 )
227+ time .sleep (0.1 )
228+
229+ with lock :
230+ assert emission_count == 1
203231
204232 api .shutdown ()
205233
0 commit comments