From 61d793cb1f1569d954d52b593561a871c6ec040d Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Thu, 14 Dec 2017 13:45:36 +0000 Subject: [PATCH 1/4] handle web_test webhandler errors. --- web/web_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/web/web_test.go b/web/web_test.go index 7b0293543..656814c37 100644 --- a/web/web_test.go +++ b/web/web_test.go @@ -108,7 +108,12 @@ func TestReadyAndHealthy(t *testing.T) { opts.Flags = map[string]string{} webHandler := New(nil, opts) - go webHandler.Run(context.Background()) + go func() { + err := webHandler.Run(context.Background()) + if err != nil { + panic(fmt.Sprintf("Can't start web handler:%s", err)) + } + }() // Give some time for the web goroutine to run since we need the server // to be up before starting tests. @@ -202,7 +207,7 @@ func TestRoutePrefix(t *testing.T) { go func() { err := webHandler.Run(context.Background()) if err != nil { - panic(fmt.Sprintf("Can't start webhandler error %s", err)) + panic(fmt.Sprintf("Can't start web handler:%s", err)) } }() From 0e58cda1fe5b5a4b8501f239faff2eaff53a999f Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Tue, 19 Dec 2017 12:02:34 +0000 Subject: [PATCH 2/4] use Fatalf instead of panic --- web/web_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/web/web_test.go b/web/web_test.go index 656814c37..10f3d83f9 100644 --- a/web/web_test.go +++ b/web/web_test.go @@ -15,7 +15,6 @@ package web import ( "context" - "fmt" "io/ioutil" "net/http" "net/http/httptest" @@ -111,7 +110,7 @@ func TestReadyAndHealthy(t *testing.T) { go func() { err := webHandler.Run(context.Background()) if err != nil { - panic(fmt.Sprintf("Can't start web handler:%s", err)) + t.Fatalf("Can't start web handler:%s", err) } }() @@ -207,7 +206,7 @@ func TestRoutePrefix(t *testing.T) { go func() { err := webHandler.Run(context.Background()) if err != nil { - panic(fmt.Sprintf("Can't start web handler:%s", err)) + t.Fatalf("Can't start web handler:%s", err) } }() From ad66476c4f73087e61b9837eb70372b4a713d50d Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Tue, 19 Dec 2017 15:06:51 +0000 Subject: [PATCH 3/4] fix flaky main.go test and simplify a bit --- cmd/prometheus/main_test.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/cmd/prometheus/main_test.go b/cmd/prometheus/main_test.go index 71d638bf0..184f47dfd 100644 --- a/cmd/prometheus/main_test.go +++ b/cmd/prometheus/main_test.go @@ -75,25 +75,20 @@ func TestStartupInterrupt(t *testing.T) { }() var startedOk bool - var stoppedOk bool var stoppedErr error Loop: for x := 0; x < 10; x++ { - // 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 { startedOk = true prom.Process.Signal(os.Interrupt) select { case stoppedErr = <-done: - stoppedOk = true break Loop case <-time.After(10 * time.Second): - } break Loop - } time.Sleep(500 * time.Millisecond) } @@ -102,10 +97,10 @@ Loop: t.Errorf("prometheus didn't start in the specified timeout") 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") - } else if stoppedErr != nil { - t.Errorf("prometheus exited with an error:%v", stoppedErr) + } 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 unexpected error:%v", stoppedErr) } } From c94fa731aae210b8ee5517b2f7e4d982bb3575cc Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Wed, 20 Dec 2017 18:21:10 +0000 Subject: [PATCH 4/4] bypass the proxy for the tests --- cmd/prometheus/main_test.go | 3 +++ web/web_test.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/cmd/prometheus/main_test.go b/cmd/prometheus/main_test.go index 184f47dfd..5c6eab97e 100644 --- a/cmd/prometheus/main_test.go +++ b/cmd/prometheus/main_test.go @@ -35,6 +35,9 @@ func TestMain(m *testing.M) { if testing.Short() { 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 promPath, err = os.Getwd() if err != nil { diff --git a/web/web_test.go b/web/web_test.go index 10f3d83f9..e761d7c27 100644 --- a/web/web_test.go +++ b/web/web_test.go @@ -29,6 +29,11 @@ import ( 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) { opts := &Options{ ListenAddress: ":9090",