...
1
16
17 package v2
18
19 import (
20 "fmt"
21 "os"
22 "testing"
23
24 "github.com/stretchr/testify/assert"
25 )
26
27 func TestCgroupv2MemoryStats(t *testing.T) {
28 checkCgroupMode(t)
29 group := "/memory-test-cg"
30 groupPath := fmt.Sprintf("%s-%d", group, os.Getpid())
31 res := Resources{
32 Memory: &Memory{
33 Max: pointerInt64(629145600),
34 Swap: pointerInt64(314572800),
35 High: pointerInt64(524288000),
36 },
37 }
38 c, err := NewManager(defaultCgroup2Path, groupPath, &res)
39 if err != nil {
40 t.Fatal("failed to init new cgroup manager: ", err)
41 }
42 defer os.Remove(c.path)
43 stats, err := c.Stat()
44 if err != nil {
45 t.Fatal("failed to get cgroups stats: ", err)
46 }
47
48 assert.Equal(t, uint64(314572800), stats.Memory.SwapLimit)
49 assert.Equal(t, uint64(629145600), stats.Memory.UsageLimit)
50 checkFileContent(t, c.path, "memory.swap.max", "314572800")
51 checkFileContent(t, c.path, "memory.max", "629145600")
52 }
53
54 func TestSystemdCgroupMemoryController(t *testing.T) {
55 checkCgroupMode(t)
56 group := fmt.Sprintf("testing-memory-%d.scope", os.Getpid())
57 res := Resources{
58 Memory: &Memory{
59 Min: pointerInt64(16384),
60 Max: pointerInt64(629145600),
61 },
62 }
63 c, err := NewSystemd("", group, os.Getpid(), &res)
64 if err != nil {
65 t.Fatal("failed to init new cgroup systemd manager: ", err)
66 }
67 checkFileContent(t, c.path, "memory.min", "16384")
68 checkFileContent(t, c.path, "memory.max", "629145600")
69 }
70
View as plain text