1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

waitAndAssert -> poll.WaitOn

go get -d golang.org/x/tools/cmd/eg && \
dir=$(go env GOPATH)/src/golang.org/x/tools && \
git -C "$dir" fetch https://github.com/tiborvass/tools handle-variadic && \
git -C "$dir" checkout 61a94b82347c29b3289e83190aa3dda74d47abbb && \
go install golang.org/x/tools/cmd/eg

eg -w -t template.waitAndAssert.go ./integration-cli 2>&1 \
| awk '{print $2}' | while read file; do
	# removing vendor/ in import paths
	# not sure why eg adds them
	sed -E -i 's#^([\t]+").*/vendor/([^"]+)#\1\2#g' "$file"
	sed -E -i 's#\.\(eg_compareFunc\)##g' "$file"
	goimports -w "$file"
done

Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tibor Vass 2019-08-26 15:51:40 +00:00
parent 42599f1cad
commit ac2f24e72a
12 changed files with 223 additions and 224 deletions

View file

@ -18,6 +18,7 @@ import (
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/internal/test/request" "github.com/docker/docker/internal/test/request"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/poll"
) )
// Regression test for #9414 // Regression test for #9414
@ -229,13 +230,13 @@ func (s *DockerSuite) TestExecStateCleanup(c *testing.T) {
startExec(c, id, http.StatusOK) startExec(c, id, http.StatusOK)
waitForExec(c, id) waitForExec(c, id)
waitAndAssert(c, 5*time.Second, checkReadDir, checker.Equals, len(fi)) poll.WaitOn(c, pollCheck(c, checkReadDir, checker.Equals(len(fi))), poll.WithTimeout(5*time.Second))
id = createExecCmd(c, name, "invalid") id = createExecCmd(c, name, "invalid")
startExec(c, id, http.StatusBadRequest) startExec(c, id, http.StatusBadRequest)
waitForExec(c, id) waitForExec(c, id)
waitAndAssert(c, 5*time.Second, checkReadDir, checker.Equals, len(fi)) poll.WaitOn(c, pollCheck(c, checkReadDir, checker.Equals(len(fi))), poll.WithTimeout(5*time.Second))
dockerCmd(c, "stop", name) dockerCmd(c, "stop", name)
_, err = os.Stat(stateDir) _, err = os.Stat(stateDir)

View file

@ -11,6 +11,7 @@ import (
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration-cli/daemon"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/poll"
) )
func (s *DockerSwarmSuite) TestAPISwarmListNodes(c *testing.T) { func (s *DockerSwarmSuite) TestAPISwarmListNodes(c *testing.T) {
@ -84,16 +85,16 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *testing.T) {
instances := 2 instances := 2
id := d1.CreateService(c, simpleTestService, setInstances(instances)) id := d1.CreateService(c, simpleTestService, setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0) poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0) poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
// drain d2, all containers should move to d1 // drain d2, all containers should move to d1
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) { d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
n.Spec.Availability = swarm.NodeAvailabilityDrain n.Spec.Availability = swarm.NodeAvailabilityDrain
}) })
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances) poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 0) poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
// set d2 back to active // set d2 back to active
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) { d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
@ -102,15 +103,15 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *testing.T) {
instances = 1 instances = 1
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances)) d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout*2, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout*2))
instances = 2 instances = 2
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances)) d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
// drained node first so we don't get any old containers // drained node first so we don't get any old containers
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0) poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0) poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout*2, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout*2))
d2ContainerCount := len(d2.ActiveContainers(c)) d2ContainerCount := len(d2.ActiveContainers(c))
@ -121,7 +122,7 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *testing.T) {
instances = 4 instances = 4
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances)) d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances-d2ContainerCount) poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(instances-d2ContainerCount)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, d2ContainerCount) poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(d2ContainerCount)), poll.WithTimeout(defaultReconciliationTimeout))
} }

View file

