Skip to content

test(config): make TestSchemelessLinear robust to coarse timers - #980

Merged
acamarata merged 1 commit into
mainfrom
dw5-cli-6
Oct 27, 2026
Merged

acamarata merged 1 commit into
mainfrom
dw5-cli-6

Conversation

@acamarata

@acamarata acamarata commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

What

TestSchemelessLinear (internal/credmask/linear_test.go, added in #979) failed on windows-2022 (run 40440673969): unit "@a(": 4000 B took 0s, 40000 B took 2.5518ms: not linear. Windows timers are coarse, so the small input read as 0s and the 50*prev + 2ms bound broke. The masking code is fine.

Note: the test lives in internal/credmask, not internal/config; config.MaskURLCredentials delegates to it. config's own TestMaskURLCredentialsLinear already has a 250 ms floor and was not changed.

Change (test only)

  • Time batches: double the repeat count until one batch lasts at least 3 ms, so no reading is 0.
  • Best (minimum) of 5 batches per size, reported per call.
  • Bound: 10x input must cost < 40x + 200 µs per call (a quadratic scan is ~100x).
  • Result assigned to a package-level sink so the call is not optimised away.

A counter-based deterministic check would need production instrumentation, so I kept it timing-based.

Verified (darwin host)

  • go test -count=20 -run TestSchemelessLinear ./internal/credmask: ok (25.6 s)
  • Same, under CPU load (2x ncpu busy loops): ok (26.5 s)
  • GOOS=windows go vet ./internal/credmask ./internal/config: clean; GOOS=windows go test -c: compiles
  • go test -count=1 ./internal/config ./internal/credmask: ok
  • Temporarily added an O(n) rescan per @proto( match in maskDSNUserinfo: test FAILED (e.g. "@a(": 40000 B took 6.2ms/call, 400000 B took 377ms/call); reverted, not in this PR.
  • Not run: the actual windows-2022 runner; this PR's CI is the check.

The test divided work for 10x input by a 4 KB reading that is 0s on
Windows (coarse timer), so any nonzero large reading failed. Time
batches of at least 3 ms per size, take the best of five, compare
per-call cost with a 40x bound plus a 200 us floor. A 100x quadratic
regression still fails.
@acamarata
acamarata merged commit 130e5f5 into main Oct 27, 2026
34 of 35 checks passed
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