Skip to content

CBG-5596: add sync test for testing report interval#8461

Open
gregns1 wants to merge 1 commit into
mainfrom
CBG-5596
Open

CBG-5596: add sync test for testing report interval#8461
gregns1 wants to merge 1 commit into
mainfrom
CBG-5596

Conversation

@gregns1

@gregns1 gregns1 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

CBG-5596

Use new synctest for mocking time to pass intervals. Requires a bit of a refactor as you cannot yet use sync test on real network I/O. It can can only have in-bubble clocking channels (channels, mutexes or timers). The fake timer will never advance on goroutine using httptest.Server for example as its making calls to OS kernal which is outside the bubble.

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

Copilot AI review requested due to automatic review settings July 16, 2026 12:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Fleet Manager metrics reporting loop to be testable and adds a new sync test to validate reporting behavior across interval/enablement changes.

Changes:

  • Extracted the Fleet Manager reporting goroutine body into runFleetManagerReportLoop for direct invocation in tests.
  • Added a testing/synctest-based unit test to simulate time passing and verify enable/disable and interval changes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
rest/fleet_manager_reporter.go Extracts the ticker-based reporting loop into a helper function and launches it as a goroutine.
rest/fleet_manager_reporter_test.go Adds a sync test that simulates ticker intervals and verifies reporting behavior and interval reset handling.

Comment on lines +261 to +263
time.Sleep(2 * time.Hour)
synctest.Wait() // wait for report goroutine to block again after another report interval
require.Equal(t, 3, reportCount()) // should only report once (on the next 1 hour tick, then tick resets to 2 hours so no 4th report on second hour)
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.

2 participants