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>
(cherry picked from commit ac2f24e72a
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d766dac3bf
commit
9266ff7893
12 changed files with 223 additions and 224 deletions
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/internal/test/request"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
// Regression test for #9414
|
||||
|
@ -229,13 +230,13 @@ func (s *DockerSuite) TestExecStateCleanup(c *testing.T) {
|
|||
startExec(c, id, http.StatusOK)
|
||||
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")
|
||||
startExec(c, id, http.StatusBadRequest)
|
||||
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)
|
||||
_, err = os.Stat(stateDir)
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmListNodes(c *testing.T) {
|
||||
|
@ -84,16 +85,16 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *testing.T) {
|
|||
instances := 2
|
||||
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
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
|
||||
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
||||
n.Spec.Availability = swarm.NodeAvailabilityDrain
|
||||
})
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 0)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// set d2 back to active
|
||||
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
||||
|
@ -102,15 +103,15 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *testing.T) {
|
|||
|
||||
instances = 1
|
||||
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
|
||||
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
||||
|
||||
// drained node first so we don't get any old containers
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout*2, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout*2))
|
||||
|
||||
d2ContainerCount := len(d2.ActiveContainers(c))
|
||||
|
||||
|
@ -121,7 +122,7 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *testing.T) {
|
|||
|
||||
instances = 4
|
||||
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances-d2ContainerCount)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, d2ContainerCount)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(instances-d2ContainerCount)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(d2ContainerCount)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"golang.org/x/sys/unix"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
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.
|
||||
portConfig := []swarm.PortConfig{{TargetPort: 8081, PublishedPort: 8080}}
|
||||
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.
|
||||
updatedPortConfig := []swarm.PortConfig{{TargetPort: 8083, PublishedPort: 8082}}
|
||||
|
@ -65,7 +66,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesCreate(c *testing.T) {
|
|||
|
||||
instances := 2
|
||||
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)
|
||||
defer client.Close()
|
||||
|
@ -87,10 +88,10 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesCreate(c *testing.T) {
|
|||
service := d.GetService(c, id)
|
||||
instances = 5
|
||||
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)
|
||||
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) {
|
||||
|
@ -103,21 +104,21 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesMultipleAgents(c *testing.T) {
|
|||
instances := 9
|
||||
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d3.CheckActiveContainerCount, checker.GreaterThan, 0)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
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
|
||||
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
|
||||
instances = 5
|
||||
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)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, 1)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 1)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d3.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d3.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
d4 := s.AddDaemon(c, true, false)
|
||||
d5 := s.AddDaemon(c, true, false)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d4.CheckActiveContainerCount, checker.Equals, 1)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d5.CheckActiveContainerCount, checker.Equals, 1)
|
||||
poll.WaitOn(c, pollCheck(c, d4.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d5.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
// 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
|
||||
image1 := "busybox:latest"
|
||||
|
@ -166,24 +167,20 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *testing.T) {
|
|||
id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances))
|
||||
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// issue service update
|
||||
service := daemons[0].GetService(c, id)
|
||||
daemons[0].UpdateService(c, service, setImage(image2))
|
||||
|
||||
// first batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - parallelism, image2: parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 2nd batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 3nd batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image2: instances})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// Roll back to the previous version. This uses the CLI because
|
||||
// rollback used to be a client-side operation.
|
||||
|
@ -191,12 +188,11 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *testing.T) {
|
|||
assert.NilError(c, err, out)
|
||||
|
||||
// first batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 2nd batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
|
||||
|
@ -223,7 +219,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
|
|||
|
||||
checkStartingTasks := func(expected int) []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)
|
||||
startingTasks = nil
|
||||
for _, t := range tasks {
|
||||
|
@ -232,7 +228,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
|
|||
}
|
||||
}
|
||||
return startingTasks, ""
|
||||
}, checker.HasLen, expected)
|
||||
}, checker.HasLen(expected)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
return startingTasks
|
||||
}
|
||||
|
@ -245,8 +241,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
|
|||
}
|
||||
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// issue service update
|
||||
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.
|
||||
startingTasks := checkStartingTasks(parallelism)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// make it healthy
|
||||
makeTasksHealthy(startingTasks)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - parallelism, image2: parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 2nd batch
|
||||
|
||||
// The old tasks should be running, and the new ones should be starting.
|
||||
startingTasks = checkStartingTasks(parallelism)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - parallelism, image2: parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// make it healthy
|
||||
makeTasksHealthy(startingTasks)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 3nd batch
|
||||
|
||||
// The old tasks should be running, and the new ones should be starting.
|
||||
startingTasks = checkStartingTasks(1)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// make it healthy
|
||||
makeTasksHealthy(startingTasks)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image2: instances})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// Roll back to the previous version. This uses the CLI because
|
||||
// rollback is a client-side operation.
|
||||
|
@ -300,12 +289,11 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {
|
|||
assert.NilError(c, err, out)
|
||||
|
||||
// first batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 2nd batch
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
// 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
|
||||
image1 := "busybox:latest"
|
||||
|
@ -327,15 +315,14 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *testing.T) {
|
|||
id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances))
|
||||
|
||||
// wait for tasks ready
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// issue service update
|
||||
service := daemons[0].GetService(c, id)
|
||||
daemons[0].UpdateService(c, service, setImage(image2), setFailureAction(swarm.UpdateFailureActionPause), setMaxFailureRatio(0.25), setParallelism(1))
|
||||
|
||||
// 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)
|
||||
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)
|
||||
assert.NilError(c, err, out)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image1: instances})
|
||||
poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
// 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
|
||||
constraints := []string{"node.role==worker"}
|
||||
instances := 3
|
||||
id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// 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
|
||||
tasks := daemons[0].GetServiceTasks(c, id)
|
||||
for _, task := range tasks {
|
||||
|
@ -376,7 +363,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *testing.T) {
|
|||
constraints = []string{"node.role!=worker"}
|
||||
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// 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)
|
||||
// validate tasks are running on manager nodes
|
||||
for _, task := range tasks {
|
||||
|
@ -390,7 +377,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *testing.T) {
|
|||
constraints = []string{"node.role==nosuchrole"}
|
||||
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// 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
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
// 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)
|
||||
}
|
||||
// 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)
|
||||
assert.Equal(c, len(nodes), nodeCount)
|
||||
|
||||
|
@ -430,7 +417,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
|
|||
constraints := []string{"node.labels.security==high"}
|
||||
id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// 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)
|
||||
// validate all tasks are running on nodes[0]
|
||||
for _, task := range tasks {
|
||||
|
@ -443,7 +430,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
|
|||
constraints = []string{"node.labels.security!=high"}
|
||||
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// 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)
|
||||
// validate all tasks are NOT running on nodes[0]
|
||||
for _, task := range tasks {
|
||||
|
@ -455,7 +442,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
|
|||
constraints = []string{"node.labels.security==medium"}
|
||||
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
||||
// 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
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
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))
|
||||
// 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
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
tasks = daemons[0].GetServiceTasks(c, id)
|
||||
|
@ -488,7 +475,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
|
|||
}
|
||||
})
|
||||
// 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)
|
||||
for _, task := range tasks {
|
||||
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)
|
||||
}
|
||||
// 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)
|
||||
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"}}}
|
||||
id := daemons[0].CreateService(c, simpleTestService, setPlacementPrefs(prefs), setInstances(instances))
|
||||
// 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)
|
||||
// validate all tasks are running on nodes[0]
|
||||
tasksOnNode := make(map[string]int)
|
||||
|
@ -550,7 +537,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *testing.T) {
|
|||
instances := 9
|
||||
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 {
|
||||
m := make(map[string]*daemon.Daemon)
|
||||
|
@ -572,7 +559,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *testing.T) {
|
|||
_, err := containers[toRemove].Cmd("stop", toRemove)
|
||||
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()
|
||||
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
|
||||
|
||||
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()
|
||||
assert.Assert(c, len(containers2) == instances)
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
var defaultReconciliationTimeout = 30 * time.Second
|
||||
|
@ -208,13 +209,13 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *testing.T) {
|
|||
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) {
|
||||
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
|
||||
// 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
|
||||
// while waiting for the role to change to worker, and the test can
|
||||
// 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"))
|
||||
if err != nil {
|
||||
return "", fmt.Sprintf("error: %v", err)
|
||||
|
@ -232,7 +233,7 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *testing.T) {
|
|||
return certs[0].Subject.OrganizationalUnit[0], ""
|
||||
}
|
||||
return "", "could not get organizational unit from certificate"
|
||||
}, checker.Equals, "swarm-worker")
|
||||
}, checker.Equals("swarm-worker")), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// Demoting last node should fail
|
||||
node := d1.GetNode(c, d1.NodeID())
|
||||
|
@ -262,7 +263,7 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *testing.T) {
|
|||
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) {
|
||||
|
@ -348,7 +349,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) {
|
|||
|
||||
// wait for an 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.Assert(c, leader != nil)
|
||||
|
@ -361,7 +362,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) {
|
|||
|
||||
// wait 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
|
||||
|
||||
// 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)
|
||||
|
||||
// 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) {
|
||||
s.Spec.Name = "top1"
|
||||
|
@ -403,15 +404,15 @@ func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *testing.T) {
|
|||
defer cli.Close()
|
||||
|
||||
// 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{})
|
||||
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)
|
||||
|
||||
// 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) {
|
||||
s.Spec.Name = "top3"
|
||||
|
@ -428,12 +429,12 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaveRemovesContainer(c *testing.T) {
|
|||
assert.NilError(c, err, 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.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")
|
||||
assert.NilError(c, err, id2)
|
||||
|
@ -462,7 +463,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaveOnPendingJoin(c *testing.T) {
|
|||
|
||||
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")
|
||||
assert.NilError(c, err, id2)
|
||||
|
@ -480,7 +481,7 @@ func (s *DockerSwarmSuite) TestAPISwarmRestoreOnPendingJoin(c *testing.T) {
|
|||
})
|
||||
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)
|
||||
|
||||
|
@ -521,11 +522,11 @@ func (s *DockerSwarmSuite) TestAPISwarmScaleNoRollingUpdate(c *testing.T) {
|
|||
instances := 2
|
||||
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)
|
||||
instances = 4
|
||||
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)
|
||||
|
||||
loop0:
|
||||
|
@ -563,14 +564,14 @@ func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *testing.T) {
|
|||
|
||||
instances := 2
|
||||
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
|
||||
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
||||
n.Spec.Availability = swarm.NodeAvailabilityDrain
|
||||
})
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 0)
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckActiveContainerCount, checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, d2.CheckActiveContainerCount, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
d2.Stop(c)
|
||||
|
||||
|
@ -579,7 +580,7 @@ func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *testing.T) {
|
|||
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)
|
||||
info := d3.SwarmInfo(c)
|
||||
|
@ -589,7 +590,7 @@ func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *testing.T) {
|
|||
instances = 4
|
||||
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) {
|
||||
|
@ -743,7 +744,7 @@ func checkClusterHealth(c *testing.T, cl []*daemon.Daemon, managerCount, workerC
|
|||
info = daemonInfo.Swarm
|
||||
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 {
|
||||
totalWCount++
|
||||
continue
|
||||
|
@ -762,7 +763,7 @@ func checkClusterHealth(c *testing.T, cl []*daemon.Daemon, managerCount, workerC
|
|||
n = *nn
|
||||
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) {
|
||||
if n.Spec.Availability == swarm.NodeAvailabilityActive {
|
||||
|
@ -772,7 +773,7 @@ func checkClusterHealth(c *testing.T, cl []*daemon.Daemon, managerCount, workerC
|
|||
n = *nn
|
||||
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 {
|
||||
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
|
||||
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)
|
||||
instances = 5
|
||||
|
@ -873,7 +874,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateWithName(c *testing.T) {
|
|||
defer cli.Close()
|
||||
_, err := cli.ServiceUpdate(context.Background(), service.Spec.Name, service.Version, service.Spec, types.ServiceUpdateOptions{})
|
||||
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
|
||||
|
@ -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)
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ import (
|
|||
"golang.org/x/sys/unix"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
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
|
||||
// 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))
|
||||
return result.ExitCode, ""
|
||||
}, checker.Equals, 0)
|
||||
}, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// restart the daemon
|
||||
s.d.Start(t, "--live-restore")
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
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}}")
|
||||
assert.NilError(c, err)
|
||||
return out, ""
|
||||
}, checker.Contains, s)
|
||||
}, checker.Contains(s)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
||||
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}}")
|
||||
assert.NilError(c, err)
|
||||
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")
|
||||
assert.NilError(c, err)
|
||||
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
|
||||
pruneNetworkAndVerify(c, d, []string{"n1", "n3"}, []string{"n2", "n4"})
|
||||
|
@ -74,7 +77,7 @@ func (s *DockerSwarmSuite) TestPruneNetwork(c *testing.T) {
|
|||
assert.NilError(c, err)
|
||||
_, err = d.Cmd("service", "rm", serviceName)
|
||||
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"})
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/docker/docker/integration-cli/checker"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
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
|
||||
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)
|
||||
assert.NilError(c, waitRun(cleanedContainerID))
|
||||
|
||||
// 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.
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) {
|
||||
|
@ -23,18 +24,18 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) {
|
|||
id := strings.TrimSpace(out)
|
||||
|
||||
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)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
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 {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// check container mount config
|
||||
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))
|
||||
|
||||
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)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
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 {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
for testName, testTarget := range testPaths {
|
||||
path := testTarget
|
||||
|
@ -187,18 +188,18 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *testing
|
|||
assert.Equal(c, len(refs), 2)
|
||||
|
||||
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)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
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 {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
for _, target := range []string{"target1", "target2"} {
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -284,18 +285,18 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *testi
|
|||
assert.Equal(c, len(refs), len(testPaths))
|
||||
|
||||
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)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
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 {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
for testName, testTarget := range testPaths {
|
||||
path := testTarget
|
||||
|
@ -334,18 +335,18 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *testing
|
|||
assert.Equal(c, len(refs), 2)
|
||||
|
||||
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)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
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 {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
for _, target := range []string{"target1", "target2"} {
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -366,18 +367,18 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *testing.T) {
|
|||
id := strings.TrimSpace(out)
|
||||
|
||||
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)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
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 {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// check container mount config
|
||||
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)
|
||||
|
||||
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)
|
||||
return len(tasks) > 0, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
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 {
|
||||
task = d.GetTask(c, task.ID)
|
||||
}
|
||||
return task.NodeID != "" && task.Status.ContainerStatus != nil, ""
|
||||
}, checker.Equals, true)
|
||||
}, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// check container alias config
|
||||
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .NetworkSettings.Networks.test_swarm_br.Aliases}}", task.Status.ContainerStatus.ContainerID)
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
// 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)
|
||||
|
||||
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)
|
||||
return tasks, ""
|
||||
}, checker.HasLen, 1)
|
||||
}, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
task := tasks[0]
|
||||
|
||||
// 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)
|
||||
return task.Status.State, ""
|
||||
}, checker.Equals, swarm.TaskStateRunning)
|
||||
}, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
containerID := task.Status.ContainerStatus.ContainerID
|
||||
|
||||
// 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)
|
||||
return strings.TrimSpace(out), ""
|
||||
}, checker.Equals, "healthy")
|
||||
}, checker.Equals("healthy")), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// make it fail
|
||||
d.Cmd("exec", containerID, "rm", "/status")
|
||||
// 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)
|
||||
return strings.TrimSpace(out), ""
|
||||
}, checker.Equals, "unhealthy")
|
||||
}, checker.Equals("unhealthy")), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// 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)
|
||||
return task.Status.State, ""
|
||||
}, checker.Equals, swarm.TaskStateFailed)
|
||||
}, checker.Equals(swarm.TaskStateFailed)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
if !strings.Contains(task.Status.Err, container.ErrContainerUnhealthy.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)
|
||||
|
||||
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)
|
||||
return tasks, ""
|
||||
}, checker.HasLen, 1)
|
||||
}, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
task := tasks[0]
|
||||
|
||||
// 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)
|
||||
return task.Status.State, ""
|
||||
}, checker.Equals, swarm.TaskStateStarting)
|
||||
}, checker.Equals(swarm.TaskStateStarting)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
containerID := task.Status.ContainerStatus.ContainerID
|
||||
|
||||
// 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)
|
||||
failingStreak, _ := strconv.Atoi(strings.TrimSpace(out))
|
||||
return failingStreak, ""
|
||||
}, checker.GreaterThan, 0)
|
||||
}, checker.GreaterThan(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// task should be blocked at starting status
|
||||
task = d.GetTask(c, task.ID)
|
||||
|
@ -130,8 +132,9 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *testing.T) {
|
|||
d.Cmd("exec", containerID, "touch", "/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)
|
||||
return task.Status.State, ""
|
||||
}, checker.Equals, swarm.TaskStateRunning)
|
||||
}, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/icmd"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
type logMessage struct {
|
||||
|
@ -39,9 +40,8 @@ func (s *DockerSwarmSuite) TestServiceLogs(c *testing.T) {
|
|||
}
|
||||
|
||||
// make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout,
|
||||
d.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{"busybox:latest": len(services)})
|
||||
poll.WaitOn(c, pollCheck(c,
|
||||
d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{"busybox:latest": len(services)})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
for name, message := range services {
|
||||
out, err := d.Cmd("service", "logs", name)
|
||||
|
@ -80,9 +80,9 @@ func (s *DockerSwarmSuite) TestServiceLogsCompleteness(c *testing.T) {
|
|||
assert.Assert(c, strings.TrimSpace(out) != "")
|
||||
|
||||
// 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
|
||||
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)
|
||||
assert.NilError(c, err)
|
||||
|
@ -107,8 +107,8 @@ func (s *DockerSwarmSuite) TestServiceLogsTail(c *testing.T) {
|
|||
assert.Assert(c, strings.TrimSpace(out) != "")
|
||||
|
||||
// make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 6)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(6)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
out, err = d.Cmd("service", "logs", "--tail=2", name)
|
||||
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")
|
||||
assert.NilError(c, err)
|
||||
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
|
||||
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)
|
||||
assert.NilError(c, err)
|
||||
|
@ -165,7 +165,7 @@ func (s *DockerSwarmSuite) TestServiceLogsFollow(c *testing.T) {
|
|||
assert.Assert(c, strings.TrimSpace(out) != "")
|
||||
|
||||
// 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}
|
||||
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})
|
||||
|
||||
// make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, replicas)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, countLogLines(d, name), checker.Equals, 6*replicas)
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount, checker.Equals(replicas)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
poll.WaitOn(c, pollCheck(c, countLogLines(d, name), checker.Equals(6*replicas)), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// get the task ids
|
||||
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})
|
||||
|
||||
// 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
|
||||
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)
|
||||
result = icmd.RunCmd(cmd)
|
||||
|
@ -315,9 +315,9 @@ func (s *DockerSwarmSuite) TestServiceLogsNoHangDeletedContainer(c *testing.T) {
|
|||
assert.Assert(c, id != "")
|
||||
|
||||
// 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
|
||||
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
|
||||
result = icmd.RunCmd(d.Command("ps", "-q"))
|
||||
|
@ -368,9 +368,9 @@ func (s *DockerSwarmSuite) TestServiceLogsDetails(c *testing.T) {
|
|||
assert.Assert(c, id != "")
|
||||
|
||||
// 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
|
||||
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
|
||||
// call service logs with details. set raw to skip pretty printing
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"gotest.tools/assert"
|
||||
"gotest.tools/fs"
|
||||
"gotest.tools/icmd"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func (s *DockerSwarmSuite) TestSwarmUpdate(c *testing.T) {
|
||||
|
@ -176,7 +177,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTemplatingHostname(c *testing.T) {
|
|||
assert.NilError(c, err, out)
|
||||
|
||||
// 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)
|
||||
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) != "")
|
||||
|
||||
// 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"
|
||||
|
||||
|
@ -303,7 +304,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceWithGroup(c *testing.T) {
|
|||
assert.Assert(c, strings.TrimSpace(out) != "")
|
||||
|
||||
// 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")
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -388,7 +389,7 @@ func (s *DockerSwarmSuite) TestSwarmContainerAttachByNetworkId(c *testing.T) {
|
|||
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) {
|
||||
|
@ -550,7 +551,7 @@ func (s *DockerSwarmSuite) TestSwarmTaskListFilter(c *testing.T) {
|
|||
}
|
||||
|
||||
// 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)
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -572,7 +573,7 @@ func (s *DockerSwarmSuite) TestSwarmTaskListFilter(c *testing.T) {
|
|||
assert.NilError(c, err, 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"
|
||||
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) != "")
|
||||
|
||||
// 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
|
||||
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)
|
||||
|
||||
// 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.
|
||||
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)
|
||||
assert.NilError(c, err, out)
|
||||
// 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
|
||||
expectedOutput = "TTY"
|
||||
|
@ -859,7 +860,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *testing.T) {
|
|||
assert.NilError(c, err, out)
|
||||
|
||||
// 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.
|
||||
out, err = d.Cmd("ps", "-q", "--no-trunc")
|
||||
|
@ -880,7 +881,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTYUpdate(c *testing.T) {
|
|||
assert.NilError(c, err, out)
|
||||
|
||||
// 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)
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -915,22 +916,20 @@ func (s *DockerSwarmSuite) TestSwarmServiceNetworkUpdate(c *testing.T) {
|
|||
result.Assert(c, icmd.Success)
|
||||
|
||||
// Make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskNetworks, checker.DeepEquals,
|
||||
map[string]int{fooNetwork: 1, barNetwork: 1})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskNetworks, checker.DeepEquals(map[string]int{fooNetwork: 1, barNetwork: 1})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// Remove a network
|
||||
result = icmd.RunCmd(d.Command("service", "update", "--detach", "--network-rm", "foo", name))
|
||||
result.Assert(c, icmd.Success)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskNetworks, checker.DeepEquals,
|
||||
map[string]int{barNetwork: 1})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskNetworks, checker.DeepEquals(map[string]int{barNetwork: 1})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
// Add a network
|
||||
result = icmd.RunCmd(d.Command("service", "update", "--detach", "--network-add", "baz", name))
|
||||
result.Assert(c, icmd.Success)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.CheckRunningTaskNetworks, checker.DeepEquals,
|
||||
map[string]int{barNetwork: 1, bazNetwork: 1})
|
||||
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskNetworks, checker.DeepEquals(map[string]int{barNetwork: 1, bazNetwork: 1})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestDNSConfig(c *testing.T) {
|
||||
|
@ -942,7 +941,7 @@ func (s *DockerSwarmSuite) TestDNSConfig(c *testing.T) {
|
|||
assert.NilError(c, err, out)
|
||||
|
||||
// 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.
|
||||
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)
|
||||
|
||||
// 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)
|
||||
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) {
|
||||
// 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)
|
||||
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) {
|
||||
// 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)
|
||||
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) {
|
||||
|
@ -1184,7 +1183,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *testing.T) {
|
|||
// joined workers start off unlocked
|
||||
d2 := s.AddDaemon(c, true, false)
|
||||
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
|
||||
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
|
||||
// (because we never want a manager TLS key to be on disk unencrypted if the cluster
|
||||
// is set to autolock)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d3.CheckControlAvailable, checker.False)
|
||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, string) {
|
||||
poll.WaitOn(c, pollCheck(c, d3.CheckControlAvailable, checker.False()), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
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"))
|
||||
if err != nil {
|
||||
return "", fmt.Sprintf("error: %v", err)
|
||||
|
@ -1223,11 +1222,11 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *testing.T) {
|
|||
return certs[0].Subject.OrganizationalUnit[0], ""
|
||||
}
|
||||
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
|
||||
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) {
|
||||
|
@ -1430,7 +1429,7 @@ func (s *DockerSwarmSuite) TestExtraHosts(c *testing.T) {
|
|||
assert.NilError(c, err, out)
|
||||
|
||||
// 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.
|
||||
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)
|
||||
|
||||
// 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")
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -1542,7 +1541,7 @@ func (s *DockerSwarmSuite) TestSwarmPublishDuplicatePorts(c *testing.T) {
|
|||
id := strings.TrimSpace(out)
|
||||
|
||||
// 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
|
||||
// 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)
|
||||
|
||||
// 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")
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -1684,7 +1683,7 @@ func (s *DockerSwarmSuite) TestSwarmStopSignal(c *testing.T) {
|
|||
assert.NilError(c, err, out)
|
||||
|
||||
// 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")
|
||||
assert.NilError(c, err, out)
|
||||
|
@ -1715,7 +1714,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceLsFilterMode(c *testing.T) {
|
|||
assert.Assert(c, strings.TrimSpace(out) != "")
|
||||
|
||||
// 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")
|
||||
assert.NilError(c, err, out)
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/poll"
|
||||
)
|
||||
|
||||
func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *testing.T) {
|
||||
|
@ -20,7 +21,7 @@ func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *testing.T) {
|
|||
assert.NilError(c, err, out)
|
||||
|
||||
// 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")
|
||||
defer plugin.Close()
|
||||
|
@ -34,7 +35,7 @@ func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *testing.T) {
|
|||
// this long delay.
|
||||
|
||||
// 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")
|
||||
assert.NilError(c, err)
|
||||
|
@ -80,7 +81,7 @@ func (s *DockerSwarmSuite) TestSwarmNetworkPluginV2(c *testing.T) {
|
|||
assert.NilError(c, err)
|
||||
|
||||
// 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
|
||||
_, 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
|
||||
// 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
|
||||
_, 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")
|
||||
assert.NilError(c, err)
|
||||
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckRunningTaskImages, checker.DeepEquals,
|
||||
map[string]int{image: 1})
|
||||
poll.WaitOn(c, pollCheck(c, d1.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image: 1})), poll.WithTimeout(defaultReconciliationTimeout))
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue