Skip to content

Commit 07525f4

Browse files
fix: wait for goroutine before TempDir cleanup in process test (#17)
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: dmitriimaksimovdevelop <227611064+dmitriimaksimovdevelop@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9800173 commit 07525f4

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

internal/collector/process_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,13 @@ func TestProcessTopByCPU_SortRegression(t *testing.T) {
133133
// The collector sleeps for SampleInterval between the two reads. We set the
134134
// interval to 5ms and rewrite after 1ms to be sure the overwrite lands
135135
// between the two reads.
136+
done := make(chan struct{})
136137
go func() {
138+
defer close(done)
137139
time.Sleep(1 * time.Millisecond)
138140
buildFakeProcfsPass(t, root, 2)
139141
}()
142+
t.Cleanup(func() { <-done }) // wait for goroutine before TempDir cleanup
140143

141144
c := NewProcessCollector(root)
142145
cfg := CollectConfig{

0 commit comments

Comments
 (0)