From c08bb86be0617558f92f3d98b0014af9ebfea08c Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Wed, 10 Nov 2021 11:33:46 +0100 Subject: [PATCH] cmd/prometheus: use random listen port in TestStartupInterrupt test So it can be run in parallel safely. Signed-off-by: Mateusz Gozdek --- cmd/prometheus/main_unix_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/prometheus/main_unix_test.go b/cmd/prometheus/main_unix_test.go index 0e21a5d0a..d7eed636d 100644 --- a/cmd/prometheus/main_unix_test.go +++ b/cmd/prometheus/main_unix_test.go @@ -17,11 +17,14 @@ package main import ( + "fmt" "net/http" "os" "os/exec" "testing" "time" + + "github.com/prometheus/prometheus/util/testutil" ) // As soon as prometheus starts responding to http request it should be able to @@ -31,7 +34,9 @@ func TestStartupInterrupt(t *testing.T) { t.Skip("skipping test in short mode.") } - prom := exec.Command(promPath, "-test.main", "--config.file="+promConfig, "--storage.tsdb.path="+t.TempDir()) + port := fmt.Sprintf(":%d", testutil.RandomUnprivilegedPort(t)) + + prom := exec.Command(promPath, "-test.main", "--config.file="+promConfig, "--storage.tsdb.path="+t.TempDir(), "--web.listen-address=0.0.0.0"+port) err := prom.Start() if err != nil { t.Fatalf("execution error: %v", err) @@ -45,11 +50,13 @@ func TestStartupInterrupt(t *testing.T) { var startedOk bool var stoppedErr error + url := "http://localhost" + port + "/graph" + Loop: for x := 0; x < 10; x++ { // error=nil means prometheus has started so we can send the interrupt // signal and wait for the graceful shutdown. - if _, err := http.Get("http://localhost:9090/graph"); err == nil { + if _, err := http.Get(url); err == nil { startedOk = true prom.Process.Signal(os.Interrupt) select {