From ee6959addc5664a5c55765f2c721f84414ea4779 Mon Sep 17 00:00:00 2001 From: Dennis Chen Date: Tue, 27 Mar 2018 03:36:55 +0000 Subject: [PATCH 1/2] Add default pollSettings adjustment routines Add the default function per resource to override the `pollSettings` which will be re-used where it's needed. Signed-off-by: Dennis Chen --- integration/internal/swarm/service.go | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/integration/internal/swarm/service.go b/integration/internal/swarm/service.go index 79705961a1..28d367c660 100644 --- a/integration/internal/swarm/service.go +++ b/integration/internal/swarm/service.go @@ -3,7 +3,9 @@ package swarm import ( "context" "fmt" + "runtime" "testing" + "time" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" @@ -12,6 +14,7 @@ import ( "github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/internal/test/environment" "github.com/gotestyourself/gotestyourself/assert" + "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" ) @@ -20,6 +23,37 @@ const ( defaultSwarmPort = 2477 ) +// ServicePoll tweaks the pollSettings for `service` +func ServicePoll(config *poll.Settings) { + // Override the default pollSettings for `service` resource here ... + + if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { + config.Timeout = 1 * time.Minute + config.Delay = 100 * time.Millisecond + } +} + +// NetworkPoll tweaks the pollSettings for `network` +func NetworkPoll(config *poll.Settings) { + // Override the default pollSettings for `network` resource here ... + config.Timeout = 30 * time.Second + config.Delay = 100 * time.Millisecond + + if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { + config.Timeout = 50 * time.Second + } +} + +// ContainerPoll tweaks the pollSettings for `container` +func ContainerPoll(config *poll.Settings) { + // Override the default pollSettings for `container` resource here ... + + if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { + config.Timeout = 30 * time.Second + config.Delay = 100 * time.Millisecond + } +} + // NewSwarm creates a swarm daemon for testing func NewSwarm(t *testing.T, testEnv *environment.Execution) *daemon.Swarm { skip.IfCondition(t, testEnv.IsRemoteDaemon()) From b8912feeffcdfd489c9fc1212277840adac2719c Mon Sep 17 00:00:00 2001 From: Dennis Chen Date: Tue, 27 Mar 2018 04:06:46 +0000 Subject: [PATCH 2/2] Using the default PollSettings function Using the default PollSettings functions to adjust the timeout value instead of changing the value each time when needed. Signed-off-by: Dennis Chen --- integration/network/inspect_test.go | 20 ++++++------------- integration/network/service_test.go | 31 +++++------------------------ integration/service/create_test.go | 31 ++++++++++------------------- 3 files changed, 22 insertions(+), 60 deletions(-) diff --git a/integration/network/inspect_test.go b/integration/network/inspect_test.go index ad4a344c49..c27b3529d3 100644 --- a/integration/network/inspect_test.go +++ b/integration/network/inspect_test.go @@ -1,7 +1,6 @@ package network // import "github.com/docker/docker/integration/network" import ( - "runtime" "testing" "time" @@ -46,15 +45,8 @@ func TestInspectNetwork(t *testing.T) { }) assert.NilError(t, err) - pollSettings := func(config *poll.Settings) { - if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { - config.Timeout = 30 * time.Second - config.Delay = 100 * time.Millisecond - } - } - serviceID := serviceResp.ID - poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), pollSettings) + poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll) _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) assert.NilError(t, err) @@ -84,8 +76,8 @@ func TestInspectNetwork(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) + poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll) + poll.WaitOn(t, noTasks(client), swarm.ServicePoll) serviceResp, err = client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ QueryRegistry: false, @@ -93,13 +85,13 @@ func TestInspectNetwork(t *testing.T) { assert.NilError(t, err) serviceID2 := serviceResp.ID - poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), pollSettings) + poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), swarm.ServicePoll) err = client.ServiceRemove(context.Background(), serviceID2) assert.NilError(t, err) - poll.WaitOn(t, serviceIsRemoved(client, serviceID2), pollSettings) - poll.WaitOn(t, noTasks(client), pollSettings) + poll.WaitOn(t, serviceIsRemoved(client, serviceID2), swarm.ServicePoll) + poll.WaitOn(t, noTasks(client), swarm.ServicePoll) err = client.NetworkRemove(context.Background(), overlayID) assert.NilError(t, err) diff --git a/integration/network/service_test.go b/integration/network/service_test.go index ea7391180a..1b729d1157 100644 --- a/integration/network/service_test.go +++ b/integration/network/service_test.go @@ -1,7 +1,6 @@ package network // import "github.com/docker/docker/integration/network" import ( - "runtime" "testing" "time" @@ -32,18 +31,8 @@ func TestServiceWithPredefinedNetwork(t *testing.T) { }) assert.NilError(t, err) - pollSettings := func(config *poll.Settings) { - if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { - config.Timeout = 50 * time.Second - config.Delay = 100 * time.Millisecond - } else { - config.Timeout = 30 * time.Second - config.Delay = 100 * time.Millisecond - } - } - serviceID := serviceResp.ID - poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), pollSettings) + poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), swarm.ServicePoll) _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) assert.NilError(t, err) @@ -62,17 +51,7 @@ func TestServiceWithIngressNetwork(t *testing.T) { client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) assert.NilError(t, err) - pollSettings := func(config *poll.Settings) { - if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { - config.Timeout = 50 * time.Second - config.Delay = 100 * time.Millisecond - } else { - config.Timeout = 30 * time.Second - config.Delay = 100 * time.Millisecond - } - } - - poll.WaitOn(t, swarmIngressReady(client), pollSettings) + poll.WaitOn(t, swarmIngressReady(client), swarm.NetworkPoll) var instances uint64 = 1 serviceName := "TestIngressService" @@ -94,7 +73,7 @@ func TestServiceWithIngressNetwork(t *testing.T) { assert.NilError(t, err) serviceID := serviceResp.ID - poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), pollSettings) + poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), swarm.ServicePoll) _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) assert.NilError(t, err) @@ -102,8 +81,8 @@ func TestServiceWithIngressNetwork(t *testing.T) { err = client.ServiceRemove(context.Background(), serviceID) assert.NilError(t, err) - poll.WaitOn(t, serviceIsRemoved(client, serviceID), pollSettings) - poll.WaitOn(t, noServices(client), pollSettings) + poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll) + poll.WaitOn(t, noServices(client), swarm.ServicePoll) // Ensure that "ingress" is not removed or corrupted time.Sleep(10 * time.Second) diff --git a/integration/service/create_test.go b/integration/service/create_test.go index 7170bda492..9522b059ef 100644 --- a/integration/service/create_test.go +++ b/integration/service/create_test.go @@ -2,7 +2,6 @@ package service // import "github.com/docker/docker/integration/service" import ( "io/ioutil" - "runtime" "testing" "time" @@ -43,16 +42,8 @@ func TestCreateServiceMultipleTimes(t *testing.T) { }) assert.NilError(t, err) - pollSettings := func(config *poll.Settings) { - // It takes about ~25s to finish the multi services creation in this case per the pratical observation on arm64/arm platform - if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { - config.Timeout = 30 * time.Second - config.Delay = 100 * time.Millisecond - } - } - serviceID := serviceResp.ID - poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), pollSettings) + poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll) _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) assert.NilError(t, err) @@ -60,8 +51,8 @@ func TestCreateServiceMultipleTimes(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) + poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll) + poll.WaitOn(t, noTasks(client), swarm.ServicePoll) serviceResp, err = client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ QueryRegistry: false, @@ -69,13 +60,13 @@ func TestCreateServiceMultipleTimes(t *testing.T) { assert.NilError(t, err) serviceID2 := serviceResp.ID - poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), pollSettings) + poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), swarm.ServicePoll) err = client.ServiceRemove(context.Background(), serviceID2) assert.NilError(t, err) - poll.WaitOn(t, serviceIsRemoved(client, serviceID2), pollSettings) - poll.WaitOn(t, noTasks(client), pollSettings) + poll.WaitOn(t, serviceIsRemoved(client, serviceID2), swarm.ServicePoll) + poll.WaitOn(t, noTasks(client), swarm.ServicePoll) err = client.NetworkRemove(context.Background(), overlayID) assert.NilError(t, err) @@ -116,7 +107,7 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) { service, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{}) assert.NilError(t, err) - poll.WaitOn(t, serviceRunningTasksCount(client, service.ID, instances)) + poll.WaitOn(t, serviceRunningTasksCount(client, service.ID, instances), swarm.ServicePoll) resp, _, err := client.ServiceInspectWithRaw(context.Background(), service.ID, types.ServiceInspectOptions{}) assert.NilError(t, err) @@ -127,7 +118,7 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) { assert.NilError(t, err) // Make sure task has been destroyed. - poll.WaitOn(t, serviceIsRemoved(client, service.ID)) + poll.WaitOn(t, serviceIsRemoved(client, service.ID), swarm.ServicePoll) // Remove networks err = client.NetworkRemove(context.Background(), n3.ID) @@ -196,7 +187,7 @@ func TestCreateServiceSecretFileMode(t *testing.T) { }) assert.NilError(t, err) - poll.WaitOn(t, serviceRunningTasksCount(client, serviceResp.ID, instances)) + poll.WaitOn(t, serviceRunningTasksCount(client, serviceResp.ID, instances), swarm.ServicePoll) filter := filters.NewArgs() filter.Add("service", serviceResp.ID) @@ -219,8 +210,8 @@ func TestCreateServiceSecretFileMode(t *testing.T) { err = client.ServiceRemove(ctx, serviceResp.ID) assert.NilError(t, err) - poll.WaitOn(t, serviceIsRemoved(client, serviceResp.ID)) - poll.WaitOn(t, noTasks(client)) + poll.WaitOn(t, serviceIsRemoved(client, serviceResp.ID), swarm.ServicePoll) + poll.WaitOn(t, noTasks(client), swarm.ServicePoll) err = client.SecretRemove(ctx, "TestSecret") assert.NilError(t, err)