Skip to content

test: clean up simulated-acquisition output instead of littering /tmp - #640

Open
Alpaca233 wants to merge 1 commit into
masterfrom
test/cleanup-simulated-acquisition-output
Open

test: clean up simulated-acquisition output instead of littering /tmp#640
Alpaca233 wants to merge 1 commit into
masterfrom
test/cleanup-simulated-acquisition-output

Conversation

@Alpaca233

Copy link
Copy Markdown
Collaborator

Problem

get_test_multi_point_controller and get_test_qt_multi_point_controller point simulated acquisitions at a literal "/tmp/". Every test that runs an acquisition leaves ~180 MB of simulated image data in /tmp/unit_test_experiment_* forever. Accumulated runs filled an entire 782 GB disk on a dev machine on 2026-09-05 (38 GB of test output going back days).

Fix

  • The stub factories create the acquisition base dir with tempfile.mkdtemp(prefix="squid_unit_test_acquisition_") and register it in test_stubs._acquisition_output_dirs.
  • cleanup_leaked_hardware (the existing autouse teardown fixture in tests/conftest.py) deletes the registered dirs at the end of each test — after controllers/microscopes are closed, so no writer is alive when the tree is removed. Peak disk usage is now one test's output instead of an unbounded accumulation.
  • The watchdog breadcrumb dir (squid-test-watchdog-cleanup-<pid>, written during leaked-acquisition cleanup, never read) is removed at session finish.

Testing

  • New tests/control/test_stub_acquisition_cleanup.py covers the registration and the cleanup.
  • Full suite (CI selection): 1791 passed, 9 skipped, 1 xfailed — and /tmp contains no unit_test_experiment_*, squid_unit_test_acquisition_*, or watchdog-cleanup leftovers afterwards (verified in the same shell).

🤖 Generated with Claude Code

The stub multipoint controllers pointed simulated acquisitions at a literal
"/tmp/", and each run left ~180 MB of image data there forever - accumulated
runs filled an entire disk on 2026-09-05.

The stub factories now write under a mkdtemp dir registered in test_stubs;
cleanup_leaked_hardware deletes the registered dirs at test teardown, after
every writer is closed, and the watchdog breadcrumb dir is removed at session
finish. A full suite run now leaves /tmp empty.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The current cleanup helper can silently fail to delete output trees (and still deregister them), undermining the PR’s primary goal of preventing disk growth.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR prevents simulated-acquisition tests from accumulating large (~180 MB/run) image output under a hard-coded /tmp/ path by routing stub controllers to per-test temp directories and cleaning those directories during the existing autouse teardown.

Changes:

  • Add temp-dir creation + registration helpers for stub acquisition base paths and a cleanup routine.
  • Update stub multipoint controller factories (including Qt) to use registered temp dirs instead of "/tmp/".
  • Extend cleanup_leaked_hardware teardown to delete registered acquisition output dirs, and remove watchdog breadcrumb dirs at session end; add tests covering registration and cleanup.
File summaries
File Description
software/tests/control/test_stubs.py Introduces registered temp acquisition base paths and a cleanup helper; updates stub controller base path usage.
software/tests/control/test_stub_acquisition_cleanup.py Adds tests asserting stub controllers write under a registered temp dir and that cleanup removes it.
software/tests/control/gui_test_stubs.py Updates Qt stub multipoint controller to use the registered temp acquisition base path.
software/tests/conftest.py Hooks cleanup of registered acquisition output dirs into the autouse teardown; removes watchdog breadcrumb dir at session finish.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +29 to 33
def cleanup_stub_acquisition_dirs():
while _acquisition_output_dirs:
shutil.rmtree(_acquisition_output_dirs.pop(), ignore_errors=True)


Comment on lines +28 to +33
scope = control.microscope.Microscope.build_from_global_config(True)
mpc = ts.get_test_multi_point_controller(microscope=scope)
base_path = mpc.base_path

ts.cleanup_stub_acquisition_dirs()

# stub controller writes into is registered here so the autouse fixture in
# tests/conftest.py can delete it at test teardown - pointing them at a literal
# "/tmp/" used to accumulate output across runs until the disk filled.
_acquisition_output_dirs: list = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants