integration: Corrected service update tests logic
Tests which will re-deploy containers uses function serviceIsUpdated() to
make sure that service update really reached state UpdateStateCompleted.
Tests which will not re-deploy container uses function
serviceSpecIsUpdated to make sure that service version is increased.
@@ -32,7 +32,7 @@ func TestServiceUpdateLabel(t *testing.T) {
service.Spec.Labels["foo"] = "bar"
_, err := cli.ServiceUpdate(ctx, serviceID, service.Version, service.Spec, types.ServiceUpdateOptions{})
assert.NilError(t, err)
- poll.WaitOn(t, serviceIsUpdated(cli, serviceID), swarm.ServicePoll)
+ poll.WaitOn(t, serviceSpecIsUpdated(cli, serviceID, service.Version.Index), swarm.ServicePoll)
service = getService(t, cli, serviceID)
assert.Check(t, is.DeepEqual(service.Spec.Labels, map[string]string{"foo": "bar"}))
@@ -40,21 +40,21 @@ func TestServiceUpdateLabel(t *testing.T) {
service.Spec.Labels["foo2"] = "bar"
_, err = cli.ServiceUpdate(ctx, serviceID, service.Version, service.Spec, types.ServiceUpdateOptions{})
assert.NilError(t, err)
- poll.WaitOn(t, serviceIsUpdated(cli, serviceID), swarm.ServicePoll)
+ poll.WaitOn(t, serviceSpecIsUpdated(cli, serviceID, service.Version.Index), swarm.ServicePoll)
service = getService(t, cli, serviceID)
assert.Check(t, is.DeepEqual(service.Spec.Labels, map[string]string{"foo": "bar", "foo2": "bar"}))
delete(service.Spec.Labels, "foo2")
_, err = cli.ServiceUpdate(ctx, serviceID, service.Version, service.Spec, types.ServiceUpdateOptions{})
assert.NilError(t, err)
- poll.WaitOn(t, serviceIsUpdated(cli, serviceID), swarm.ServicePoll)
+ poll.WaitOn(t, serviceSpecIsUpdated(cli, serviceID, service.Version.Index), swarm.ServicePoll)
service = getService(t, cli, serviceID)
assert.Check(t, is.DeepEqual(service.Spec.Labels, map[string]string{"foo": "bar"}))
delete(service.Spec.Labels, "foo")
_, err = cli.ServiceUpdate(ctx, serviceID, service.Version, service.Spec, types.ServiceUpdateOptions{})
assert.NilError(t, err)
- poll.WaitOn(t, serviceIsUpdated(cli, serviceID), swarm.ServicePoll)
+ poll.WaitOn(t, serviceSpecIsUpdated(cli, serviceID, service.Version.Index), swarm.ServicePoll)
service = getService(t, cli, serviceID)
assert.Check(t, is.DeepEqual(service.Spec.Labels, map[string]string{}))
@@ -62,7 +62,7 @@ func TestServiceUpdateLabel(t *testing.T) {
service.Spec.Labels["foo"] = "bar"
_, err = cli.ServiceUpdate(ctx, serviceID, service.Version, service.Spec, types.ServiceUpdateOptions{})
assert.NilError(t, err)
- poll.WaitOn(t, serviceIsUpdated(cli, serviceID), swarm.ServicePoll)
+ poll.WaitOn(t, serviceSpecIsUpdated(cli, serviceID, service.Version.Index), swarm.ServicePoll)
service = getService(t, cli, serviceID)
assert.Check(t, is.DeepEqual(service.Spec.Labels, map[string]string{"foo": "bar"}))
@@ -217,3 +217,17 @@ func serviceIsUpdated(client client.ServiceAPIClient, serviceID string) func(log
}
}
}
+
+func serviceSpecIsUpdated(client client.ServiceAPIClient, serviceID string, serviceOldVersion uint64) func(log poll.LogT) poll.Result {
+ return func(log poll.LogT) poll.Result {
+ service, _, err := client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
+ switch {
+ case err != nil:
+ return poll.Error(err)
+ case service.Version.Index > serviceOldVersion:
+ return poll.Success()
+ default:
+ return poll.Continue("waiting for service %s to be updated", serviceID)
+ }
+ }
+}
