Skip to content

Deduplicate the auto_discover shell bootstraps and poll instead of sleeping #47

Description

@FAZuH

Part of the whole-repo test-suite audit (2026-09-30). Cuts 330 lines of copy-paste and 144 seconds of wall clock.

What to build

Every auto_discover integration test bootstrapping its harness through the existing helper, and waiting on a poller instead of a fixed sleep.

Findings

  • 18 hand-rolled ~30-line bootstraps. tests/auto_discover/recovery.rs inlines the consul + dummy0 + natmap + cat > /tmp/discovery.yaml + auto-discover block ten times (rg -c "cat > /tmp/discovery.yaml" tests/auto_discover/recovery.rs returns 10; consul agent -dev appears seven times). tests/auto_discover/forwarding.rs inlines the consul + natmap pair seven times, and startup_race.rs:17-49 inlines the whole thing once. new_format_setup_with_defaults_ext at tests/auto_discover/mod.rs:114 and new_format_setup at :110 already emit exactly that block, and 32 tests use them. There is no tests/common/ because mod.rs already is it; the copy-paste bypasses it.
  • 160 fixed sleeps, 308 seconds of unconditional wait, across the tests/ tree. 36 of them are sleep 4 waiting for a Docker event to reach Consul. wait_for_consul_service at mod.rs:166 polls for exactly that condition and is used by only three tests. tests/natmap_docker.rs adds 39 copies of for i in $(seq 1 20); do [ -S /tmp/ns ] && break; sleep 0.2; done; extract one wait_for_socket helper.
  • A shutdown-flush race. tests/natmap_docker.rs:287,309 send kill -INT $DAEMON_PID and then poll [ -S /tmp/ns ], but the socket already exists, so the loop breaks on its first iteration and the flush assertion races the shutdown. Poll kill -0 $DAEMON_PID instead.
  • A duplicate test. tests/auto_discover/recovery.rs:411 remove_all_services_clean_slate and :266 remove_service_from_config_stale_deregistered are the same test: both kill the daemon, write services: {}, run sync, and assert the service is gone. Merge into one.

Acceptance criteria

  • No test in tests/auto_discover/ writes a discovery config inline
  • rg -c "sleep 4" tests/ finds no unconditional four-second wait for a Consul service
  • Total suite wall clock drops by at least two minutes
  • The shutdown-flush tests wait on the process, not on the socket file
  • No test becomes order-dependent. The Docker suite runs single-threaded today via .cargo/config.toml; do not rely on that for correctness.
  • cargo test -p lab-ops --test auto_discover passes

Blocked by

None (can start immediately).

Note: run the auto_discover integration suite deliberately, not as a side effect.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions