From 68e266ee3aaf1b44e990f5ad856a71abaeb2b4ec Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Tue, 15 Jan 2019 03:54:52 +0000 Subject: [PATCH] Replace waitAndAssert in config_test.go with poll.WaitOn This fix replaces waitAndAssert in config_test.go with poll.WaitOn so that the testing is consistent with all other tests in integration. Also, config_test.go uses to wait and sleep for 2 * (1 minutes) to get the task info. This fix combined those two sleep and wait for 1 mins. Think 1 min is enough for config test. Signed-off-by: Yong Tang --- integration/config/config_test.go | 37 +++++++++++++------------------ 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/integration/config/config_test.go b/integration/config/config_test.go index 480232d196..5cadf09dac 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -16,6 +16,7 @@ import ( "github.com/docker/docker/pkg/stdcopy" "gotest.tools/assert" is "gotest.tools/assert/cmp" + "gotest.tools/poll" "gotest.tools/skip" ) @@ -268,18 +269,26 @@ func TestTemplatedConfig(t *testing.T) { ) var tasks []swarmtypes.Task - waitAndAssert(t, 60*time.Second, func(t *testing.T) bool { + getRunningTasks := func(log poll.LogT) poll.Result { tasks = swarm.GetRunningTasks(t, client, serviceID) - return len(tasks) > 0 - }) + if len(tasks) > 0 { + return poll.Success() + } + return poll.Continue("task still waiting") + } + poll.WaitOn(t, getRunningTasks, swarm.ServicePoll, poll.WithTimeout(1*time.Minute)) task := tasks[0] - waitAndAssert(t, 60*time.Second, func(t *testing.T) bool { + getTask := func(log poll.LogT) poll.Result { if task.NodeID == "" || (task.Status.ContainerStatus == nil || task.Status.ContainerStatus.ContainerID == "") { task, _, _ = client.TaskInspectWithRaw(context.Background(), task.ID) } - return task.NodeID != "" && task.Status.ContainerStatus != nil && task.Status.ContainerStatus.ContainerID != "" - }) + if task.NodeID != "" && task.Status.ContainerStatus != nil && task.Status.ContainerStatus.ContainerID != "" { + return poll.Success() + } + return poll.Continue("task still waiting") + } + poll.WaitOn(t, getTask, swarm.ServicePoll, poll.WithTimeout(1*time.Minute)) attach := swarm.ExecTask(t, d, task, types.ExecConfig{ Cmd: []string{"/bin/cat", "/" + templatedConfigName}, @@ -307,22 +316,6 @@ func assertAttachedStream(t *testing.T, attach types.HijackedResponse, expect st assert.Check(t, is.Contains(buf.String(), expect)) } -func waitAndAssert(t *testing.T, timeout time.Duration, f func(*testing.T) bool) { - t.Helper() - after := time.After(timeout) - for { - select { - case <-after: - t.Fatalf("timed out waiting for condition") - default: - } - if f(t) { - return - } - time.Sleep(100 * time.Millisecond) - } -} - func TestConfigInspect(t *testing.T) { skip.If(t, testEnv.DaemonInfo.OSType == "windows")