Repository navigation
[client] Make conntrack cap and UDP cleanup tests deterministic - #8625
Conversation
The cap tests assert that the oldest flow is evicted, but eviction picks the smallest lastSeen and breaks ties by map iteration order. On a coarse clock (Windows) flows admitted back to back share a timestamp, so the "oldest" flow could survive. The tests now pin each flow's lastSeen to a distinct, increasing value after admitting it. TestUDPTracker_Cleanup slept for timeout plus two ticker intervals and raced the real ticker under load (macOS CI). It now drives the cleanup routine with a test-owned tick channel, expires flows explicitly through lastSeen, and also checks that a fresh flow survives the pass.
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|



Describe your changes
Two conntrack tests flake in CI on PRs that don't touch the client (seen on #8619 and #8620).
TestUDPCapEvicts(Windows): eviction takes the entry with the smallestlastSeenand breaks ties by map iteration order. On Windows' coarse clock, flows admitted back to back can share a timestamp, so the flow the test calls "oldest" can survive. I reproduced this on Linux by giving every flow the samelastSeen, and the same flow (SrcPort 0x7530) survived. The cap tests now set each flow'slastSeento a distinct, increasing value after it's admitted, so "oldest" is always well defined. The TCP and ICMP cap tests had the same weakness and get the same fix. I left production eviction alone: tied entries are equally old as far as the tracker can tell, and the scan is already a sampled approximation of LRU.TestUDPTracker_Cleanup(macOS): it slept 100ms and hoped the 25ms ticker had fired. Under CPU load it failed 1 run in 200 locally. It now sends the cleanup routine a tick over a channel the test owns, expires flows by settinglastSeendirectly, and waits for the routine to exit. It also adds a fresh flow that has to survive cleanup.Verified with
go test -race -count=200(and-count=1000), withGOMAXPROCS=1and with 16 busy loops on 4 cores: no failures. Both tests still fail when eviction is changed to pick the newest flow, or cleanup is changed to remove everything.Issue ticket number and link
No issue: this changes tests only.
Stack
Checklist
Documentation
Select exactly one:
Only test code changes; nothing user-facing.
Docs PR URL (required if "docs added" is checked)
Paste the PR link from https://github.com/netbirdio/docs here:
https://github.com/netbirdio/docs/pull/__
Generated by Claude Code
Summary by CodeRabbit