Integration: Alter TestContainerPids for Windows

The point of this test is to see that we successfully can get all of
the pids running in the container and they match the number expected,
but for Windows this concept is a bit different. Windows containers
essentially go through the usermode boot phase of the operating system,
and have quite a few processes and system services running outside of
the "init" process you specify. Because of this, there's not a great
way to say "there should only be N processes running" like we can ensure
for Linux. So, on Windows check that we're at least greater than one.

Signed-off-by: Danny Canter <danny@dcantah.dev>
This commit is contained in:
Danny Canter 2023-06-22 19:18:04 -07:00
parent 420503072e
commit 3c1e7ffb80

View File

@ -570,30 +570,45 @@ func TestContainerPids(t *testing.T) {
if taskPid < 1 { if taskPid < 1 {
t.Errorf("invalid task pid %d", taskPid) t.Errorf("invalid task pid %d", taskPid)
} }
processes, err := task.Pids(ctx) processes, err := task.Pids(ctx)
switch runtime.GOOS { if err != nil {
case "windows": t.Fatal(err)
// TODO: This is currently not implemented on windows }
default:
if err != nil { l := len(processes)
t.Fatal(err) // The point of this test is to see that we successfully can get all of
// the pids running in the container and they match the number expected,
// but for Windows this concept is a bit different. Windows containers
// essentially go through the usermode boot phase of the operating system,
// and have quite a few processes and system services running outside of
// the "init" process you specify. Because of this, there's not a great
// way to say "there should only be N processes running" like we can ensure
// for Linux based off the process we asked to run.
//
// With all that said, on Windows lets check that we're greater than one
// ("init" + system services/procs)
if runtime.GOOS == "windows" {
if l <= 1 {
t.Errorf("expected more than one process but received %d", l)
} }
} else {
// 2 processes, 1 for sh and one for sleep // 2 processes, 1 for sh and one for sleep
if l := len(processes); l != 2 { if l != 2 {
t.Errorf("expected 2 process but received %d", l) t.Errorf("expected 2 process but received %d", l)
} }
}
var found bool var found bool
for _, p := range processes { for _, p := range processes {
if p.Pid == taskPid { if p.Pid == taskPid {
found = true found = true
break break
}
}
if !found {
t.Errorf("pid %d must be in %+v", taskPid, processes)
} }
} }
if !found {
t.Errorf("pid %d must be in %+v", taskPid, processes)
}
if err := task.Kill(ctx, syscall.SIGKILL); err != nil { if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
select { select {
case s := <-statusC: case s := <-statusC: