Skip to content

Commit

Permalink
Fix race in Query Log Test (prometheus#6727)
Browse files Browse the repository at this point in the history
A data race can happen if we run t.Log after the test t is done -- which
in this case is highly possible because of the use of subtests and the
fact that we call t.Log in a goroutine.

Signed-off-by: Julien Pivotto <[email protected]>
  • Loading branch information
roidelapluie authored Jan 30, 2020
1 parent 8360120 commit 3c4c01e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/prometheus/query_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -244,9 +245,15 @@ func (p *queryLogTest) run(t *testing.T) {
// Log stderr in case of failure.
stderr, err := prom.StderrPipe()
testutil.Ok(t, err)

// We use a WaitGroup to avoid calling t.Log after the test is done.
var wg sync.WaitGroup
wg.Add(1)
defer wg.Wait()
go func() {
slurp, _ := ioutil.ReadAll(stderr)
t.Log(string(slurp))
wg.Done()
}()

testutil.Ok(t, prom.Start())
Expand Down

0 comments on commit 3c4c01e

Please sign in to comment.