@ -20,6 +20,7 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/icmd" "gotest.tools/icmd"
"gotest.tools/poll"
) )
func setPortConfig(portConfig []swarm.PortConfig) testdaemon.ServiceConstructor { func setPortConfig(portConfig []swarm.PortConfig) testdaemon.ServiceConstructor {
@ -37,7 +38,7 @@ func (s *DockerSwarmSuite) TestAPIServiceUpdatePort(c *testing.T) {
// Create a service with a port mapping of 8080:8081. // Create a service with a port mapping of 8080:8081.
portConfig := []swarm.PortConfig{{TargetPort: 8081, PublishedPort: 8080}} portConfig := []swarm.PortConfig{{TargetPort: 8081, PublishedPort: 8080}}
serviceID := d.CreateService(c, simpleTestService, setInstances(1), setPortConfig(portConfig)) serviceID := d.CreateService(c, simpleTestService, setInstances(1), setPortConfig(portConfig))
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// Update the service: changed the port mapping from 8080:8081 to 8082:8083. // Update the service: changed the port mapping from 8080:8081 to 8082:8083.
updatedPortConfig := []swarm.PortConfig{{TargetPort: 8083, PublishedPort: 8082}} updatedPortConfig := []swarm.PortConfig{{TargetPort: 8083, PublishedPort: 8082}}
@ -65,7 +66,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesCreate(c *testing.T) {
instances := 2 instances := 2
id := d.CreateService(c, simpleTestService, setInstances(instances)) id := d.CreateService(c, simpleTestService, setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
client := d.NewClientT(c) client := d.NewClientT(c)
defer client.Close() defer client.Close()
@ -87,10 +88,10 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesCreate(c *testing.T) {
service := d.GetService(c, id) service := d.GetService(c, id)
instances = 5 instances = 5
d.UpdateService(c, service, setInstances(instances)) d.UpdateService(c, service, setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
d.RemoveService(c, service.ID) d.RemoveService(c, service.ID)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 0) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
} }
func (s *DockerSwarmSuite) TestAPISwarmServicesMultipleAgents(c *testing.T) { func (s *DockerSwarmSuite) TestAPISwarmServicesMultipleAgents(c *testing.T) {
@ -103,21 +104,21 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesMultipleAgents(c *testing.T) {
instances := 9 instances := 9
id := d1.CreateService(c, simpleTestService, setInstances(instances)) id := d1.CreateService(c, simpleTestService, setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0) poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0) poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, d3.CheckActiveContainerCount, checker.GreaterThan, 0) poll.WaitOn(c, pollCheck(c, d3.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
// reconciliation on d2 node down // reconciliation on d2 node down
d2.Stop(c) d2.Stop(c)
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
// test downscaling // test downscaling
instances = 5 instances = 5
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances)) d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
} }
@ -128,15 +129,15 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesCreateGlobal(c *testing.T) {
d1.CreateService(c, simpleTestService, setGlobalMode) d1.CreateService(c, simpleTestService, setGlobalMode)
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, d3.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d3.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
d4 := s.AddDaemon(c, true, false) d4 := s.AddDaemon(c, true, false)
d5 := s.AddDaemon(c, true, false) d5 := s.AddDaemon(c, true, false)
waitAndAssert(c, defaultReconciliationTimeout, d4.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d4.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, d5.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d5.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
} }
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *testing.T) { func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *testing.T) {
@ -146,7 +147,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *testing.T) {
daemons[i] = s.AddDaemon(c, true, i == 0) daemons[i] = s.AddDaemon(c, true, i == 0)
} }
// wait for nodes ready // wait for nodes ready
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount) poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))
// service image at start // service image at start
image1 := "busybox:latest" image1 := "busybox:latest"
@ -166,24 +167,20 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *testing.T) {
id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances)) id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances))
// wait for tasks ready // wait for tasks ready
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances})
// issue service update // issue service update
service := daemons[0].GetService(c, id) service := daemons[0].GetService(c, id)
daemons[0].UpdateService(c, service, setImage(image2)) daemons[0].UpdateService(c, service, setImage(image2))
// first batch // first batch
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances - parallelism, image2: parallelism})
// 2nd batch // 2nd batch
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})
// 3nd batch // 3nd batch
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image2: instances})
// Roll back to the previous version. This uses the CLI because // Roll back to the previous version. This uses the CLI because
// rollback used to be a client-side operation. // rollback used to be a client-side operation.
@ -191,12 +188,11 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// first batch // first batch
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})
// 2nd batch // 2nd batch
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances})
} }
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) { func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
@ -223,7 +219,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
checkStartingTasks := func(expected int) []swarm.Task { checkStartingTasks := func(expected int) []swarm.Task {
var startingTasks []swarm.Task var startingTasks []swarm.Task
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks := d.GetServiceTasks(c, id) tasks := d.GetServiceTasks(c, id)
startingTasks = nil startingTasks = nil
for _, t := range tasks { for _, t := range tasks {
@ -232,7 +228,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
} }
} }
return startingTasks, "" return startingTasks, ""
}, checker.HasLen, expected) }, checker.HasLen(expected)), poll.WithTimeout(defaultReconciliationTimeout))
return startingTasks return startingTasks
} }
@ -245,8 +241,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
} }
// wait for tasks ready // wait for tasks ready
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances})
// issue service update // issue service update
service := d.GetService(c, id) service := d.GetService(c, id)
@ -257,42 +252,36 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
// The old tasks should be running, and the new ones should be starting. // The old tasks should be running, and the new ones should be starting.
startingTasks := checkStartingTasks(parallelism) startingTasks := checkStartingTasks(parallelism)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances})
// make it healthy // make it healthy
makeTasksHealthy(startingTasks) makeTasksHealthy(startingTasks)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances - parallelism, image2: parallelism})
// 2nd batch // 2nd batch
// The old tasks should be running, and the new ones should be starting. // The old tasks should be running, and the new ones should be starting.
startingTasks = checkStartingTasks(parallelism) startingTasks = checkStartingTasks(parallelism)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances - parallelism, image2: parallelism})
// make it healthy // make it healthy
makeTasksHealthy(startingTasks) makeTasksHealthy(startingTasks)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})
// 3nd batch // 3nd batch
// The old tasks should be running, and the new ones should be starting. // The old tasks should be running, and the new ones should be starting.
startingTasks = checkStartingTasks(1) startingTasks = checkStartingTasks(1)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})
// make it healthy // make it healthy
makeTasksHealthy(startingTasks) makeTasksHealthy(startingTasks)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image2: instances})
// Roll back to the previous version. This uses the CLI because // Roll back to the previous version. This uses the CLI because
// rollback is a client-side operation. // rollback is a client-side operation.
@ -300,12 +289,11 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// first batch // first batch
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})
// 2nd batch // 2nd batch
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances})
} }
func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *testing.T) { func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *testing.T) {
@ -315,7 +303,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *testing.T) {
daemons[i] = s.AddDaemon(c, true, i == 0) daemons[i] = s.AddDaemon(c, true, i == 0)
} }
// wait for nodes ready // wait for nodes ready
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount) poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))
// service image at start // service image at start
image1 := "busybox:latest" image1 := "busybox:latest"
@ -327,15 +315,14 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *testing.T) {
id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances)) id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances))
// wait for tasks ready // wait for tasks ready
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances})
// issue service update // issue service update
service := daemons[0].GetService(c, id) service := daemons[0].GetService(c, id)
daemons[0].UpdateService(c, service, setImage(image2), setFailureAction(swarm.UpdateFailureActionPause), setMaxFailureRatio(0.25), setParallelism(1)) daemons[0].UpdateService(c, service, setImage(image2), setFailureAction(swarm.UpdateFailureActionPause), setMaxFailureRatio(0.25), setParallelism(1))
// should update 2 tasks and then pause // should update 2 tasks and then pause
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceUpdateState(id), checker.Equals, swarm.UpdateStatePaused) poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceUpdateState(id), checker.Equals(swarm.UpdateStatePaused)), poll.WithTimeout(defaultReconciliationTimeout))
v, _ := daemons[0].CheckServiceRunningTasks(id)(c) v, _ := daemons[0].CheckServiceRunningTasks(id)(c)
assert.Assert(c, v == instances-2) assert.Assert(c, v == instances-2)
@ -344,8 +331,8 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *testing.T) {
out, err := daemons[0].Cmd("service", "update", "--detach", "--rollback", id) out, err := daemons[0].Cmd("service", "update", "--detach", "--rollback", id)
assert.NilError(c, err, out) assert.NilError(c, err, out)
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image1: instances})
} }
func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *testing.T) { func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *testing.T) {
@ -355,14 +342,14 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *testing.T) {
daemons[i] = s.AddDaemon(c, true, i == 0) daemons[i] = s.AddDaemon(c, true, i == 0)
} }
// wait for nodes ready // wait for nodes ready
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount) poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))
// create service // create service
constraints := []string{"node.role==worker"} constraints := []string{"node.role==worker"}
instances := 3 instances := 3
id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
// wait for tasks ready // wait for tasks ready
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
// validate tasks are running on worker nodes // validate tasks are running on worker nodes
tasks := daemons[0].GetServiceTasks(c, id) tasks := daemons[0].GetServiceTasks(c, id)
for _, task := range tasks { for _, task := range tasks {
@ -376,7 +363,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *testing.T) {
constraints = []string{"node.role!=worker"} constraints = []string{"node.role!=worker"}
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
// wait for tasks ready // wait for tasks ready
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
tasks = daemons[0].GetServiceTasks(c, id) tasks = daemons[0].GetServiceTasks(c, id)
// validate tasks are running on manager nodes // validate tasks are running on manager nodes
for _, task := range tasks { for _, task := range tasks {
@ -390,7 +377,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *testing.T) {
constraints = []string{"node.role==nosuchrole"} constraints = []string{"node.role==nosuchrole"}
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
// wait for tasks created // wait for tasks created
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceTasks(id), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
// let scheduler try // let scheduler try
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
// validate tasks are not assigned to any node // validate tasks are not assigned to any node
@ -407,7 +394,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
daemons[i] = s.AddDaemon(c, true, i == 0) daemons[i] = s.AddDaemon(c, true, i == 0)
} }
// wait for nodes ready // wait for nodes ready
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount) poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))
nodes := daemons[0].ListNodes(c) nodes := daemons[0].ListNodes(c)
assert.Equal(c, len(nodes), nodeCount) assert.Equal(c, len(nodes), nodeCount)
@ -430,7 +417,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
constraints := []string{"node.labels.security==high"} constraints := []string{"node.labels.security==high"}
id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
// wait for tasks ready // wait for tasks ready
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
tasks := daemons[0].GetServiceTasks(c, id) tasks := daemons[0].GetServiceTasks(c, id)
// validate all tasks are running on nodes[0] // validate all tasks are running on nodes[0]
for _, task := range tasks { for _, task := range tasks {
@ -443,7 +430,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
constraints = []string{"node.labels.security!=high"} constraints = []string{"node.labels.security!=high"}
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
// wait for tasks ready // wait for tasks ready
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
tasks = daemons[0].GetServiceTasks(c, id) tasks = daemons[0].GetServiceTasks(c, id)
// validate all tasks are NOT running on nodes[0] // validate all tasks are NOT running on nodes[0]
for _, task := range tasks { for _, task := range tasks {
@ -455,7 +442,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
constraints = []string{"node.labels.security==medium"} constraints = []string{"node.labels.security==medium"}
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
// wait for tasks created // wait for tasks created
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceTasks(id), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
// let scheduler try // let scheduler try
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
tasks = daemons[0].GetServiceTasks(c, id) tasks = daemons[0].GetServiceTasks(c, id)
@ -473,7 +460,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
} }
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
// wait for tasks created // wait for tasks created
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceTasks(id), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
// let scheduler try // let scheduler try
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
tasks = daemons[0].GetServiceTasks(c, id) tasks = daemons[0].GetServiceTasks(c, id)
@ -488,7 +475,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
} }
}) })
// wait for tasks ready // wait for tasks ready
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
tasks = daemons[0].GetServiceTasks(c, id) tasks = daemons[0].GetServiceTasks(c, id)
for _, task := range tasks { for _, task := range tasks {
assert.Assert(c, task.NodeID == nodes[1].ID) assert.Assert(c, task.NodeID == nodes[1].ID)
@ -502,7 +489,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicePlacementPrefs(c *testing.T) {
daemons[i] = s.AddDaemon(c, true, i == 0) daemons[i] = s.AddDaemon(c, true, i == 0)
} }
// wait for nodes ready // wait for nodes ready
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount) poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))
nodes := daemons[0].ListNodes(c) nodes := daemons[0].ListNodes(c)
assert.Equal(c, len(nodes), nodeCount) assert.Equal(c, len(nodes), nodeCount)
@ -525,7 +512,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicePlacementPrefs(c *testing.T) {
prefs := []swarm.PlacementPreference{{Spread: &swarm.SpreadOver{SpreadDescriptor: "node.labels.rack"}}} prefs := []swarm.PlacementPreference{{Spread: &swarm.SpreadOver{SpreadDescriptor: "node.labels.rack"}}}
id := daemons[0].CreateService(c, simpleTestService, setPlacementPrefs(prefs), setInstances(instances)) id := daemons[0].CreateService(c, simpleTestService, setPlacementPrefs(prefs), setInstances(instances))
// wait for tasks ready // wait for tasks ready
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
tasks := daemons[0].GetServiceTasks(c, id) tasks := daemons[0].GetServiceTasks(c, id)
// validate all tasks are running on nodes[0] // validate all tasks are running on nodes[0]
tasksOnNode := make(map[string]int) tasksOnNode := make(map[string]int)
@ -550,7 +537,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *testing.T) {
instances := 9 instances := 9
d1.CreateService(c, simpleTestService, setInstances(instances)) d1.CreateService(c, simpleTestService, setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
getContainers := func() map[string]*daemon.Daemon { getContainers := func() map[string]*daemon.Daemon {
m := make(map[string]*daemon.Daemon) m := make(map[string]*daemon.Daemon)
@ -572,7 +559,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *testing.T) {
_, err := containers[toRemove].Cmd("stop", toRemove) _, err := containers[toRemove].Cmd("stop", toRemove)
assert.NilError(c, err) assert.NilError(c, err)
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
containers2 := getContainers() containers2 := getContainers()
assert.Assert(c, len(containers2) == instances) assert.Assert(c, len(containers2) == instances)
@ -598,7 +585,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *testing.T) {
time.Sleep(time.Second) // give some time to handle the signal time.Sleep(time.Second) // give some time to handle the signal
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
containers2 = getContainers() containers2 = getContainers()
assert.Assert(c, len(containers2) == instances) assert.Assert(c, len(containers2) == instances)

View file

@ -30,6 +30,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"gotest.tools/assert" "gotest.tools/assert"
is "gotest.tools/assert/cmp" is "gotest.tools/assert/cmp"
"gotest.tools/poll"
) )
var defaultReconciliationTimeout = 30 * time.Second var defaultReconciliationTimeout = 30 * time.Second
@ -208,13 +209,13 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *testing.T) {
n.Spec.Role = swarm.NodeRoleManager n.Spec.Role = swarm.NodeRoleManager
}) })
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.True) poll.WaitOn(c, pollCheck(c, d2.CheckControlAvailable, checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) { d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
n.Spec.Role = swarm.NodeRoleWorker n.Spec.Role = swarm.NodeRoleWorker
}) })
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.False) poll.WaitOn(c, pollCheck(c, d2.CheckControlAvailable, checker.False()), poll.WithTimeout(defaultReconciliationTimeout))
// Wait for the role to change to worker in the cert. This is partially // Wait for the role to change to worker in the cert. This is partially
// done because it's something worth testing in its own right, and // done because it's something worth testing in its own right, and
@ -222,7 +223,7 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *testing.T) {
// back to manager quickly might cause the node to pause for awhile // back to manager quickly might cause the node to pause for awhile
// while waiting for the role to change to worker, and the test can // while waiting for the role to change to worker, and the test can
// time out during this interval. // time out during this interval.
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
certBytes, err := ioutil.ReadFile(filepath.Join(d2.Folder, "root", "swarm", "certificates", "swarm-node.crt")) certBytes, err := ioutil.ReadFile(filepath.Join(d2.Folder, "root", "swarm", "certificates", "swarm-node.crt"))
if err != nil { if err != nil {
return "", fmt.Sprintf("error: %v", err) return "", fmt.Sprintf("error: %v", err)
@ -232,7 +233,7 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *testing.T) {
return certs[0].Subject.OrganizationalUnit[0], "" return certs[0].Subject.OrganizationalUnit[0], ""
} }
return "", "could not get organizational unit from certificate" return "", "could not get organizational unit from certificate"
}, checker.Equals, "swarm-worker") }, checker.Equals("swarm-worker")), poll.WithTimeout(defaultReconciliationTimeout))
// Demoting last node should fail // Demoting last node should fail
node := d1.GetNode(c, d1.NodeID()) node := d1.GetNode(c, d1.NodeID())
@ -262,7 +263,7 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *testing.T) {
n.Spec.Role = swarm.NodeRoleManager n.Spec.Role = swarm.NodeRoleManager
}) })
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.True) poll.WaitOn(c, pollCheck(c, d2.CheckControlAvailable, checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
} }
func (s *DockerSwarmSuite) TestAPISwarmLeaderProxy(c *testing.T) { func (s *DockerSwarmSuite) TestAPISwarmLeaderProxy(c *testing.T) {
@ -348,7 +349,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) {
// wait for an election to occur // wait for an election to occur
c.Logf("Waiting for election to occur...") c.Logf("Waiting for election to occur...")
waitAndAssert(c, defaultReconciliationTimeout, checkLeader(d2, d3), checker.True) poll.WaitOn(c, pollCheck(c, checkLeader(d2, d3), checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
// assert that we have a new leader // assert that we have a new leader
assert.Assert(c, leader != nil) assert.Assert(c, leader != nil)
@ -361,7 +362,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) {
// wait for possible election // wait for possible election
c.Logf("Waiting for possible election...") c.Logf("Waiting for possible election...")
waitAndAssert(c, defaultReconciliationTimeout, checkLeader(d1, d2, d3), checker.True) poll.WaitOn(c, pollCheck(c, checkLeader(d1, d2, d3), checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
// pick out the leader and the followers again // pick out the leader and the followers again
// verify that we still only have 1 leader and 2 followers // verify that we still only have 1 leader and 2 followers
@ -388,7 +389,7 @@ func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *testing.T) {
d2.Stop(c) d2.Stop(c)
// make sure there is a leader // make sure there is a leader
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckLeader, checker.IsNil) poll.WaitOn(c, pollCheck(c, d1.CheckLeader, checker.IsNil()), poll.WithTimeout(defaultReconciliationTimeout))
d1.CreateService(c, simpleTestService, func(s *swarm.Service) { d1.CreateService(c, simpleTestService, func(s *swarm.Service) {
s.Spec.Name = "top1" s.Spec.Name = "top1"
@ -403,15 +404,15 @@ func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *testing.T) {
defer cli.Close() defer cli.Close()
// d1 will eventually step down from leader because there is no longer an active quorum, wait for that to happen // d1 will eventually step down from leader because there is no longer an active quorum, wait for that to happen
waitAndAssert(c, defaultReconciliationTimeout*2, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
_, err := cli.ServiceCreate(context.Background(), service.Spec, types.ServiceCreateOptions{}) _, err := cli.ServiceCreate(context.Background(), service.Spec, types.ServiceCreateOptions{})
return err.Error(), "" return err.Error(), ""
}, checker.Contains, "Make sure more than half of the managers are online.") }, checker.Contains("Make sure more than half of the managers are online.")), poll.WithTimeout(defaultReconciliationTimeout*2))
d2.StartNode(c) d2.StartNode(c)
// make sure there is a leader // make sure there is a leader
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckLeader, checker.IsNil) poll.WaitOn(c, pollCheck(c, d1.CheckLeader, checker.IsNil()), poll.WithTimeout(defaultReconciliationTimeout))
d1.CreateService(c, simpleTestService, func(s *swarm.Service) { d1.CreateService(c, simpleTestService, func(s *swarm.Service) {
s.Spec.Name = "top3" s.Spec.Name = "top3"
@ -428,12 +429,12 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaveRemovesContainer(c *testing.T) {
assert.NilError(c, err, id) assert.NilError(c, err, id)
id = strings.TrimSpace(id) id = strings.TrimSpace(id)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances+1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances+1)), poll.WithTimeout(defaultReconciliationTimeout))
assert.ErrorContains(c, d.SwarmLeave(c, false), "") assert.ErrorContains(c, d.SwarmLeave(c, false), "")
assert.NilError(c, d.SwarmLeave(c, true)) assert.NilError(c, d.SwarmLeave(c, true))
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
id2, err := d.Cmd("ps", "-q") id2, err := d.Cmd("ps", "-q")
assert.NilError(c, err, id2) assert.NilError(c, err, id2)
@ -462,7 +463,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaveOnPendingJoin(c *testing.T) {
assert.NilError(c, d2.SwarmLeave(c, true)) assert.NilError(c, d2.SwarmLeave(c, true))
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
id2, err := d2.Cmd("ps", "-q") id2, err := d2.Cmd("ps", "-q")
assert.NilError(c, err, id2) assert.NilError(c, err, id2)
@ -480,7 +481,7 @@ func (s *DockerSwarmSuite) TestAPISwarmRestoreOnPendingJoin(c *testing.T) {
}) })
assert.ErrorContains(c, err, "Timeout was reached") assert.ErrorContains(c, err, "Timeout was reached")
waitAndAssert(c, defaultReconciliationTimeout, d.CheckLocalNodeState, checker.Equals, swarm.LocalNodeStatePending) poll.WaitOn(c, pollCheck(c, d.CheckLocalNodeState, checker.Equals(swarm.LocalNodeStatePending)), poll.WithTimeout(defaultReconciliationTimeout))
d.RestartNode(c) d.RestartNode(c)
@ -521,11 +522,11 @@ func (s *DockerSwarmSuite) TestAPISwarmScaleNoRollingUpdate(c *testing.T) {
instances := 2 instances := 2
id := d.CreateService(c, simpleTestService, setInstances(instances)) id := d.CreateService(c, simpleTestService, setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
containers := d.ActiveContainers(c) containers := d.ActiveContainers(c)
instances = 4 instances = 4
d.UpdateService(c, d.GetService(c, id), setInstances(instances)) d.UpdateService(c, d.GetService(c, id), setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
containers2 := d.ActiveContainers(c) containers2 := d.ActiveContainers(c)
loop0: loop0:
@ -563,14 +564,14 @@ func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *testing.T) {
instances := 2 instances := 2
id := d1.CreateService(c, simpleTestService, setInstances(instances)) id := d1.CreateService(c, simpleTestService, setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
// drain d2, all containers should move to d1 // drain d2, all containers should move to d1
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) { d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
n.Spec.Availability = swarm.NodeAvailabilityDrain n.Spec.Availability = swarm.NodeAvailabilityDrain
}) })
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances) poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 0) poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
d2.Stop(c) d2.Stop(c)
@ -579,7 +580,7 @@ func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *testing.T) {
Spec: swarm.Spec{}, Spec: swarm.Spec{},
}) })
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances) poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
d3 := s.AddDaemon(c, true, true) d3 := s.AddDaemon(c, true, true)
info := d3.SwarmInfo(c) info := d3.SwarmInfo(c)
@ -589,7 +590,7 @@ func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *testing.T) {
instances = 4 instances = 4
d3.UpdateService(c, d3.GetService(c, id), setInstances(instances)) d3.UpdateService(c, d3.GetService(c, id), setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
} }
func simpleTestService(s *swarm.Service) { func simpleTestService(s *swarm.Service) {
@ -743,7 +744,7 @@ func checkClusterHealth(c *testing.T, cl []*daemon.Daemon, managerCount, workerC
info = daemonInfo.Swarm info = daemonInfo.Swarm
return err, "cluster not ready in time" return err, "cluster not ready in time"
} }
waitAndAssert(c, defaultReconciliationTimeout, checkInfo, checker.IsNil) poll.WaitOn(c, pollCheck(c, checkInfo, checker.IsNil()), poll.WithTimeout(defaultReconciliationTimeout))
if !info.ControlAvailable { if !info.ControlAvailable {
totalWCount++ totalWCount++
continue continue
@ -762,7 +763,7 @@ func checkClusterHealth(c *testing.T, cl []*daemon.Daemon, managerCount, workerC
n = *nn n = *nn
return n.Status.State == swarm.NodeStateReady, fmt.Sprintf("state of node %s, reported by %s", n.ID, d.NodeID()) return n.Status.State == swarm.NodeStateReady, fmt.Sprintf("state of node %s, reported by %s", n.ID, d.NodeID())
} }
waitAndAssert(c, defaultReconciliationTimeout, waitReady, checker.True) poll.WaitOn(c, pollCheck(c, waitReady, checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
waitActive := func(c *testing.T) (interface{}, string) { waitActive := func(c *testing.T) (interface{}, string) {
if n.Spec.Availability == swarm.NodeAvailabilityActive { if n.Spec.Availability == swarm.NodeAvailabilityActive {
@ -772,7 +773,7 @@ func checkClusterHealth(c *testing.T, cl []*daemon.Daemon, managerCount, workerC
n = *nn n = *nn
return n.Spec.Availability == swarm.NodeAvailabilityActive, fmt.Sprintf("availability of node %s, reported by %s", n.ID, d.NodeID()) return n.Spec.Availability == swarm.NodeAvailabilityActive, fmt.Sprintf("availability of node %s, reported by %s", n.ID, d.NodeID())
} }
waitAndAssert(c, defaultReconciliationTimeout, waitActive, checker.True) poll.WaitOn(c, pollCheck(c, waitActive, checker.True()), poll.WithTimeout(defaultReconciliationTimeout))
if n.Spec.Role == swarm.NodeRoleManager { if n.Spec.Role == swarm.NodeRoleManager {
assert.Assert(c, n.ManagerStatus != nil, "manager status of node %s (manager), reported by %s", n.ID, d.NodeID()) assert.Assert(c, n.ManagerStatus != nil, "manager status of node %s (manager), reported by %s", n.ID, d.NodeID())
@ -863,7 +864,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateWithName(c *testing.T) {
instances := 2 instances := 2
id := d.CreateService(c, simpleTestService, setInstances(instances)) id := d.CreateService(c, simpleTestService, setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
service := d.GetService(c, id) service := d.GetService(c, id)
instances = 5 instances = 5
@ -873,7 +874,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateWithName(c *testing.T) {
defer cli.Close() defer cli.Close()
_, err := cli.ServiceUpdate(context.Background(), service.Spec.Name, service.Version, service.Spec, types.ServiceUpdateOptions{}) _, err := cli.ServiceUpdate(context.Background(), service.Spec.Name, service.Version, service.Spec, types.ServiceUpdateOptions{})
assert.NilError(c, err) assert.NilError(c, err)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
} }
// Unlocking an unlocked swarm results in an error // Unlocking an unlocked swarm results in an error
@ -948,7 +949,7 @@ func (s *DockerSwarmSuite) TestAPISwarmHealthcheckNone(c *testing.T) {
} }
}) })
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
containers := d.ActiveContainers(c) containers := d.ActiveContainers(c)

View file

@ -40,6 +40,7 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/icmd" "gotest.tools/icmd"
"gotest.tools/poll"
) )
const containerdSocket = "/var/run/docker/containerd/containerd.sock" const containerdSocket = "/var/run/docker/containerd/containerd.sock"
@ -2071,10 +2072,10 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithUnpausedRunningContainer(t *tes
// Give time to containerd to process the command if we don't // Give time to containerd to process the command if we don't
// the resume event might be received after we do the inspect // the resume event might be received after we do the inspect
waitAndAssert(t, defaultReconciliationTimeout, func(*testing.T) (interface{}, string) { poll.WaitOn(t, pollCheck(t, func(*testing.T) (interface{}, string) {
result := icmd.RunCommand("kill", "-0", strings.TrimSpace(pid)) result := icmd.RunCommand("kill", "-0", strings.TrimSpace(pid))
return result.ExitCode, "" return result.ExitCode, ""
}, checker.Equals, 0) }, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
// restart the daemon // restart the daemon
s.d.Start(t, "--live-restore") s.d.Start(t, "--live-restore")

View file

@ -17,6 +17,7 @@ import (
"github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration-cli/daemon"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/icmd" "gotest.tools/icmd"
"gotest.tools/poll"
) )
func pruneNetworkAndVerify(c *testing.T, d *daemon.Daemon, kept, pruned []string) { func pruneNetworkAndVerify(c *testing.T, d *daemon.Daemon, kept, pruned []string) {
@ -24,19 +25,21 @@ func pruneNetworkAndVerify(c *testing.T, d *daemon.Daemon, kept, pruned []string
assert.NilError(c, err) assert.NilError(c, err)
for _, s := range kept { for _, s := range kept {
waitAndAssert(c, defaultReconciliationTimeout, func(*testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(*testing.T) (interface{}, string) {
out, err := d.Cmd("network", "ls", "--format", "{{.Name}}") out, err := d.Cmd("network", "ls", "--format", "{{.Name}}")
assert.NilError(c, err) assert.NilError(c, err)
return out, "" return out, ""
}, checker.Contains, s) }, checker.Contains(s)), poll.WithTimeout(defaultReconciliationTimeout))
} }
for _, s := range pruned { for _, s := range pruned {
waitAndAssert(c, defaultReconciliationTimeout, func(*testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(*testing.T) (interface{}, string) {
out, err := d.Cmd("network", "ls", "--format", "{{.Name}}") out, err := d.Cmd("network", "ls", "--format", "{{.Name}}")
assert.NilError(c, err) assert.NilError(c, err)
return out, "" return out, ""
}, checker.Not(checker.Contains(s))) }, checker.Not(checker.Contains(s))()), poll.WithTimeout(defaultReconciliationTimeout))
} }
} }
@ -64,7 +67,7 @@ func (s *DockerSwarmSuite) TestPruneNetwork(c *testing.T) {
"busybox", "top") "busybox", "top")
assert.NilError(c, err) assert.NilError(c, err)
assert.Assert(c, strings.TrimSpace(out) != "") assert.Assert(c, strings.TrimSpace(out) != "")
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, replicas+1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(replicas+1)), poll.WithTimeout(defaultReconciliationTimeout))
// prune and verify // prune and verify
pruneNetworkAndVerify(c, d, []string{"n1", "n3"}, []string{"n2", "n4"}) pruneNetworkAndVerify(c, d, []string{"n1", "n3"}, []string{"n2", "n4"})
@ -74,7 +77,7 @@ func (s *DockerSwarmSuite) TestPruneNetwork(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
_, err = d.Cmd("service", "rm", serviceName) _, err = d.Cmd("service", "rm", serviceName)
assert.NilError(c, err) assert.NilError(c, err)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 0) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
pruneNetworkAndVerify(c, d, []string{}, []string{"n1", "n3"}) pruneNetworkAndVerify(c, d, []string{}, []string{"n1", "n3"})
} }

View file

@ -10,6 +10,7 @@ import (
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"gotest.tools/assert" "gotest.tools/assert"
is "gotest.tools/assert/cmp" is "gotest.tools/assert/cmp"
"gotest.tools/poll"
) )
func (s *DockerSuite) TestRestartStoppedContainer(c *testing.T) { func (s *DockerSuite) TestRestartStoppedContainer(c *testing.T) {
@ -42,13 +43,13 @@ func (s *DockerSuite) TestRestartRunningContainer(c *testing.T) {
} }
// Wait 10 seconds for the 'echo' to appear in the logs // Wait 10 seconds for the 'echo' to appear in the logs
waitAndAssert(c, 10*time.Second, getLogs, checker.Equals, "foobar\n") poll.WaitOn(c, pollCheck(c, getLogs, checker.Equals("foobar\n")), poll.WithTimeout(10*time.Second))
dockerCmd(c, "restart", "-t", "1", cleanedContainerID) dockerCmd(c, "restart", "-t", "1", cleanedContainerID)
assert.NilError(c, waitRun(cleanedContainerID)) assert.NilError(c, waitRun(cleanedContainerID))
// Wait 10 seconds for first 'echo' appear (again) in the logs // Wait 10 seconds for first 'echo' appear (again) in the logs
waitAndAssert(c, 10*time.Second, getLogs, checker.Equals, "foobar\nfoobar\n") poll.WaitOn(c, pollCheck(c, getLogs, checker.Equals("foobar\nfoobar\n")), poll.WithTimeout(10*time.Second))
} }
// Test that restarting a container with a volume does not create a new volume on restart. Regression test for #819. // Test that restarting a container with a volume does not create a new volume on restart. Regression test for #819.

View file

@ -14,6 +14,7 @@ import (
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/poll"
) )
func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) { func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) {
@ -23,18 +24,18 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) {
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
var tasks []swarm.Task var tasks []swarm.Task
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks = d.GetServiceTasks(c, id) tasks = d.GetServiceTasks(c, id)
return len(tasks) > 0, "" return len(tasks) > 0, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
task := tasks[0] task := tasks[0]
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
if task.NodeID == "" || task.Status.ContainerStatus == nil { if task.NodeID == "" || task.Status.ContainerStatus == nil {
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
} }
return task.NodeID != "" && task.Status.ContainerStatus != nil, "" return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
// check container mount config // check container mount config
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID) out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID)
@ -137,18 +138,18 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *testi
assert.Equal(c, len(refs), len(testPaths)) assert.Equal(c, len(refs), len(testPaths))
var tasks []swarm.Task var tasks []swarm.Task
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks = d.GetServiceTasks(c, serviceName) tasks = d.GetServiceTasks(c, serviceName)
return len(tasks) > 0, "" return len(tasks) > 0, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
task := tasks[0] task := tasks[0]
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
if task.NodeID == "" || task.Status.ContainerStatus == nil { if task.NodeID == "" || task.Status.ContainerStatus == nil {
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
} }
return task.NodeID != "" && task.Status.ContainerStatus != nil, "" return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
for testName, testTarget := range testPaths { for testName, testTarget := range testPaths {
path := testTarget path := testTarget
@ -187,18 +188,18 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *testing
assert.Equal(c, len(refs), 2) assert.Equal(c, len(refs), 2)
var tasks []swarm.Task var tasks []swarm.Task
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks = d.GetServiceTasks(c, serviceName) tasks = d.GetServiceTasks(c, serviceName)
return len(tasks) > 0, "" return len(tasks) > 0, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
task := tasks[0] task := tasks[0]
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
if task.NodeID == "" || task.Status.ContainerStatus == nil { if task.NodeID == "" || task.Status.ContainerStatus == nil {
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
} }
return task.NodeID != "" && task.Status.ContainerStatus != nil, "" return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
for _, target := range []string{"target1", "target2"} { for _, target := range []string{"target1", "target2"} {
assert.NilError(c, err, out) assert.NilError(c, err, out)
@ -284,18 +285,18 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *testi
assert.Equal(c, len(refs), len(testPaths)) assert.Equal(c, len(refs), len(testPaths))
var tasks []swarm.Task var tasks []swarm.Task
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks = d.GetServiceTasks(c, serviceName) tasks = d.GetServiceTasks(c, serviceName)
return len(tasks) > 0, "" return len(tasks) > 0, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
task := tasks[0] task := tasks[0]
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
if task.NodeID == "" || task.Status.ContainerStatus == nil { if task.NodeID == "" || task.Status.ContainerStatus == nil {
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
} }
return task.NodeID != "" && task.Status.ContainerStatus != nil, "" return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
for testName, testTarget := range testPaths { for testName, testTarget := range testPaths {
path := testTarget path := testTarget
@ -334,18 +335,18 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *testing
assert.Equal(c, len(refs), 2) assert.Equal(c, len(refs), 2)
var tasks []swarm.Task var tasks []swarm.Task
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks = d.GetServiceTasks(c, serviceName) tasks = d.GetServiceTasks(c, serviceName)
return len(tasks) > 0, "" return len(tasks) > 0, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
task := tasks[0] task := tasks[0]
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
if task.NodeID == "" || task.Status.ContainerStatus == nil { if task.NodeID == "" || task.Status.ContainerStatus == nil {
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
} }
return task.NodeID != "" && task.Status.ContainerStatus != nil, "" return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
for _, target := range []string{"target1", "target2"} { for _, target := range []string{"target1", "target2"} {
assert.NilError(c, err, out) assert.NilError(c, err, out)
@ -366,18 +367,18 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *testing.T) {
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
var tasks []swarm.Task var tasks []swarm.Task
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks = d.GetServiceTasks(c, id) tasks = d.GetServiceTasks(c, id)
return len(tasks) > 0, "" return len(tasks) > 0, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
task := tasks[0] task := tasks[0]
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
if task.NodeID == "" || task.Status.ContainerStatus == nil { if task.NodeID == "" || task.Status.ContainerStatus == nil {
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
} }
return task.NodeID != "" && task.Status.ContainerStatus != nil, "" return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
// check container mount config // check container mount config
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID) out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID)
@ -422,18 +423,18 @@ func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *testing.T) {
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
var tasks []swarm.Task var tasks []swarm.Task
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks = d.GetServiceTasks(c, id) tasks = d.GetServiceTasks(c, id)
return len(tasks) > 0, "" return len(tasks) > 0, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
task := tasks[0] task := tasks[0]
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
if task.NodeID == "" || task.Status.ContainerStatus == nil { if task.NodeID == "" || task.Status.ContainerStatus == nil {
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
} }
return task.NodeID != "" && task.Status.ContainerStatus != nil, "" return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
}, checker.Equals, true) }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
// check container alias config // check container alias config
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .NetworkSettings.Networks.test_swarm_br.Aliases}}", task.Status.ContainerStatus.ContainerID) out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .NetworkSettings.Networks.test_swarm_br.Aliases}}", task.Status.ContainerStatus.ContainerID)

View file

@ -14,6 +14,7 @@ import (
"github.com/docker/docker/integration-cli/cli/build" "github.com/docker/docker/integration-cli/cli/build"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/icmd" "gotest.tools/icmd"
"gotest.tools/poll"
) )
// start a service, and then make its task unhealthy during running // start a service, and then make its task unhealthy during running
@ -39,39 +40,40 @@ func (s *DockerSwarmSuite) TestServiceHealthRun(c *testing.T) {
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
var tasks []swarm.Task var tasks []swarm.Task
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks = d.GetServiceTasks(c, id) tasks = d.GetServiceTasks(c, id)
return tasks, "" return tasks, ""
}, checker.HasLen, 1) }, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout))
task := tasks[0] task := tasks[0]
// wait for task to start // wait for task to start
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
return task.Status.State, "" return task.Status.State, ""
}, checker.Equals, swarm.TaskStateRunning) }, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout))
containerID := task.Status.ContainerStatus.ContainerID containerID := task.Status.ContainerStatus.ContainerID
// wait for container to be healthy // wait for container to be healthy
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID) out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID)
return strings.TrimSpace(out), "" return strings.TrimSpace(out), ""
}, checker.Equals, "healthy") }, checker.Equals("healthy")), poll.WithTimeout(defaultReconciliationTimeout))
// make it fail // make it fail
d.Cmd("exec", containerID, "rm", "/status") d.Cmd("exec", containerID, "rm", "/status")
// wait for container to be unhealthy // wait for container to be unhealthy
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID) out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID)
return strings.TrimSpace(out), "" return strings.TrimSpace(out), ""
}, checker.Equals, "unhealthy") }, checker.Equals("unhealthy")), poll.WithTimeout(defaultReconciliationTimeout))
// Task should be terminated // Task should be terminated
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
return task.Status.State, "" return task.Status.State, ""
}, checker.Equals, swarm.TaskStateFailed) }, checker.Equals(swarm.TaskStateFailed)), poll.WithTimeout(defaultReconciliationTimeout))
if !strings.Contains(task.Status.Err, container.ErrContainerUnhealthy.Error()) { if !strings.Contains(task.Status.Err, container.ErrContainerUnhealthy.Error()) {
c.Fatal("unhealthy task exits because of other error") c.Fatal("unhealthy task exits because of other error")
@ -100,27 +102,27 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *testing.T) {
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
var tasks []swarm.Task var tasks []swarm.Task
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
tasks = d.GetServiceTasks(c, id) tasks = d.GetServiceTasks(c, id)
return tasks, "" return tasks, ""
}, checker.HasLen, 1) }, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout))
task := tasks[0] task := tasks[0]
// wait for task to start // wait for task to start
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
return task.Status.State, "" return task.Status.State, ""
}, checker.Equals, swarm.TaskStateStarting) }, checker.Equals(swarm.TaskStateStarting)), poll.WithTimeout(defaultReconciliationTimeout))
containerID := task.Status.ContainerStatus.ContainerID containerID := task.Status.ContainerStatus.ContainerID
// wait for health check to work // wait for health check to work
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
out, _ := d.Cmd("inspect", "--format={{.State.Health.FailingStreak}}", containerID) out, _ := d.Cmd("inspect", "--format={{.State.Health.FailingStreak}}", containerID)
failingStreak, _ := strconv.Atoi(strings.TrimSpace(out)) failingStreak, _ := strconv.Atoi(strings.TrimSpace(out))
return failingStreak, "" return failingStreak, ""
}, checker.GreaterThan, 0) }, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
// task should be blocked at starting status // task should be blocked at starting status
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
@ -130,8 +132,9 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *testing.T) {
d.Cmd("exec", containerID, "touch", "/status") d.Cmd("exec", containerID, "touch", "/status")
// Task should be at running status // Task should be at running status
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
task = d.GetTask(c, task.ID) task = d.GetTask(c, task.ID)
return task.Status.State, "" return task.Status.State, ""
}, checker.Equals, swarm.TaskStateRunning) }, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout))
} }

View file

@ -15,6 +15,7 @@ import (
"github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration-cli/daemon"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/icmd" "gotest.tools/icmd"
"gotest.tools/poll"
) )
type logMessage struct { type logMessage struct {
@ -39,9 +40,8 @@ func (s *DockerSwarmSuite) TestServiceLogs(c *testing.T) {
} }
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, poll.WaitOn(c, pollCheck(c,
d.CheckRunningTaskImages, checker.DeepEquals, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{"busybox:latest": len(services)})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{"busybox:latest": len(services)})
for name, message := range services { for name, message := range services {
out, err := d.Cmd("service", "logs", name) out, err := d.Cmd("service", "logs", name)
@ -80,9 +80,9 @@ func (s *DockerSwarmSuite) TestServiceLogsCompleteness(c *testing.T) {
assert.Assert(c, strings.TrimSpace(out) != "") assert.Assert(c, strings.TrimSpace(out) != "")
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// and make sure we have all the log lines // and make sure we have all the log lines
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 6) poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(6)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("service", "logs", name) out, err = d.Cmd("service", "logs", name)
assert.NilError(c, err) assert.NilError(c, err)
@ -107,8 +107,8 @@ func (s *DockerSwarmSuite) TestServiceLogsTail(c *testing.T) {
assert.Assert(c, strings.TrimSpace(out) != "") assert.Assert(c, strings.TrimSpace(out) != "")
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 6) poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(6)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("service", "logs", "--tail=2", name) out, err = d.Cmd("service", "logs", "--tail=2", name)
assert.NilError(c, err) assert.NilError(c, err)
@ -129,9 +129,9 @@ func (s *DockerSwarmSuite) TestServiceLogsSince(c *testing.T) {
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "busybox", "sh", "-c", "for i in $(seq 1 3); do sleep .1; echo log$i; done; sleep 10000000") out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "busybox", "sh", "-c", "for i in $(seq 1 3); do sleep .1; echo log$i; done; sleep 10000000")
assert.NilError(c, err) assert.NilError(c, err)
assert.Assert(c, strings.TrimSpace(out) != "") assert.Assert(c, strings.TrimSpace(out) != "")
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// wait a sec for the logs to come in // wait a sec for the logs to come in
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 3) poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(3)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("service", "logs", "-t", name) out, err = d.Cmd("service", "logs", "-t", name)
assert.NilError(c, err) assert.NilError(c, err)
@ -165,7 +165,7 @@ func (s *DockerSwarmSuite) TestServiceLogsFollow(c *testing.T) {
assert.Assert(c, strings.TrimSpace(out) != "") assert.Assert(c, strings.TrimSpace(out) != "")
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
args := []string{"service", "logs", "-f", name} args := []string{"service", "logs", "-f", name}
cmd := exec.Command(dockerBinary, d.PrependHostArg(args)...) cmd := exec.Command(dockerBinary, d.PrependHostArg(args)...)
@ -228,8 +228,8 @@ func (s *DockerSwarmSuite) TestServiceLogsTaskLogs(c *testing.T) {
result.Assert(c, icmd.Expected{Out: id}) result.Assert(c, icmd.Expected{Out: id})
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, replicas) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(replicas)), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 6*replicas) poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(6*replicas)), poll.WithTimeout(defaultReconciliationTimeout))
// get the task ids // get the task ids
result = icmd.RunCmd(d.Command("service", "ps", "-q", name)) result = icmd.RunCmd(d.Command("service", "ps", "-q", name))
@ -281,9 +281,9 @@ func (s *DockerSwarmSuite) TestServiceLogsTTY(c *testing.T) {
result.Assert(c, icmd.Expected{Out: id}) result.Assert(c, icmd.Expected{Out: id})
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// and make sure we have all the log lines // and make sure we have all the log lines
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 2) poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(2)), poll.WithTimeout(defaultReconciliationTimeout))
cmd := d.Command("service", "logs", "--raw", name) cmd := d.Command("service", "logs", "--raw", name)
result = icmd.RunCmd(cmd) result = icmd.RunCmd(cmd)
@ -315,9 +315,9 @@ func (s *DockerSwarmSuite) TestServiceLogsNoHangDeletedContainer(c *testing.T) {
assert.Assert(c, id != "") assert.Assert(c, id != "")
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// and make sure we have all the log lines // and make sure we have all the log lines
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 2) poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(2)), poll.WithTimeout(defaultReconciliationTimeout))
// now find and nuke the container // now find and nuke the container
result = icmd.RunCmd(d.Command("ps", "-q")) result = icmd.RunCmd(d.Command("ps", "-q"))
@ -368,9 +368,9 @@ func (s *DockerSwarmSuite) TestServiceLogsDetails(c *testing.T) {
assert.Assert(c, id != "") assert.Assert(c, id != "")
// make sure task has been deployed // make sure task has been deployed
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// and make sure we have all the log lines // and make sure we have all the log lines
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 1) poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// First, test without pretty printing // First, test without pretty printing
// call service logs with details. set raw to skip pretty printing // call service logs with details. set raw to skip pretty printing

View file

@ -32,6 +32,7 @@ import (
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/fs" "gotest.tools/fs"
"gotest.tools/icmd" "gotest.tools/icmd"
"gotest.tools/poll"
) )
func (s *DockerSwarmSuite) TestSwarmUpdate(c *testing.T) { func (s *DockerSwarmSuite) TestSwarmUpdate(c *testing.T) {
@ -176,7 +177,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTemplatingHostname(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
containers := d.ActiveContainers(c) containers := d.ActiveContainers(c)
out, err = d.Cmd("inspect", "--type", "container", "--format", "{{.Config.Hostname}}", containers[0]) out, err = d.Cmd("inspect", "--type", "container", "--format", "{{.Config.Hostname}}", containers[0])
@ -251,7 +252,7 @@ func (s *DockerSwarmSuite) TestSwarmNodeTaskListFilter(c *testing.T) {
assert.Assert(c, strings.TrimSpace(out) != "") assert.Assert(c, strings.TrimSpace(out) != "")
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 3) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(3)), poll.WithTimeout(defaultReconciliationTimeout))
filter := "name=redis-cluster" filter := "name=redis-cluster"
@ -303,7 +304,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceWithGroup(c *testing.T) {
assert.Assert(c, strings.TrimSpace(out) != "") assert.Assert(c, strings.TrimSpace(out) != "")
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("ps", "-q") out, err = d.Cmd("ps", "-q")
assert.NilError(c, err, out) assert.NilError(c, err, out)
@ -388,7 +389,7 @@ func (s *DockerSwarmSuite) TestSwarmContainerAttachByNetworkId(c *testing.T) {
return out, "" return out, ""
} }
waitAndAssert(c, 3*time.Second, checkNetwork, checker.Not(checker.Contains("testnet"))) poll.WaitOn(c, pollCheck(c, checkNetwork, checker.Not(checker.Contains("testnet"))()), poll.WithTimeout(3*time.Second))
} }
func (s *DockerSwarmSuite) TestOverlayAttachable(c *testing.T) { func (s *DockerSwarmSuite) TestOverlayAttachable(c *testing.T) {
@ -550,7 +551,7 @@ func (s *DockerSwarmSuite) TestSwarmTaskListFilter(c *testing.T) {
} }
// wait until all tasks have been created // wait until all tasks have been created
waitAndAssert(c, defaultReconciliationTimeout, checkNumTasks, checker.Equals, 3) poll.WaitOn(c, pollCheck(c, checkNumTasks, checker.Equals(3)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("service", "ps", "--filter", filter, name) out, err = d.Cmd("service", "ps", "--filter", filter, name)
assert.NilError(c, err, out) assert.NilError(c, err, out)
@ -572,7 +573,7 @@ func (s *DockerSwarmSuite) TestSwarmTaskListFilter(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
assert.Assert(c, strings.TrimSpace(out) != "") assert.Assert(c, strings.TrimSpace(out) != "")
waitAndAssert(c, defaultReconciliationTimeout, checkNumTasks, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, checkNumTasks, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
filter = "name=redis-cluster" filter = "name=redis-cluster"
out, err = d.Cmd("service", "ps", "--filter", filter, name) out, err = d.Cmd("service", "ps", "--filter", filter, name)
@ -600,7 +601,7 @@ func (s *DockerSwarmSuite) TestPsListContainersFilterIsTask(c *testing.T) {
assert.Assert(c, strings.TrimSpace(out) != "") assert.Assert(c, strings.TrimSpace(out) != "")
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckServiceRunningTasks(name), checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckServiceRunningTasks(name), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// Filter non-tasks // Filter non-tasks
out, err = d.Cmd("ps", "-a", "-q", "--filter=is-task=false") out, err = d.Cmd("ps", "-a", "-q", "--filter=is-task=false")
@ -837,7 +838,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// Make sure task has been deployed. // Make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// We need to get the container id. // We need to get the container id.
out, err = d.Cmd("ps", "-q", "--no-trunc") out, err = d.Cmd("ps", "-q", "--no-trunc")
@ -851,7 +852,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *testing.T) {
out, err = d.Cmd("service", "rm", name) out, err = d.Cmd("service", "rm", name)
assert.NilError(c, err, out) assert.NilError(c, err, out)
// Make sure container has been destroyed. // Make sure container has been destroyed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 0) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
// With --tty // With --tty
expectedOutput = "TTY" expectedOutput = "TTY"
@ -859,7 +860,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// Make sure task has been deployed. // Make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// We need to get the container id. // We need to get the container id.
out, err = d.Cmd("ps", "-q", "--no-trunc") out, err = d.Cmd("ps", "-q", "--no-trunc")
@ -880,7 +881,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTYUpdate(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// Make sure task has been deployed. // Make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.TTY }}", name) out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.TTY }}", name)
assert.NilError(c, err, out) assert.NilError(c, err, out)
@ -915,22 +916,20 @@ func (s *DockerSwarmSuite) TestSwarmServiceNetworkUpdate(c *testing.T) {
result.Assert(c, icmd.Success) result.Assert(c, icmd.Success)
// Make sure task has been deployed. // Make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskNetworks, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskNetworks, checker.DeepEquals(map[string]int{fooNetwork: 1, barNetwork: 1})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{fooNetwork: 1, barNetwork: 1})
// Remove a network // Remove a network
result = icmd.RunCmd(d.Command("service", "update", "--detach", "--network-rm", "foo", name)) result = icmd.RunCmd(d.Command("service", "update", "--detach", "--network-rm", "foo", name))
result.Assert(c, icmd.Success) result.Assert(c, icmd.Success)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskNetworks, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskNetworks, checker.DeepEquals(map[string]int{barNetwork: 1})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{barNetwork: 1})
// Add a network // Add a network
result = icmd.RunCmd(d.Command("service", "update", "--detach", "--network-add", "baz", name)) result = icmd.RunCmd(d.Command("service", "update", "--detach", "--network-add", "baz", name))
result.Assert(c, icmd.Success) result.Assert(c, icmd.Success)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskNetworks, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskNetworks, checker.DeepEquals(map[string]int{barNetwork: 1, bazNetwork: 1})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{barNetwork: 1, bazNetwork: 1})
} }
func (s *DockerSwarmSuite) TestDNSConfig(c *testing.T) { func (s *DockerSwarmSuite) TestDNSConfig(c *testing.T) {
@ -942,7 +941,7 @@ func (s *DockerSwarmSuite) TestDNSConfig(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// Make sure task has been deployed. // Make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// We need to get the container id. // We need to get the container id.
out, err = d.Cmd("ps", "-a", "-q", "--no-trunc") out, err = d.Cmd("ps", "-a", "-q", "--no-trunc")
@ -969,7 +968,7 @@ func (s *DockerSwarmSuite) TestDNSConfigUpdate(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// Make sure task has been deployed. // Make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("service", "update", "--detach", "--dns-add=1.2.3.4", "--dns-search-add=example.com", "--dns-option-add=timeout:3", name) out, err = d.Cmd("service", "update", "--detach", "--dns-add=1.2.3.4", "--dns-search-add=example.com", "--dns-option-add=timeout:3", name)
assert.NilError(c, err, out) assert.NilError(c, err, out)
@ -1002,18 +1001,18 @@ func checkKeyIsEncrypted(d *daemon.Daemon) func(*testing.T) (interface{}, string
func checkSwarmLockedToUnlocked(c *testing.T, d *daemon.Daemon) { func checkSwarmLockedToUnlocked(c *testing.T, d *daemon.Daemon) {
// Wait for the PEM file to become unencrypted // Wait for the PEM file to become unencrypted
waitAndAssert(c, defaultReconciliationTimeout, checkKeyIsEncrypted(d), checker.Equals, false) poll.WaitOn(c, pollCheck(c, checkKeyIsEncrypted(d), checker.Equals(false)), poll.WithTimeout(defaultReconciliationTimeout))
d.RestartNode(c) d.RestartNode(c)
waitAndAssert(c, time.Second, d.CheckLocalNodeState, checker.Equals, swarm.LocalNodeStateActive) poll.WaitOn(c, pollCheck(c, d.CheckLocalNodeState, checker.Equals(swarm.LocalNodeStateActive)), poll.WithTimeout(time.Second))
} }
func checkSwarmUnlockedToLocked(c *testing.T, d *daemon.Daemon) { func checkSwarmUnlockedToLocked(c *testing.T, d *daemon.Daemon) {
// Wait for the PEM file to become encrypted // Wait for the PEM file to become encrypted
waitAndAssert(c, defaultReconciliationTimeout, checkKeyIsEncrypted(d), checker.Equals, true) poll.WaitOn(c, pollCheck(c, checkKeyIsEncrypted(d), checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
d.RestartNode(c) d.RestartNode(c)
waitAndAssert(c, time.Second, d.CheckLocalNodeState, checker.Equals, swarm.LocalNodeStateLocked) poll.WaitOn(c, pollCheck(c, d.CheckLocalNodeState, checker.Equals(swarm.LocalNodeStateLocked)), poll.WithTimeout(time.Second))
} }
func (s *DockerSwarmSuite) TestUnlockEngineAndUnlockedSwarm(c *testing.T) { func (s *DockerSwarmSuite) TestUnlockEngineAndUnlockedSwarm(c *testing.T) {
@ -1184,7 +1183,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *testing.T) {
// joined workers start off unlocked // joined workers start off unlocked
d2 := s.AddDaemon(c, true, false) d2 := s.AddDaemon(c, true, false)
d2.RestartNode(c) d2.RestartNode(c)
waitAndAssert(c, time.Second, d2.CheckLocalNodeState, checker.Equals, swarm.LocalNodeStateActive) poll.WaitOn(c, pollCheck(c, d2.CheckLocalNodeState, checker.Equals(swarm.LocalNodeStateActive)), poll.WithTimeout(time.Second))
// promote worker // promote worker
outs, err = d1.Cmd("node", "promote", d2.NodeID()) outs, err = d1.Cmd("node", "promote", d2.NodeID())
@ -1212,8 +1211,8 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *testing.T) {
// to be replaced, then the node still has the manager TLS key which is still locked // to be replaced, then the node still has the manager TLS key which is still locked
// (because we never want a manager TLS key to be on disk unencrypted if the cluster // (because we never want a manager TLS key to be on disk unencrypted if the cluster
// is set to autolock) // is set to autolock)
waitAndAssert(c, defaultReconciliationTimeout, d3.CheckControlAvailable, checker.False) poll.WaitOn(c, pollCheck(c, d3.CheckControlAvailable, checker.False()), poll.WithTimeout(defaultReconciliationTimeout))
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) { poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
certBytes, err := ioutil.ReadFile(filepath.Join(d3.Folder, "root", "swarm", "certificates", "swarm-node.crt")) certBytes, err := ioutil.ReadFile(filepath.Join(d3.Folder, "root", "swarm", "certificates", "swarm-node.crt"))
if err != nil { if err != nil {
return "", fmt.Sprintf("error: %v", err) return "", fmt.Sprintf("error: %v", err)
@ -1223,11 +1222,11 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *testing.T) {
return certs[0].Subject.OrganizationalUnit[0], "" return certs[0].Subject.OrganizationalUnit[0], ""
} }
return "", "could not get organizational unit from certificate" return "", "could not get organizational unit from certificate"
}, checker.Equals, "swarm-worker") }, checker.Equals("swarm-worker")), poll.WithTimeout(defaultReconciliationTimeout))
// by now, it should *never* be locked on restart // by now, it should *never* be locked on restart
d3.RestartNode(c) d3.RestartNode(c)
waitAndAssert(c, time.Second, d3.CheckLocalNodeState, checker.Equals, swarm.LocalNodeStateActive) poll.WaitOn(c, pollCheck(c, d3.CheckLocalNodeState, checker.Equals(swarm.LocalNodeStateActive)), poll.WithTimeout(time.Second))
} }
func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *testing.T) { func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *testing.T) {
@ -1430,7 +1429,7 @@ func (s *DockerSwarmSuite) TestExtraHosts(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// Make sure task has been deployed. // Make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// We need to get the container id. // We need to get the container id.
out, err = d.Cmd("ps", "-a", "-q", "--no-trunc") out, err = d.Cmd("ps", "-a", "-q", "--no-trunc")
@ -1480,7 +1479,7 @@ func (s *DockerSwarmSuite) TestSwarmNetworkIPAMOptions(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("network", "inspect", "--format", "{{.IPAM.Options}}", "foo") out, err = d.Cmd("network", "inspect", "--format", "{{.IPAM.Options}}", "foo")
assert.NilError(c, err, out) assert.NilError(c, err, out)
@ -1542,7 +1541,7 @@ func (s *DockerSwarmSuite) TestSwarmPublishDuplicatePorts(c *testing.T) {
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
// Total len = 4, with 2 dynamic ports and 2 non-dynamic ports // Total len = 4, with 2 dynamic ports and 2 non-dynamic ports
// Dynamic ports are likely to be 30000 and 30001 but doesn't matter // Dynamic ports are likely to be 30000 and 30001 but doesn't matter
@ -1599,7 +1598,7 @@ func (s *DockerSwarmSuite) TestSwarmReadonlyRootfs(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.ReadOnly }}", "top") out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.ReadOnly }}", "top")
assert.NilError(c, err, out) assert.NilError(c, err, out)
@ -1684,7 +1683,7 @@ func (s *DockerSwarmSuite) TestSwarmStopSignal(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.StopSignal }}", "top") out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.StopSignal }}", "top")
assert.NilError(c, err, out) assert.NilError(c, err, out)
@ -1715,7 +1714,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceLsFilterMode(c *testing.T) {
assert.Assert(c, strings.TrimSpace(out) != "") assert.Assert(c, strings.TrimSpace(out) != "")
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 2) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(2)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("service", "ls") out, err = d.Cmd("service", "ls")
assert.NilError(c, err, out) assert.NilError(c, err, out)

View file

@ -11,6 +11,7 @@ import (
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/poll"
) )
func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *testing.T) { func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *testing.T) {
@ -20,7 +21,7 @@ func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *testing.T) {
assert.NilError(c, err, out) assert.NilError(c, err, out)
// Make sure task stays pending before plugin is available // Make sure task stays pending before plugin is available
waitAndAssert(c, defaultReconciliationTimeout, d.CheckServiceTasksInStateWithError("top", swarm.TaskStatePending, "missing plugin on 1 node"), checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckServiceTasksInStateWithError("top", swarm.TaskStatePending, "missing plugin on 1 node"), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
plugin := newVolumePlugin(c, "customvolumedriver") plugin := newVolumePlugin(c, "customvolumedriver")
defer plugin.Close() defer plugin.Close()
@ -34,7 +35,7 @@ func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *testing.T) {
// this long delay. // this long delay.
// make sure task has been deployed. // make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
out, err = d.Cmd("ps", "-q") out, err = d.Cmd("ps", "-q")
assert.NilError(c, err) assert.NilError(c, err)
@ -80,7 +81,7 @@ func (s *DockerSwarmSuite) TestSwarmNetworkPluginV2(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
// wait for tasks ready // wait for tasks ready
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, 2) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(2)), poll.WithTimeout(defaultReconciliationTimeout))
// remove service // remove service
_, err = d1.Cmd("service", "rm", serviceName) _, err = d1.Cmd("service", "rm", serviceName)
@ -88,7 +89,7 @@ func (s *DockerSwarmSuite) TestSwarmNetworkPluginV2(c *testing.T) {
// wait to ensure all containers have exited before removing the plugin. Else there's a // wait to ensure all containers have exited before removing the plugin. Else there's a
// possibility of container exits erroring out due to plugins being unavailable. // possibility of container exits erroring out due to plugins being unavailable.
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, 0) poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
// disable plugin on worker // disable plugin on worker
_, err = d2.Cmd("plugin", "disable", "-f", pluginName) _, err = d2.Cmd("plugin", "disable", "-f", pluginName)
@ -101,6 +102,6 @@ func (s *DockerSwarmSuite) TestSwarmNetworkPluginV2(c *testing.T) {
_, err = d1.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--mode=global", "--network", networkName, image, "top") _, err = d1.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--mode=global", "--network", networkName, image, "top")
assert.NilError(c, err) assert.NilError(c, err)
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckRunningTaskImages, checker.DeepEquals, poll.WaitOn(c, pollCheck(c, d1.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image: 1})), poll.WithTimeout(defaultReconciliationTimeout))
map[string]int{image: 1})
} }