Commit bd7fa38
authored
fix: replace asyncio.sleep FAF guards with deterministic awaits (#919)
* fix: replace asyncio.sleep FAF guards with deterministic awaits
Bumps cpex to 0.1.0.dev12, which exposes PluginResult.background_tasks
and wait_for_background_tasks(). Uses these to eliminate all racy
asyncio.sleep() calls that were guarding FIRE_AND_FORGET plugin
completion in tests.
- Add drain_background_tasks() to mellea/plugins/manager.py: accumulates
PluginResult objects with background tasks in invoke_hook(), drains via
wait_for_background_tasks() in tests
- test/plugins/test_execution_modes.py: capture invoke_hook result and
call result.wait_for_background_tasks() directly
- test/telemetry/test_metrics_backend.py: replace 7x asyncio.sleep(0.05)
with drain_background_tasks()
Closes #691
Assisted-by: Claude Code
Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
* fix: isolate FAF plugin results per test to prevent cross-loop errors
Add discard_background_tasks() to clear accumulated FIRE_AND_FORGET
results without awaiting them, and call it in the enable_metrics fixture
to discard stale results from previous test event loops before each test.
Also clears _pending_background_results in shutdown_plugins() for
completeness.
Assisted-by: Claude Code
Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
* fix: gate background result collection behind opt-in flag
Adds `_collect_background_results` boolean (default False) so
`_pending_background_results` is never populated in production.
Collection is enabled/disabled explicitly by test fixtures via the new
`enable_background_collection()` / `disable_background_collection()`
helpers, eliminating the unbounded growth on metrics-enabled servers.
Also replaces "FAF" abbreviation in docstrings with "fire-and-forget"
for clarity.
Assisted-by: Claude Code
Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
---------
Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>1 parent 790c319 commit bd7fa38
5 files changed
Lines changed: 68 additions & 28 deletions
File tree
- mellea/plugins
- test
- plugins
- telemetry
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
34 | 70 | | |
35 | 71 | | |
36 | 72 | | |
| |||
143 | 179 | | |
144 | 180 | | |
145 | 181 | | |
| 182 | + | |
146 | 183 | | |
147 | 184 | | |
148 | 185 | | |
| |||
229 | 266 | | |
230 | 267 | | |
231 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
232 | 272 | | |
233 | 273 | | |
234 | 274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
26 | 24 | | |
27 | 25 | | |
28 | 26 | | |
| |||
344 | 342 | | |
345 | 343 | | |
346 | 344 | | |
347 | | - | |
| 345 | + | |
348 | 346 | | |
349 | | - | |
350 | | - | |
351 | | - | |
| 347 | + | |
| 348 | + | |
352 | 349 | | |
353 | 350 | | |
354 | 351 | | |
| |||
413 | 410 | | |
414 | 411 | | |
415 | 412 | | |
416 | | - | |
| 413 | + | |
417 | 414 | | |
418 | | - | |
| 415 | + | |
| 416 | + | |
419 | 417 | | |
420 | 418 | | |
421 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
| |||
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
| 49 | + | |
| 50 | + | |
44 | 51 | | |
45 | 52 | | |
46 | 53 | | |
| |||
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
| 62 | + | |
55 | 63 | | |
56 | 64 | | |
57 | 65 | | |
| |||
169 | 177 | | |
170 | 178 | | |
171 | 179 | | |
172 | | - | |
173 | | - | |
| 180 | + | |
174 | 181 | | |
175 | 182 | | |
176 | 183 | | |
| |||
235 | 242 | | |
236 | 243 | | |
237 | 244 | | |
238 | | - | |
239 | | - | |
| 245 | + | |
240 | 246 | | |
241 | 247 | | |
242 | 248 | | |
| |||
290 | 296 | | |
291 | 297 | | |
292 | 298 | | |
293 | | - | |
294 | | - | |
| 299 | + | |
295 | 300 | | |
296 | 301 | | |
297 | 302 | | |
| |||
354 | 359 | | |
355 | 360 | | |
356 | 361 | | |
357 | | - | |
358 | | - | |
| 362 | + | |
359 | 363 | | |
360 | 364 | | |
361 | 365 | | |
| |||
413 | 417 | | |
414 | 418 | | |
415 | 419 | | |
416 | | - | |
417 | | - | |
| 420 | + | |
418 | 421 | | |
419 | 422 | | |
420 | 423 | | |
| |||
470 | 473 | | |
471 | 474 | | |
472 | 475 | | |
473 | | - | |
474 | | - | |
| 476 | + | |
475 | 477 | | |
476 | 478 | | |
477 | 479 | | |
| |||
508 | 510 | | |
509 | 511 | | |
510 | 512 | | |
511 | | - | |
512 | | - | |
| 513 | + | |
513 | 514 | | |
514 | 515 | | |
515 | 516 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments