Repository navigation
Conversation
`test_restart_terminates_managers_and_starts_thread` patched `astrbot.core.core_lifecycle.threading.Thread`, and that attribute is the global `threading` module, so the patch replaced `threading.Thread` process-wide. `AstrBotCoreLifecycle.restart()` awaits `asyncio.to_thread(close_trace_store)`, and `ThreadPoolExecutor` creates its workers with `threading.Thread`. With the process-wide mock the worker was a `MagicMock` that never ran, so the submitted callable was never executed and the awaited future never completed: the test hung until the 30-minute CI job timeout. Patch the `threading` reference on the lifecycle module instead, which leaves the real `threading.Thread` and the default executor intact. The assertions on the restart thread are unchanged.
5 of 6 tasks
Author
|
Closing as a duplicate of #10617, which fixes the same restart-test hang (it mocks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tests/unit/test_core_lifecycle.py::TestAstrBotCoreLifecycleRestart::test_restart_terminates_managers_and_starts_threadhangs forever, so everyUnit Testsrun now dies on the 30-minute job timeout.On
masterall three lanes are cancelled at exactly the timeout:and the ubuntu log stops at 77%, right before
tests/unit/test_core_lifecycle.py:Root cause
The test patches
astrbot.core.core_lifecycle.threading.Thread:astrbot.core.core_lifecycle.threadingis the globalthreadingmodule, so this replacesthreading.Threadprocess-wide.AstrBotCoreLifecycle.restart()(await added in #10515) then calls:asyncio.to_thread()submits to aThreadPoolExecutor, and its_adjust_thread_count()spawns workers withthreading.Thread. With the mockin place the "worker" is a
MagicMockthat never runs, so the callable is neverexecuted and the awaited future never resolves. The event loop goes idle in
selectors.selectand the test hangs forever.Minimal reproduction, independent of the test suite:
Fix
Patch the
threadingreference on the lifecycle module instead ofthreading.Threaditself, so the realthreadingmodule,threading.Threadand the default executor stay intact. The assertions on the restart thread are
unchanged.
Verification
Before, on
master:After:
The suite previously stalled at 77% for the full 30-minute CI job timeout.
Summary by Sourcery
Fix the lifecycle restart test to isolate its thread mock and prevent executor-backed asynchronous work from hanging the test suite.
Bug Fixes:
Tests: