Skip to content

Commit

Permalink
Merge pull request #3688 from weaveworks/fix-testregdelete-flake
Browse files Browse the repository at this point in the history
fix(test-flake): poll for result in TestRegistryDelete() to avoid race
  • Loading branch information
qiell authored Sep 19, 2019
2 parents f675c87 + 49dfd98 commit 4b6b12d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions probe/docker/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import (
client "github.com/fsouza/go-dockerclient"

"github.com/weaveworks/common/mtime"
commonTest "github.com/weaveworks/common/test"
"github.com/weaveworks/scope/probe/controls"
"github.com/weaveworks/scope/probe/docker"
"github.com/weaveworks/scope/report"
"github.com/weaveworks/scope/test"
"github.com/weaveworks/scope/test/reflect"
)

func testRegistry() docker.Registry {
Expand Down Expand Up @@ -496,20 +494,23 @@ func TestRegistryDelete(t *testing.T) {
delete(mdc.containers, "ping")
mdc.Unlock()
mdc.send(&client.APIEvents{Status: docker.DestroyEvent, ID: "ping"})
runtime.Gosched()

check([]docker.Container{})

mtx.Lock()
want := []report.Node{
report.MakeNodeWith(report.MakeContainerNodeID("ping"), map[string]string{
docker.ContainerID: "ping",
docker.ContainerState: "deleted",
}),
}
if !reflect.DeepEqual(want, nodes) {
t.Errorf("Didn't get right container updates: %v", commonTest.Diff(want, nodes))
}
test.Poll(t, 100*time.Millisecond, want, func() interface{} {
mtx.Lock()
nodesCopy := make([]report.Node, len(nodes))
copy(nodesCopy, nodes)
mtx.Unlock()
return nodesCopy
})
mtx.Lock()
nodes = []report.Node{}
mtx.Unlock()
}
Expand Down

0 comments on commit 4b6b12d

Please sign in to comment.