mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 22:19:40 -08:00
Merge pull request #3587 from krasi-georgiev/web-test-error-check
handle web_test webhandler errors.
This commit is contained in:
commit
35a6ffbaf3
|
@ -35,6 +35,9 @@ func TestMain(m *testing.M) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
// On linux with a global proxy the tests will fail as the go client(http,grpc) tries to connect through the proxy.
|
||||||
|
os.Setenv("no_proxy", "localhost,127.0.0.1,0.0.0.0,:")
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
promPath, err = os.Getwd()
|
promPath, err = os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -75,25 +78,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 +100,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -30,6 +29,11 @@ import (
|
||||||
libtsdb "github.com/prometheus/tsdb"
|
libtsdb "github.com/prometheus/tsdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
// On linux with a global proxy the tests will fail as the go client(http,grpc) tries to connect through the proxy.
|
||||||
|
os.Setenv("no_proxy", "localhost,127.0.0.1,0.0.0.0,:")
|
||||||
|
os.Exit(m.Run())
|
||||||
|
}
|
||||||
func TestGlobalURL(t *testing.T) {
|
func TestGlobalURL(t *testing.T) {
|
||||||
opts := &Options{
|
opts := &Options{
|
||||||
ListenAddress: ":9090",
|
ListenAddress: ":9090",
|
||||||
|
@ -108,7 +112,12 @@ func TestReadyAndHealthy(t *testing.T) {
|
||||||
opts.Flags = map[string]string{}
|
opts.Flags = map[string]string{}
|
||||||
|
|
||||||
webHandler := New(nil, opts)
|
webHandler := New(nil, opts)
|
||||||
go webHandler.Run(context.Background())
|
go func() {
|
||||||
|
err := webHandler.Run(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Can't start web handler:%s", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Give some time for the web goroutine to run since we need the server
|
// Give some time for the web goroutine to run since we need the server
|
||||||
// to be up before starting tests.
|
// to be up before starting tests.
|
||||||
|
@ -202,7 +211,7 @@ func TestRoutePrefix(t *testing.T) {
|
||||||
go func() {
|
go func() {
|
||||||
err := webHandler.Run(context.Background())
|
err := webHandler.Run(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Can't start webhandler error %s", err))
|
t.Fatalf("Can't start web handler:%s", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue