From 57fbd81772d33ea5adebe615ddf4f6036f042af5 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Thu, 17 Dec 2020 17:15:48 +0100 Subject: [PATCH] Make sure mock metrics server is started before testing metrics Signed-off-by: Guillaume Tardif --- tests/e2e/e2e_test.go | 12 ++++++++++++ tests/framework/mockmetrics.go | 4 ---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index eb49bc693..9e61638a2 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -144,6 +144,18 @@ func TestContextMetrics(t *testing.T) { s.Start() defer s.Stop() + started := false + for i := 0; i < 30; i++ { + c.RunDockerCmd("help", "ps") + if len(s.GetUsage()) > 0 { + started = true + fmt.Printf(" [%s] Server up in %d ms\n", t.Name(), i*100) + break + } + time.Sleep(100 * time.Millisecond) + } + assert.Assert(t, started, "Metrics mock server not available after 3 secs") + t.Run("send metrics on help commands", func(t *testing.T) { s.ResetUsage() diff --git a/tests/framework/mockmetrics.go b/tests/framework/mockmetrics.go index 90ee9799b..541868e9d 100644 --- a/tests/framework/mockmetrics.go +++ b/tests/framework/mockmetrics.go @@ -22,7 +22,6 @@ import ( "net" "net/http" "strings" - "time" "github.com/labstack/echo" ) @@ -78,7 +77,4 @@ func (s *MockMetricsServer) Start() { s.e.POST("/usage", s.handlePostUsage) _ = s.e.Start(":1323") }() - - // wait a bit for the mock metrics server to actually listen - time.Sleep(500 * time.Millisecond) }