From 177b91adc80f93e26dc7c249b41cf9fd054ea325 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Wed, 9 Dec 2020 16:25:32 +0100 Subject: [PATCH] Trying to fix flakyness on metrics e2e tests Signed-off-by: Guillaume Tardif --- tests/e2e/e2e_test.go | 6 +++--- tests/framework/mockmetrics.go | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index eb49bc693..c9e1101e4 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -151,7 +151,7 @@ func TestContextMetrics(t *testing.T) { c.RunDockerCmd("--help") c.RunDockerCmd("run", "--help") - usage := s.GetUsage() + usage := s.GetUsage(3) assert.DeepEqual(t, []string{ `{"command":"help run","context":"moby","source":"cli","status":"success"}`, `{"command":"--help","context":"moby","source":"cli","status":"success"}`, @@ -166,7 +166,7 @@ func TestContextMetrics(t *testing.T) { c.RunDockerCmd("version") c.RunDockerOrExitError("version", "--xxx") - usage := s.GetUsage() + usage := s.GetUsage(3) assert.DeepEqual(t, []string{ `{"command":"ps","context":"moby","source":"cli","status":"success"}`, `{"command":"version","context":"moby","source":"cli","status":"success"}`, @@ -185,7 +185,7 @@ func TestContextMetrics(t *testing.T) { c.RunDockerCmd("context", "use", "default") c.RunDockerCmd("--context", "test-example", "ps") - usage := s.GetUsage() + usage := s.GetUsage(7) assert.DeepEqual(t, []string{ `{"command":"context create","context":"moby","source":"cli","status":"success"}`, `{"command":"ps","context":"moby","source":"cli","status":"success"}`, diff --git a/tests/framework/mockmetrics.go b/tests/framework/mockmetrics.go index 71ed01925..265518036 100644 --- a/tests/framework/mockmetrics.go +++ b/tests/framework/mockmetrics.go @@ -22,6 +22,7 @@ import ( "net" "net/http" "strings" + "time" "github.com/labstack/echo" ) @@ -53,7 +54,10 @@ func (s *MockMetricsServer) hello(c echo.Context) error { } // GetUsage get usage -func (s *MockMetricsServer) GetUsage() []string { +func (s *MockMetricsServer) GetUsage(expectedCommands int) []string { + if len(s.usage) < expectedCommands { + time.Sleep(1 * time.Second) // a simple sleep 1s here should be enough, if not there are real issues + } return s.usage }