2 Commits

Author SHA1 Message Date
lukaszraczylo 3f11219dc1 test: drain healthcheck goroutine + lock read in HealthCallback test
CI on Linux flagged a race in TestStartWorker_HealthCallback_StatusChange:
the test read ui.updates while the healthchecker's per-port goroutine
(spawned by Register at checker.go:164) was still running and could
fire UpdateStatus through notifyStatusChange.

The earlier mutex on MockStatusUpdater protected the writes; the read
side was unprotected, and the goroutine had not finished by the time
the test started ranging over the slice on slower runners.

Fix:
  - call healthChecker.Unregister(fwd.ID()) to drain the per-port
    goroutine before reading
  - hold ui.mu around the slice read for belt-and-suspenders happens-
    before, regardless of goroutine timing

Verified locally with go test -race -count=20 on the targeted test
and -count=3 on the full forward package.
2026-05-06 18:24:38 +01:00
lukaszraczylo ed80015e23 test: cover forward manager/worker/watchdog/portchecker
internal/forward: 45.9% -> 70.8%. Adds 14 critical-gap tests:
  - Manager.startWorker registration + duplicate error + healthcheck
    callback paths (status changes via MarkStarting/MarkReconnecting)
    + watchdog hung-callback (backdated heartbeat + checkWorkers).
  - stopWorker delegate + stopWorkerInternal removeFromUI=false.
  - DisableForward / EnableForward all error paths.
  - Reload diff logic: remove-stale, keep-unchanged, port conflict,
    empty new-config, currentConfig update.
  - SetMDNSPublisher trivial setter.
  - Watchdog.RegisterWorkerWithResponder alive/dead/transition cycle
    + pollHeartbeats direct + monitorLoop heartbeat ticker branch.
  - ForwardWorker.sleepWithBackoff (normal/cancelled/verbose) +
    IsAlive doneChan branch + Start terminates on cancel.
  - Manager.Start port-conflict path.
  - getProcessUsingPortUnix empty-bound and active-bound paths.

Remaining gaps (untestable without refactoring):
  - Windows-only branches (build tag prevents execution on macOS/Linux)
  - worker.run / establishForward — need a fake k8s.PortForwarder, but
    the Manager field is *k8s.PortForwarder (concrete), so a mock
    cannot be injected without source-level refactor.
2026-05-06 14:08:56 +01:00