mirror of
https://github.com/prometheus/prometheus
synced 2025-01-12 18:01:36 +00:00
Fix race in Query Log Test (#6727)
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 <roidelapluie@inuits.eu>
This commit is contained in:
parent
83601202d9
commit
3c4c01eae2
@ -26,6 +26,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -244,9 +245,15 @@ func (p *queryLogTest) run(t *testing.T) {
|
|||||||
// Log stderr in case of failure.
|
// Log stderr in case of failure.
|
||||||
stderr, err := prom.StderrPipe()
|
stderr, err := prom.StderrPipe()
|
||||||
testutil.Ok(t, err)
|
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() {
|
go func() {
|
||||||
slurp, _ := ioutil.ReadAll(stderr)
|
slurp, _ := ioutil.ReadAll(stderr)
|
||||||
t.Log(string(slurp))
|
t.Log(string(slurp))
|
||||||
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
testutil.Ok(t, prom.Start())
|
testutil.Ok(t, prom.Start())
|
||||||
|
Loading…
Reference in New Issue
Block a user