mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-19 04:16:21 +00:00
Merge pull request #482 from weaveworks/443-flaky
Address intermittent failure in registry_test.go
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package docker_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"sync"
|
||||
@@ -126,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
|
||||
@@ -173,32 +176,31 @@ 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()
|
||||
|
||||
{
|
||||
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)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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()
|
||||
@@ -211,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"})
|
||||
@@ -222,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"})
|
||||
@@ -233,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"})
|
||||
|
||||
Reference in New Issue
Block a user