Skip to content

Commit

Permalink
profiler: handle low Windows timer resolution for metrics profile tests
Browse files Browse the repository at this point in the history
The Windows system timer resolution is about 15 milliseconds (see
https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/high-resolution-timers#controlling-timer-accuracy)
This caused the metrics profile tests from #2865 to fail because the
metrics profiler will likely be stopped in less than 15 milliseconds,
meaning we'll see 0 duration between profile collection and log an
error. Drop TestMetricsProfileStopEarlyNoLog because it's not going to
be useful if the timer resolution is that low. Bump the period in
TestShortMetricsProfile from 10ms to 20ms so that the Windows timer will
(hopefully) be able to actually measure the duration.
  • Loading branch information
nsrip-dd committed Sep 24, 2024
1 parent 101d4da commit 8772c17
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions profiler/profiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,24 +782,18 @@ func TestOrchestrionProfileInfo(t *testing.T) {
}

func TestShortMetricsProfile(t *testing.T) {
profiles := startTestProfiler(t, 1, WithPeriod(10*time.Millisecond), WithProfileTypes(MetricsProfile))
rl := new(log.RecordLogger)
defer log.UseLogger(rl)()
profiles := startTestProfiler(t, 1, WithPeriod(20*time.Millisecond), WithProfileTypes(MetricsProfile))
for range 3 {
p := <-profiles
if _, ok := p.attachments["metrics.json"]; !ok {
t.Errorf("didn't get metrics profile, got %v", p.event.Attachments)
}
}
}

func TestMetricsProfileStopEarlyNoLog(t *testing.T) {
rl := new(log.RecordLogger)
defer log.UseLogger(rl)()
startTestProfiler(t, 1, WithPeriod(2*time.Second), WithProfileTypes(MetricsProfile))
// Stop the profiler immediately
Stop()
log.Flush()
for _, msg := range rl.Logs() {
// We should not see any error about stopping the metrics profile short
// We should not see any errors from the metrics profiler
if strings.Contains(msg, "ERROR:") {
t.Errorf("unexpected error log: %s", msg)
}
Expand Down

0 comments on commit 8772c17

Please sign in to comment.