From 306fa4ea6f6d9b24513e34fca15553fdeb303052 Mon Sep 17 00:00:00 2001 From: dmitriimaksimovdevelop <227611064+dmitriimaksimovdevelop@users.noreply.github.com> Date: Thu, 2 Apr 2026 17:19:38 +0300 Subject: [PATCH] fix: wait for goroutine before TempDir cleanup in process test TestProcessTopByCPU_SortRegression spawns a goroutine that writes to TempDir after 1ms. On Go 1.25+ t.TempDir() cleanup is strict and fails if the directory is not empty. The goroutine could still be writing when cleanup starts. Fix: t.Cleanup(func() { <-done }) ensures goroutine finishes before TempDir removal. Co-Authored-By: Claude Opus 4.6 (1M context) --- internal/collector/process_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/collector/process_test.go b/internal/collector/process_test.go index 3ce13c5..6adef5c 100644 --- a/internal/collector/process_test.go +++ b/internal/collector/process_test.go @@ -133,10 +133,13 @@ func TestProcessTopByCPU_SortRegression(t *testing.T) { // The collector sleeps for SampleInterval between the two reads. We set the // interval to 5ms and rewrite after 1ms to be sure the overwrite lands // between the two reads. + done := make(chan struct{}) go func() { + defer close(done) time.Sleep(1 * time.Millisecond) buildFakeProcfsPass(t, root, 2) }() + t.Cleanup(func() { <-done }) // wait for goroutine before TempDir cleanup c := NewProcessCollector(root) cfg := CollectConfig{