Commit 82de51d
test: fix race condition in delayed failure event test (#47)
**Requirements**
- [x] I have added test coverage for new or changed functionality
- [x] I have followed the repository's [pull request submission
guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests)
- [x] I have validated my changes against all supported platform
versions
**Related issues**
None.
**Describe the solution you've provided**
Three event emission tests
(`test_provider_emits_ready_event_when_immediately_ready`,
`test_provider_emits_error_event_immediately_failed`,
`test_provider_emits_error_event_delayed_failure`) check a counter
immediately after `set_provider` without waiting for the event to be
dispatched. The OpenFeature SDK now dispatches provider events
asynchronously, so these assertions fail.
The fix uses `threading.Event` with `wait(timeout=5)`, matching the
pattern already used by `test_provider_emits_stale_event` and
`test_provider_emits_configuration_event`.
**Describe alternatives you've considered**
Could add `time.sleep()` calls, but event-based waiting is more robust
and consistent with existing tests.
**Additional context**
All 66 tests pass consistently. Lint (mypy) also passes.
Link to Devin session:
https://app.devin.ai/sessions/385a2c260fe8433ea7e6af74fcde903c
Requested by: @kinyoklion
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Test-only changes with no runtime or library behavior modified.
>
> **Overview**
> Fixes flaky provider lifecycle tests that assumed **OpenFeature**
dispatches `PROVIDER_READY` / `PROVIDER_ERROR` synchronously on
`set_provider`.
>
> **`test_provider_emits_ready_event_when_immediately_ready`**,
**`test_provider_emits_error_event_immediately_failed`**, and
**`test_provider_emits_error_event_delayed_failure`** now wait on a
**`threading.Event`** (with **`wait(timeout=5)`**) set from the handler
before asserting the emission count, plus a short **`time.sleep(0.1)`**
so the counter update is visible. Handlers were simplified (shared
**`emission_count`**, **`thread_event.set()`**). This matches
**`test_provider_emits_stale_event`** and
**`test_provider_emits_configuration_event`**.
>
> No production/provider code changes—tests only.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
0340a25. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>1 parent 3d422b4 commit 82de51d
1 file changed
Lines changed: 28 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
153 | | - | |
| 154 | + | |
154 | 155 | | |
| 156 | + | |
155 | 157 | | |
156 | 158 | | |
157 | 159 | | |
158 | | - | |
159 | | - | |
| 160 | + | |
160 | 161 | | |
161 | | - | |
| 162 | + | |
| 163 | + | |
162 | 164 | | |
163 | | - | |
164 | | - | |
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
170 | 173 | | |
171 | | - | |
| 174 | + | |
172 | 175 | | |
173 | 176 | | |
174 | 177 | | |
175 | 178 | | |
176 | 179 | | |
177 | | - | |
| 180 | + | |
178 | 181 | | |
| 182 | + | |
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
182 | | - | |
183 | | - | |
| 186 | + | |
184 | 187 | | |
185 | | - | |
| 188 | + | |
| 189 | + | |
186 | 190 | | |
187 | 191 | | |
188 | 192 | | |
| |||
191 | 195 | | |
192 | 196 | | |
193 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
194 | 201 | | |
195 | | - | |
| 202 | + | |
196 | 203 | | |
197 | 204 | | |
198 | 205 | | |
199 | 206 | | |
200 | 207 | | |
201 | | - | |
| 208 | + | |
202 | 209 | | |
| 210 | + | |
203 | 211 | | |
204 | 212 | | |
205 | 213 | | |
206 | | - | |
207 | | - | |
| 214 | + | |
208 | 215 | | |
209 | | - | |
| 216 | + | |
| 217 | + | |
210 | 218 | | |
211 | 219 | | |
212 | 220 | | |
| |||
215 | 223 | | |
216 | 224 | | |
217 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
218 | 229 | | |
219 | | - | |
| 230 | + | |
220 | 231 | | |
221 | 232 | | |
222 | 233 | | |
| |||
0 commit comments