Merge pull request #16224 from pr00se/main-test-data-race

Address data race in main_test.go
This commit is contained in:
Ganesh Vernekar 2025-03-18 13:49:26 -04:00 committed by GitHub
commit 62bf7dbed7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 6 deletions

View File

@ -252,6 +252,8 @@ func TestWALSegmentSizeBounds(t *testing.T) {
// WaitGroup is used to ensure that we don't call t.Log() after the test has finished. // WaitGroup is used to ensure that we don't call t.Log() after the test has finished.
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)
defer wg.Wait()
go func() { go func() {
defer wg.Done() defer wg.Done()
slurp, _ := io.ReadAll(stderr) slurp, _ := io.ReadAll(stderr)
@ -271,7 +273,6 @@ func TestWALSegmentSizeBounds(t *testing.T) {
prom.Process.Kill() prom.Process.Kill()
<-done <-done
} }
wg.Wait()
return return
} }
@ -281,8 +282,6 @@ func TestWALSegmentSizeBounds(t *testing.T) {
require.ErrorAs(t, err, &exitError) require.ErrorAs(t, err, &exitError)
status := exitError.Sys().(syscall.WaitStatus) status := exitError.Sys().(syscall.WaitStatus)
require.Equal(t, tc.exitCode, status.ExitStatus()) require.Equal(t, tc.exitCode, status.ExitStatus())
wg.Wait()
}) })
} }
} }
@ -313,7 +312,14 @@ func TestMaxBlockChunkSegmentSizeBounds(t *testing.T) {
// Log stderr in case of failure. // Log stderr in case of failure.
stderr, err := prom.StderrPipe() stderr, err := prom.StderrPipe()
require.NoError(t, err) require.NoError(t, err)
// WaitGroup is used to ensure that we don't call t.Log() after the test has finished.
var wg sync.WaitGroup
wg.Add(1)
defer wg.Wait()
go func() { go func() {
defer wg.Done()
slurp, _ := io.ReadAll(stderr) slurp, _ := io.ReadAll(stderr)
t.Log(string(slurp)) t.Log(string(slurp))
}() }()
@ -511,6 +517,8 @@ func TestModeSpecificFlags(t *testing.T) {
// WaitGroup is used to ensure that we don't call t.Log() after the test has finished. // WaitGroup is used to ensure that we don't call t.Log() after the test has finished.
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)
defer wg.Wait()
go func() { go func() {
defer wg.Done() defer wg.Done()
slurp, _ := io.ReadAll(stderr) slurp, _ := io.ReadAll(stderr)
@ -530,7 +538,6 @@ func TestModeSpecificFlags(t *testing.T) {
prom.Process.Kill() prom.Process.Kill()
<-done <-done
} }
wg.Wait()
return return
} }
@ -543,8 +550,6 @@ func TestModeSpecificFlags(t *testing.T) {
} else { } else {
t.Errorf("unable to retrieve the exit status for prometheus: %v", err) t.Errorf("unable to retrieve the exit status for prometheus: %v", err)
} }
wg.Wait()
}) })
} }
} }