cockroachdb / cockroachdb/cockroach
kv: plumb a mock clock to deflake TestPaceUpdateSignalling
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Describe the problem**
`TestPaceUpdateSignalling` validates that the task pacer properly spaces out `sync.Cond` signals when waking goroutines waiting on the `updatesBuf`. The test is inherently flaky because it relies on real wall-clock timing: it spawns 1000 goroutines, triggers a paced broadcast, and then asserts that the min-max spread of receive times falls within expected bounds (e.g. >= 125ms for a 250ms pacing interval, or <= 40ms when pacing is disabled).
Proposed fix
- Thread a clock source into the pacer / `updatesBuf` so that tests can use a fully controlled mock clock. Concretely:
- Introduce a Clock interface (or use an existing one like `timeutil.TimeSource`) with `Now() crtime.Mono` and `Sleep(d time.Duration)` methods. This could live in `taskpacer` or in `updatesBuf` directly.
- Inject the clock into `updatesBuf` and `PaceBroadcastUpdate`. Replace the three call sites above with calls through the interface. Production code uses a real clock; tests inject a mock.
Jira issue: CRDB-60851
Contributor guide
Assessment
This issue has not been assessed yet.