fix: replace asyncio.sleep FAF guards with deterministic awaits#919
fix: replace asyncio.sleep FAF guards with deterministic awaits#919ajbozarth wants to merge 3 commits intogenerative-computing:mainfrom
Conversation
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 generative-computing#691 Assisted-by: Claude Code Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
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>
|
Follow-up to address a test failure in The Fix: added Also clears |
|
Claude decided to delete my worktree for this PR instead of #895 when I went to clean up and I didn't noticed it picked the wrong branch name |
|
cc @araujof as the original plugins/hook author |
Misc PR
Type of PR
Description
Bumps
cpexto0.1.0.dev12, which addsPluginResult.background_tasksandwait_for_background_tasks()(upstream contextforge-org/contextforge-plugins-framework#33). Uses these to replace all racyasyncio.sleep()guards that were used to wait for FIRE_AND_FORGET plugin completion in tests.Changes:
mellea/plugins/manager.py: adddrain_background_tasks()— accumulatesPluginResultobjects with background tasks ininvoke_hook(), drains viawait_for_background_tasks()for tests where the hook fires inside a backend calltest/plugins/test_execution_modes.py: captureinvoke_hookresult directly and callresult.wait_for_background_tasks()(2 tests)test/telemetry/test_metrics_backend.py: replace 7×asyncio.sleep(0.05)withdrain_background_tasks()Testing
Attribution