mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Merge pull request #1076 from gtardif/fix_metrics_flakyness
Fix metrics flakyness
This commit is contained in:
commit
f6f9241d12
@ -144,6 +144,18 @@ func TestContextMetrics(t *testing.T) {
|
|||||||
s.Start()
|
s.Start()
|
||||||
defer s.Stop()
|
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) {
|
t.Run("send metrics on help commands", func(t *testing.T) {
|
||||||
s.ResetUsage()
|
s.ResetUsage()
|
||||||
|
|
||||||
@ -151,7 +163,7 @@ func TestContextMetrics(t *testing.T) {
|
|||||||
c.RunDockerCmd("--help")
|
c.RunDockerCmd("--help")
|
||||||
c.RunDockerCmd("run", "--help")
|
c.RunDockerCmd("run", "--help")
|
||||||
|
|
||||||
usage := s.GetUsage(3)
|
usage := s.GetUsage()
|
||||||
assert.DeepEqual(t, []string{
|
assert.DeepEqual(t, []string{
|
||||||
`{"command":"help run","context":"moby","source":"cli","status":"success"}`,
|
`{"command":"help run","context":"moby","source":"cli","status":"success"}`,
|
||||||
`{"command":"--help","context":"moby","source":"cli","status":"success"}`,
|
`{"command":"--help","context":"moby","source":"cli","status":"success"}`,
|
||||||
@ -166,7 +178,7 @@ func TestContextMetrics(t *testing.T) {
|
|||||||
c.RunDockerCmd("version")
|
c.RunDockerCmd("version")
|
||||||
c.RunDockerOrExitError("version", "--xxx")
|
c.RunDockerOrExitError("version", "--xxx")
|
||||||
|
|
||||||
usage := s.GetUsage(3)
|
usage := s.GetUsage()
|
||||||
assert.DeepEqual(t, []string{
|
assert.DeepEqual(t, []string{
|
||||||
`{"command":"ps","context":"moby","source":"cli","status":"success"}`,
|
`{"command":"ps","context":"moby","source":"cli","status":"success"}`,
|
||||||
`{"command":"version","context":"moby","source":"cli","status":"success"}`,
|
`{"command":"version","context":"moby","source":"cli","status":"success"}`,
|
||||||
@ -185,7 +197,7 @@ func TestContextMetrics(t *testing.T) {
|
|||||||
c.RunDockerCmd("context", "use", "default")
|
c.RunDockerCmd("context", "use", "default")
|
||||||
c.RunDockerCmd("--context", "test-example", "ps")
|
c.RunDockerCmd("--context", "test-example", "ps")
|
||||||
|
|
||||||
usage := s.GetUsage(7)
|
usage := s.GetUsage()
|
||||||
assert.DeepEqual(t, []string{
|
assert.DeepEqual(t, []string{
|
||||||
`{"command":"context create","context":"moby","source":"cli","status":"success"}`,
|
`{"command":"context create","context":"moby","source":"cli","status":"success"}`,
|
||||||
`{"command":"ps","context":"moby","source":"cli","status":"success"}`,
|
`{"command":"ps","context":"moby","source":"cli","status":"success"}`,
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/labstack/echo"
|
"github.com/labstack/echo"
|
||||||
)
|
)
|
||||||
@ -42,8 +41,7 @@ func NewMetricsServer(socket string) *MockMetricsServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler
|
func (s *MockMetricsServer) handlePostUsage(c echo.Context) error {
|
||||||
func (s *MockMetricsServer) hello(c echo.Context) error {
|
|
||||||
body, error := ioutil.ReadAll(c.Request().Body)
|
body, error := ioutil.ReadAll(c.Request().Body)
|
||||||
if error != nil {
|
if error != nil {
|
||||||
return error
|
return error
|
||||||
@ -54,10 +52,7 @@ func (s *MockMetricsServer) hello(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUsage get usage
|
// GetUsage get usage
|
||||||
func (s *MockMetricsServer) GetUsage(expectedCommands int) []string {
|
func (s *MockMetricsServer) GetUsage() []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
|
return s.usage
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +74,7 @@ func (s *MockMetricsServer) Start() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
s.e.Listener = listener
|
s.e.Listener = listener
|
||||||
s.e.POST("/usage", s.hello)
|
s.e.POST("/usage", s.handlePostUsage)
|
||||||
_ = s.e.Start(":1323")
|
_ = s.e.Start(":1323")
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user