浏览代码

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 <elango.siva@docker.com>
selansen 7 年之前
父节点
当前提交
dabffd806c
共有 1 个文件被更改,包括 15 次插入8 次删除
  1. 15 8
      integration/network/service_test.go

+ 15 - 8
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))
+		}
+	}
+}