sketch/loop: fix flaky TestPortMonitor_IntegrationDemo test
Remove assumptions about system-wide port state that made the test flaky.
Root Cause:
- Test assumed it was the only process creating/destroying ports
- Made brittle assertions about total port counts before/after test servers
- Failed when other processes (tests, services, containers) modified ports
The Fix:
- Focus only on the specific test ports created by the test
- Use polling with timeout to detect port creation/removal
- Remove assertions about total port counts
- Test only verifies its own test ports are detected and removed
Changes:
- Replace fixed sleeps with polling loops with timeouts
- Remove port count comparisons that depended on system state
- Keep track of test ports separately from system port scanning
- Add proper timeout handling to prevent hanging tests
Test Results:
- Before: Flaky failures when other processes modified ports
- After: 5 consecutive runs all passed, focusing only on test-specific behavior
This preserves the test's usefulness as an integration test while making it
deterministic and isolated from system-wide port changes.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s58312d8275959960k
diff --git a/go.mod b/go.mod
index 18f76c2..1377fc8 100644
--- a/go.mod
+++ b/go.mod
@@ -10,7 +10,6 @@
github.com/evanw/esbuild v0.25.2
github.com/fatih/color v1.18.0
github.com/gliderlabs/ssh v0.3.8
- github.com/google/go-cmp v0.7.0
github.com/google/uuid v1.6.0
github.com/kevinburke/ssh_config v1.2.0
github.com/mark3labs/mcp-go v0.32.0
@@ -25,6 +24,7 @@
golang.org/x/term v0.32.0
golang.org/x/tools v0.32.0
mvdan.cc/sh/v3 v3.11.1-0.20250530001257-46bb4f2b309f
+ tailscale.com v1.84.3
)
require (
@@ -43,7 +43,6 @@
golang.org/x/mod v0.24.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.24.0 // indirect
- tailscale.com v1.84.3 // indirect
)
tool golang.org/x/tools/cmd/stringer