mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
fix flaky main.go test and simplify a bit
This commit is contained in:
parent
0e58cda1fe
commit
ad66476c4f
|
@ -75,25 +75,20 @@ func TestStartupInterrupt(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var startedOk bool
|
var startedOk bool
|
||||||
var stoppedOk bool
|
|
||||||
var stoppedErr error
|
var stoppedErr error
|
||||||
|
|
||||||
Loop:
|
Loop:
|
||||||
for x := 0; x < 10; x++ {
|
for x := 0; x < 10; x++ {
|
||||||
|
|
||||||
// error=nil means prometheus has started so can send the interrupt signal and wait for the grace shutdown.
|
// error=nil means prometheus has started so can send the interrupt signal and wait for the grace shutdown.
|
||||||
if _, err := http.Get("http://localhost:9090/graph"); err == nil {
|
if _, err := http.Get("http://localhost:9090/graph"); err == nil {
|
||||||
startedOk = true
|
startedOk = true
|
||||||
prom.Process.Signal(os.Interrupt)
|
prom.Process.Signal(os.Interrupt)
|
||||||
select {
|
select {
|
||||||
case stoppedErr = <-done:
|
case stoppedErr = <-done:
|
||||||
stoppedOk = true
|
|
||||||
break Loop
|
break Loop
|
||||||
case <-time.After(10 * time.Second):
|
case <-time.After(10 * time.Second):
|
||||||
|
|
||||||
}
|
}
|
||||||
break Loop
|
break Loop
|
||||||
|
|
||||||
}
|
}
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
@ -102,10 +97,10 @@ Loop:
|
||||||
t.Errorf("prometheus didn't start in the specified timeout")
|
t.Errorf("prometheus didn't start in the specified timeout")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := prom.Process.Kill(); err == nil && !stoppedOk {
|
if err := prom.Process.Kill(); err == nil {
|
||||||
t.Errorf("prometheus didn't shutdown gracefully after sending the Interrupt signal")
|
t.Errorf("prometheus didn't shutdown gracefully after sending the Interrupt signal")
|
||||||
} else if stoppedErr != nil {
|
} else if stoppedErr != nil && stoppedErr.Error() != "signal: interrupt" { // TODO - find a better way to detect when the process didn't exit as expected!
|
||||||
t.Errorf("prometheus exited with an error:%v", stoppedErr)
|
t.Errorf("prometheus exited with an unexpected error:%v", stoppedErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue