From 7f49ca259bfea1c08bb3019d0db3aa894ff157a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 15 Mar 2023 16:38:31 +0100 Subject: [PATCH] TestDaemonRestartKillContainers: Fix loop capture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestDaemonRestartKillContainers test was always executing the last case (`container created should not be restarted`) because the iterated variables were not copied correctly. Capture iterated values by value correctly and rename c to tc. Signed-off-by: Paweł Gronowski (cherry picked from commit fed1c96e10fc246076db43465d0f5a8b9d93d42d) Signed-off-by: Paweł Gronowski --- integration/container/restart_test.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/integration/container/restart_test.go b/integration/container/restart_test.go index 201c2d6344..3a6155003a 100644 --- a/integration/container/restart_test.go +++ b/integration/container/restart_test.go @@ -76,11 +76,10 @@ func TestDaemonRestartKillContainers(t *testing.T) { d.Stop(t) }, } { + tc := tc + liveRestoreEnabled := liveRestoreEnabled + stopDaemon := stopDaemon t.Run(fmt.Sprintf("live-restore=%v/%s/%s", liveRestoreEnabled, tc.desc, fnName), func(t *testing.T) { - c := tc - liveRestoreEnabled := liveRestoreEnabled - stopDaemon := stopDaemon - t.Parallel() d := daemon.New(t) @@ -95,11 +94,11 @@ func TestDaemonRestartKillContainers(t *testing.T) { defer d.Stop(t) ctx := context.Background() - resp, err := client.ContainerCreate(ctx, c.config, c.hostConfig, nil, nil, "") + resp, err := client.ContainerCreate(ctx, tc.config, tc.hostConfig, nil, nil, "") assert.NilError(t, err) defer client.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true}) - if c.xStart { + if tc.xStart { err = client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}) assert.NilError(t, err) } @@ -107,9 +106,9 @@ func TestDaemonRestartKillContainers(t *testing.T) { stopDaemon(t, d) d.Start(t, args...) - expected := c.xRunning + expected := tc.xRunning if liveRestoreEnabled { - expected = c.xRunningLiveRestore + expected = tc.xRunningLiveRestore } var running bool @@ -125,7 +124,7 @@ func TestDaemonRestartKillContainers(t *testing.T) { } assert.Equal(t, expected, running, "got unexpected running state, expected %v, got: %v", expected, running) - if c.xHealthCheck { + if tc.xHealthCheck { startTime := time.Now() ctxPoll, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel()