From 4fe8ac65f6026e55fbd8b1dcdf4c1f60fbf3e69d Mon Sep 17 00:00:00 2001 From: gbudjeakp Date: Sat, 11 Jul 2026 14:39:36 -0600 Subject: [PATCH] fix: relax TestCollector_HeartbeatFile timing for -race on CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each collect() tick calls cpu.Percent + disk/net IOCounters via psutil, which can take 50-100 ms on a loaded runner. The race detector adds further overhead, making the original 400 ms / 100 ms heartbeat budget too tight — the heartbeat ticker never fired before context cancel. New intervals: collect=200 ms, heartbeat=400 ms, context=3 s. This gives ~7 heartbeat opportunities even on a heavily loaded machine. --- internal/agent/collector_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/agent/collector_test.go b/internal/agent/collector_test.go index 32df8ca..600f873 100644 --- a/internal/agent/collector_test.go +++ b/internal/agent/collector_test.go @@ -85,15 +85,18 @@ func TestCollector_HeartbeatFile(t *testing.T) { dir := t.TempDir() hbPath := filepath.Join(dir, "metrics-heartbeat.json") + // Use generous intervals so the test is stable under -race on loaded CI + // runners. Each collect() invokes psutil (cpu.Percent, disk/net counters) + // which can take 50-100 ms; the race detector adds further overhead. c := NewCollector(Config{ - Interval: 50 * time.Millisecond, - HeartbeatInterval: 100 * time.Millisecond, + Interval: 200 * time.Millisecond, + HeartbeatInterval: 400 * time.Millisecond, OutputDir: dir, JobID: "test-heartbeat", HeartbeatFilePath: hbPath, }) - ctx, cancel := context.WithTimeout(context.Background(), 400*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() _ = c.Run(ctx)