Skip to content

fix: make TestLockPortSameDirectory_NoError resilient to busy ports#83

Open
dapi wants to merge 9 commits intomasterfrom
fix/flaky-test-lock-same-dir
Open

fix: make TestLockPortSameDirectory_NoError resilient to busy ports#83
dapi wants to merge 9 commits intomasterfrom
fix/flaky-test-lock-same-dir

Conversation

@dapi
Copy link
Owner

@dapi dapi commented Mar 2, 2026

Summary

  • Replace hardcoded port 3003 in TestLockPortSameDirectory_NoError with dynamically discovered free port
  • Scans the configured range (3000-4000) for an available port before running the test
  • Prevents flakiness when port 3003 is occupied by other services (e.g. docker-proxy)

Test plan

  • TestLockPortSameDirectory_NoError passes
  • Full test suite passes (go test ./...)

🤖 Generated with Claude Code

dapi and others added 8 commits March 2, 2026 10:52
Instead of hardcoding port 3003, dynamically find a free port within
the configured range (3000-4000). This prevents flakiness when the
hardcoded port is in use by other services (e.g. docker-proxy).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Revert err2 back to idiomatic err (no shadowing conflict)
- Fix "Step 1" comment: allocate -> allocate and lock
- Add allocation state verification after re-lock (matches sibling test pattern)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Move port discovery after setup to minimize TOCTOU window
- Use t.Skipf instead of t.Fatalf for first --lock call (matches project
  pattern for port-unavailable scenarios)
- Add .gitignore entries for pr-review-fix-loop artifacts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Narrow t.Skipf guard on first --lock call to only skip for TOCTOU-related
failures ("in use", "busy"). All other failures now use t.Fatalf so real
regressions in the --lock code path are not silently skipped.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Check for external allocation path in Step 1 output after success.
If port was claimed by external process between discovery and lock,
skip the test instead of continuing with misleading state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change t.Fatal to t.Skipf when no free port is found in range,
matching project convention for port-unavailability scenarios.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Check fmt.Sscanf error return value (errcheck)
- Add unreachable return after t.Fatal to satisfy staticcheck SA5011
  (staticcheck doesn't recognize t.Fatal as terminating)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dapi dapi closed this Mar 2, 2026
@dapi dapi reopened this Mar 2, 2026
- Use port-specific TOCTOU string matching instead of generic "in use"/"busy"
- Verify external allocation state instead of blindly skipping
- Add comment explaining why Step 2 is immune to TOCTOU
- Log last error when no free port found in scan
- Validate parsed port range (1-65535) in Sscanf test
- Verify Name field preserved after re-lock

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant