* fix(threads): stop and join the prompt cleanup thread, the image worker and the observer (#302, #370) - PromptTracker: the cleanup thread waits on a stop event instead of time.sleep; new shutdown(timeout=2) joins it and returns whether it ended. - ImageGenerationHandler.shutdown(timeout=5) now joins the worker and returns a bool; new close() is final: schedule() refuses and a sealed run's history re-check is dropped, so no worker restarts afterwards. - ImageMonitor.stop_monitoring(timeout=5) closes the handler first, then stops and joins the watchdog observer within one deadline. - Every test that builds a real tracker, handler or monitor ends with its final stop and an assertion, before its folder and databases go. - #370: the wrapper/session history test drains before dispose(); the held-write bound test uses 30 s ceilings instead of tight wall clocks. * test(history): drain the writer before asserting a bounded close it does not test (#370) * fix(threads): a later stop waits again for a worker or observer an earlier stop left running (#302) Review findings on #372: - ImageGenerationHandler keeps the workers a stop signalled that had not ended; every later shutdown/close joins them again, so a second call no longer returns True while the first worker still runs. - ImageMonitor.stop_monitoring keeps an observer or handler it left running and stops and joins it again on the next call. - A closed handler takes no awaiting history path, and a re-check that raced close() is not kept due. - Tests: second stops of a busy worker and a live observer, the closed handler's re-check paths, the handle test asserts the worker ended and stops before it asserts, and a no-new-thread check instead of set equality. * test(browser): the System reset restores every settings value, safety_backup included The frontend coverage shard of #372 failed in workspace-system-tagging: the review read "No safety backup (the policy is off)". The backups spec saves safety_backup=false, and /__test__/system/reset restored config.json but not PromptManagerConfig.SAFETY_BACKUP (nor INFINITE_SCROLL), so a later spec on the same worker server saw the policy off. The reset now captures and restores every non-tagging value POST /settings can change.
28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
"""Final stops for the background threads a test starts (#301, #302).
|
|
|
|
Every real ``ImageGenerationHandler``, ``ImageMonitor`` or ``PromptTracker``
|
|
a test constructs ends with its final stop and an assertion, before the
|
|
test's folder and databases go: ``close()`` for a handler,
|
|
``stop_monitoring()`` for a monitor, ``shutdown()`` for a tracker.
|
|
"""
|
|
|
|
from utils.prompt_tracker import PromptTracker
|
|
|
|
|
|
def stop_tracker(testcase, tracker):
|
|
"""Shut a real tracker's cleanup thread down; mocks are left alone."""
|
|
if isinstance(tracker, PromptTracker):
|
|
testcase.assertTrue(tracker.shutdown(), "prompt cleanup thread still running")
|
|
|
|
|
|
def close_handler(testcase, handler):
|
|
"""Close ``handler`` for good, then stop the tracker it was built with."""
|
|
testcase.assertTrue(handler.close(), "image worker still running")
|
|
stop_tracker(testcase, getattr(handler, "prompt_tracker", None))
|
|
|
|
|
|
def stop_monitor(testcase, monitor):
|
|
"""Stop ``monitor`` (its observer and worker), then its tracker."""
|
|
testcase.assertTrue(monitor.stop_monitoring(), "image monitor still running")
|
|
stop_tracker(testcase, getattr(monitor, "prompt_tracker", None))
|