...
1
16
17 package v2
18
19 import (
20 "fmt"
21 "os"
22 "strconv"
23 "testing"
24 )
25
26 func TestCgroupv2PidsStats(t *testing.T) {
27 checkCgroupMode(t)
28 group := "/pids-test-cg"
29 groupPath := fmt.Sprintf("%s-%d", group, os.Getpid())
30 var max int64 = 1000
31 res := Resources{
32 Pids: &Pids{
33 Max: max,
34 },
35 }
36 c, err := NewManager(defaultCgroup2Path, groupPath, &res)
37 if err != nil {
38 t.Fatal("failed to init new cgroup manager: ", err)
39 }
40 defer os.Remove(c.path)
41
42 checkFileContent(t, c.path, "pids.max", strconv.Itoa(int(max)))
43 }
44
45 func TestSystemdCgroupPidsController(t *testing.T) {
46 checkCgroupMode(t)
47 group := fmt.Sprintf("testing-pids-%d.scope", os.Getpid())
48 pid := os.Getpid()
49 res := Resources{}
50 c, err := NewSystemd("", group, pid, &res)
51 if err != nil {
52 t.Fatal("failed to init new cgroup systemd manager: ", err)
53 }
54 checkFileContent(t, c.path, "cgroup.procs", strconv.Itoa(pid))
55 }
56
View as plain text