Skip to content

Commit

Permalink
Cgroup2: Cleanup procs in TestKill
Browse files Browse the repository at this point in the history
If the test fails before we get to calling manager.Kill
we'll leak the 5 sleep processes.

Signed-off-by: Danny Canter <danny@dcantah.dev>
  • Loading branch information
dcantah committed Apr 20, 2023
1 parent db40fde commit 4c05761
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cgroup2/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"os"
"os/exec"
"syscall"
"testing"
"time"

Expand Down Expand Up @@ -153,12 +154,15 @@ func TestKill(t *testing.T) {
var procs []*exec.Cmd
for i := 0; i < 5; i++ {
cmd := exec.Command("sleep", "infinity")
// Don't leak the process if we fail to join the cg,
// send sigkill after tests over.
cmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGKILL,
}
if err := cmd.Start(); err != nil {
t.Fatal(err)
}
if cmd.Process == nil {
t.Fatal("Process is nil")
}

if err := manager.AddProc(uint64(cmd.Process.Pid)); err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 4c05761

Please sign in to comment.