Skip to content

Commit abf4de4

Browse files
committed
integration: Enables Windows containerd restart test
The test sets container's Linux.SecurityContext.NamespaceOptions.Pid = NamespaceMode_CONTAINER, which will ensure that the container keeps running even if the sandbox container dies. We do not have that option on Windows. Adds additional logging in the test, so it is easier to figure out which assertion failed. Signed-off-by: Claudiu Belu <[email protected]>
1 parent d58542a commit abf4de4

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

integration/main_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os"
2525
"os/exec"
2626
"path/filepath"
27+
goruntime "runtime"
2728
"strconv"
2829
"strings"
2930
"testing"
@@ -338,7 +339,14 @@ func Randomize(str string) string {
338339

339340
// KillProcess kills the process by name. pkill is used.
340341
func KillProcess(name string) error {
341-
output, err := exec.Command("pkill", "-x", fmt.Sprintf("^%s$", name)).CombinedOutput()
342+
var command []string
343+
if goruntime.GOOS == "windows" {
344+
command = []string{"tskill", strings.TrimSuffix(name, ".exe")}
345+
} else {
346+
command = []string{"pkill", "-x", fmt.Sprintf("^%s$", name)}
347+
}
348+
349+
output, err := exec.Command(command[0], command[1:]...).CombinedOutput()
342350
if err != nil {
343351
return errors.Errorf("failed to kill %q - error: %v, output: %q", name, err, output)
344352
}

integration/restart_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ import (
3232
// Restart test must run sequentially.
3333

3434
func TestContainerdRestart(t *testing.T) {
35-
if goruntime.GOOS == "windows" {
36-
t.Skip("Skipped on Windows.")
37-
}
3835
type container struct {
3936
name string
4037
id string
@@ -75,17 +72,23 @@ func TestContainerdRestart(t *testing.T) {
7572
name: "created-container",
7673
state: runtime.ContainerState_CONTAINER_CREATED,
7774
},
78-
{
79-
name: "running-container",
80-
state: runtime.ContainerState_CONTAINER_RUNNING,
81-
},
8275
{
8376
name: "exited-container",
8477
state: runtime.ContainerState_CONTAINER_EXITED,
8578
},
8679
},
8780
},
8881
}
82+
// NOTE(claudiub): The test will set the container's Linux.SecurityContext.NamespaceOptions.Pid = NamespaceMode_CONTAINER,
83+
// and the expectation is that the container will keep running even if the sandbox container dies.
84+
// We do not have that option on Windows.
85+
if goruntime.GOOS != "windows" {
86+
sandboxes[1].containers = append(sandboxes[1].containers, container{
87+
name: "running-container",
88+
state: runtime.ContainerState_CONTAINER_RUNNING,
89+
})
90+
}
91+
8992
t.Logf("Make sure no sandbox is running before test")
9093
existingSandboxes, err := runtimeService.ListPodSandbox(&runtime.PodSandboxFilter{})
9194
require.NoError(t, err)
@@ -139,7 +142,7 @@ func TestContainerdRestart(t *testing.T) {
139142
}
140143

141144
t.Logf("Pull test images")
142-
for _, image := range []string{GetImage(BusyBox), GetImage(Alpine)} {
145+
for _, image := range []string{GetImage(BusyBox), GetImage(Pause)} {
143146
EnsureImageExists(t, image)
144147
}
145148
imagesBeforeRestart, err := imageService.ListImages(nil)
@@ -154,17 +157,19 @@ func TestContainerdRestart(t *testing.T) {
154157
assert.Len(t, loadedSandboxes, len(sandboxes))
155158
loadedContainers, err := runtimeService.ListContainers(&runtime.ContainerFilter{})
156159
require.NoError(t, err)
157-
assert.Len(t, loadedContainers, len(sandboxes)*3)
160+
assert.Len(t, loadedContainers, len(sandboxes[0].containers)+len(sandboxes[1].containers))
158161
for _, s := range sandboxes {
159162
for _, loaded := range loadedSandboxes {
160163
if s.id == loaded.Id {
164+
t.Logf("Checking sandbox state for '%s'", s.name)
161165
assert.Equal(t, s.state, loaded.State)
162166
break
163167
}
164168
}
165169
for _, c := range s.containers {
166170
for _, loaded := range loadedContainers {
167171
if c.id == loaded.Id {
172+
t.Logf("Checking container state for '%s' in sandbox '%s'", c.name, s.name)
168173
assert.Equal(t, c.state, loaded.State)
169174
break
170175
}

0 commit comments

Comments
 (0)