Skip to content

Commit

Permalink
retry untracked container check
Browse files Browse the repository at this point in the history
  • Loading branch information
gulducat committed May 12, 2023
1 parent 3a8099e commit 912cf68
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions drivers/docker/reconcile_dangling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
docker "github.com/fsouza/go-dockerclient"
"github.com/hashicorp/go-set"
"github.com/shoenig/test/must"
"github.com/shoenig/test/wait"

"github.com/hashicorp/nomad/ci"
"github.com/hashicorp/nomad/client/testutil"
Expand Down Expand Up @@ -245,18 +246,27 @@ func TestDanglingContainerRemoval_Stopped(t *testing.T) {
tracked := reconciler.trackedContainers()
must.NotContains[string](t, container.ID, tracked)

untracked, err := reconciler.untrackedContainers(set.New[string](0), time.Now())
checkUntracked := func() error {
untracked, err := reconciler.untrackedContainers(set.New[string](0), time.Now())
must.NoError(t, err)
if untracked.Contains(container.ID) {
err = fmt.Errorf("container ID %s in untracked set: %v", container.ID, untracked.Slice())
t.Logf("had a sad: %s", err)
}
return err
}

must.NoError(t, err)
must.NotContains[string](t, container.ID, untracked)
// retry because it's slower on windows :\
must.Wait(t, wait.InitialSuccess(
wait.ErrorFunc(checkUntracked),
wait.Timeout(5*time.Second),
wait.Gap(100*time.Millisecond),
))

// if we start container again, it'll be marked as untracked
must.NoError(t, dockerClient.StartContainer(container.ID, nil))

untracked, err = reconciler.untrackedContainers(set.New[string](0), time.Now())
untracked, err := reconciler.untrackedContainers(set.New[string](0), time.Now())
must.NoError(t, err)
for _, d := range untracked.Slice() {
t.Logf("danglin: %#v", d)
}
must.Contains[string](t, container.ID, untracked)
}

0 comments on commit 912cf68

Please sign in to comment.