From c9f39d41294c54968e8f3e2e04fd7297501474f5 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Mon, 14 Sep 2015 04:57:56 +0000 Subject: [PATCH 1/2] Address one intermittent failure in registry_test.go --- probe/docker/registry_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/probe/docker/registry_test.go b/probe/docker/registry_test.go index 79ecbe50e..6a0ae651e 100644 --- a/probe/docker/registry_test.go +++ b/probe/docker/registry_test.go @@ -1,7 +1,6 @@ package docker_test import ( - "reflect" "runtime" "sort" "sync" @@ -181,17 +180,16 @@ func TestRegistry(t *testing.T) { { want := []docker.Container{&mockContainer{container1}} - test.Poll(t, 10*time.Millisecond, want, func() interface{} { + test.Poll(t, 100*time.Millisecond, want, func() interface{} { return allContainers(registry) }) } { - have := allImages(registry) want := []*client.APIImages{&apiImage1} - if !reflect.DeepEqual(want, have) { - t.Errorf("%s", test.Diff(want, have)) - } + test.Poll(t, 100*time.Millisecond, want, func() interface{} { + return allImages(registry) + }) } }) } From 2fdfa1cbf5baac09630622c91f3f5ff77914dd34 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Mon, 14 Sep 2015 05:09:33 +0000 Subject: [PATCH 2/2] Fix flaky docker tests. --- probe/docker/registry_test.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/probe/docker/registry_test.go b/probe/docker/registry_test.go index 6a0ae651e..f603f0420 100644 --- a/probe/docker/registry_test.go +++ b/probe/docker/registry_test.go @@ -125,13 +125,17 @@ var ( }, } apiContainer1 = client.APIContainers{ID: "ping"} + apiContainer2 = client.APIContainers{ID: "wiff"} apiImage1 = client.APIImages{ID: "baz", RepoTags: []string{"bang", "not-chosen"}} - mockClient = mockDockerClient{ +) + +func newMockClient() *mockDockerClient { + return &mockDockerClient{ apiContainers: []client.APIContainers{apiContainer1}, containers: map[string]*client.Container{"ping": container1}, apiImages: []client.APIImages{apiImage1}, } -) +} func setupStubs(mdc *mockDockerClient, f func()) { oldDockerClient, oldNewContainer := docker.NewDockerClientStub, docker.NewContainerStub @@ -172,8 +176,8 @@ func allImages(r docker.Registry) []*client.APIImages { } func TestRegistry(t *testing.T) { - mdc := mockClient // take a copy - setupStubs(&mdc, func() { + mdc := newMockClient() + setupStubs(mdc, func() { registry, _ := docker.NewRegistry(10 * time.Second) defer registry.Stop() runtime.Gosched() @@ -195,8 +199,8 @@ func TestRegistry(t *testing.T) { } func TestRegistryEvents(t *testing.T) { - mdc := mockClient // take a copy - setupStubs(&mdc, func() { + mdc := newMockClient() + setupStubs(mdc, func() { registry, _ := docker.NewRegistry(10 * time.Second) defer registry.Stop() runtime.Gosched() @@ -209,6 +213,7 @@ func TestRegistryEvents(t *testing.T) { { mdc.Lock() + mdc.apiContainers = []client.APIContainers{apiContainer1, apiContainer2} mdc.containers["wiff"] = container2 mdc.Unlock() mdc.send(&client.APIEvents{Status: docker.StartEvent, ID: "wiff"}) @@ -220,6 +225,7 @@ func TestRegistryEvents(t *testing.T) { { mdc.Lock() + mdc.apiContainers = []client.APIContainers{apiContainer1} delete(mdc.containers, "wiff") mdc.Unlock() mdc.send(&client.APIEvents{Status: docker.DieEvent, ID: "wiff"}) @@ -231,6 +237,7 @@ func TestRegistryEvents(t *testing.T) { { mdc.Lock() + mdc.apiContainers = []client.APIContainers{} delete(mdc.containers, "ping") mdc.Unlock() mdc.send(&client.APIEvents{Status: docker.DieEvent, ID: "ping"})