Skip to content

test(agent): the certificate budget test no longer depends on the clock's nanoseconds - #520

Merged
samuelmbabhazi merged 1 commit into
mainfrom
test/certwatch-fixed-subsecond
Nov 26, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
test/certwatch-fixed-subsecond

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

TestWithinKeepsTheInventoryAndTheSoonestExpiries takes its base time with a fixed sub-second part (.600), instead of whatever time.Now() returns.

Why

The test failed twice in a row on #513 with kept 64 certificates: the budget was not applied. #513 does not touch certwatch, and the test passed 100 times locally.

Cause

  • The report leaves the certificates a budget of 19,136 bytes. All 64 certificates take 19,264 bytes, so the margin is 128 bytes, or 2 bytes per certificate.
  • Each NotAfter timestamp carries the base time's nanoseconds, a varint of 3 to 5 bytes.
  • When time.Now() falls in the first 2.1 ms of a second, every certificate is 2 bytes shorter, all 64 fit, and the assertion fails. That is about one run in 500.

Reproduced by pinning the nanoseconds in a local copy:

Nanoseconds Result
1,000 fails, kept 64
1,500,000 fails, kept 64
150,000,000 passes
600,000,000 passes

How it was tested

go test -race -count=20 ./agent/internal/certwatch/ passes.

Security considerations

Test only.

@samuelmbabhazi samuelmbabhazi added bug Something isn't working track:agent labels Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 53eb186 and 92061ff.

Files selected for processing: 1

  • agent/internal/certwatch/certwatch_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@samuelmbabhazi
samuelmbabhazi merged commit 7a4d85e into main Nov 26, 2026
27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the test/certwatch-fixed-subsecond branch November 26, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working track:agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant