From 16e1ab0f89aeba680d15da2b91ec87b5ed091133 Mon Sep 17 00:00:00 2001 From: selansen Date: Fri, 9 Mar 2018 17:03:59 -0500 Subject: [PATCH] Fix for Flaky test TestServiceWithPredefinedNetwork TestServiceWithPredefinedNetwork test case was failing at times. To fix the issue, added new API to check for services after we clean up all services. Tested multiple times and this sould fix flaky issue. Signed-off-by: selansen (cherry picked from commit dabffd806c98ab13dbc25e57bee21c5291b9a50c) Signed-off-by: Sebastiaan van Stijn --- .../integration/network/service_test.go | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/components/engine/integration/network/service_test.go b/components/engine/integration/network/service_test.go index a9fccf9522..ea7391180a 100644 --- a/components/engine/integration/network/service_test.go +++ b/components/engine/integration/network/service_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/swarm" @@ -51,10 +50,6 @@ func TestServiceWithPredefinedNetwork(t *testing.T) { err = client.ServiceRemove(context.Background(), serviceID) assert.NilError(t, err) - - poll.WaitOn(t, serviceIsRemoved(client, serviceID), pollSettings) - poll.WaitOn(t, noTasks(client), pollSettings) - } const ingressNet = "ingress" @@ -108,7 +103,7 @@ func TestServiceWithIngressNetwork(t *testing.T) { assert.NilError(t, err) poll.WaitOn(t, serviceIsRemoved(client, serviceID), pollSettings) - poll.WaitOn(t, noTasks(client), pollSettings) + poll.WaitOn(t, noServices(client), pollSettings) // Ensure that "ingress" is not removed or corrupted time.Sleep(10 * time.Second) @@ -125,8 +120,6 @@ func TestServiceWithIngressNetwork(t *testing.T) { func serviceRunningCount(client client.ServiceAPIClient, serviceID string, instances uint64) func(log poll.LogT) poll.Result { return func(log poll.LogT) poll.Result { - filter := filters.NewArgs() - filter.Add("service", serviceID) services, err := client.ServiceList(context.Background(), types.ServiceListOptions{}) if err != nil { return poll.Error(err) @@ -160,3 +153,17 @@ func swarmIngressReady(client client.NetworkAPIClient) func(log poll.LogT) poll. return poll.Success() } } + +func noServices(client client.ServiceAPIClient) func(log poll.LogT) poll.Result { + return func(log poll.LogT) poll.Result { + services, err := client.ServiceList(context.Background(), types.ServiceListOptions{}) + switch { + case err != nil: + return poll.Error(err) + case len(services) == 0: + return poll.Success() + default: + return poll.Continue("Service count at %d waiting for 0", len(services)) + } + } +}