MCPcopy Create free account
hub / github.com/containerd/cgroups / TestEventChanCleanupAfterOOMKill

Function TestEventChanCleanupAfterOOMKill

cgroup2/manager_test.go:121–175  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

119}
120
121func TestEventChanCleanupAfterOOMKill(t *testing.T) {
122 checkCgroupMode(t)
123
124 groupPath := fmt.Sprintf("/testing-oom-watcher-%d", time.Now().UnixNano())
125 c, err := NewManager(defaultCgroup2Path, groupPath,
126 &Resources{
127 Memory: &Memory{
128 Max: toPtr(int64(15 * 1024 * 1024)), // 15MB
129 Swap: toPtr(int64(15 * 1024 * 1024)), // 15MB
130 },
131 },
132 )
133 require.NoError(t, err, "failed to init new cgroup manager")
134 defer func() {
135 require.NoError(t, c.Delete())
136 }()
137
138 cgroupFD, err := os.Open(c.path)
139 require.NoError(t, err, "failed to open cgroup path")
140 defer cgroupFD.Close()
141
142 evCh, errCh := c.EventChan()
143
144 cmd := exec.Command("dd", "if=/dev/zero", "of=/dev/null", "bs=64M")
145 cmd.SysProcAttr = &syscall.SysProcAttr{
146 Pdeathsig: syscall.SIGKILL,
147 UseCgroupFD: true,
148 CgroupFD: int(cgroupFD.Fd()),
149 }
150
151 err = cmd.Start()
152 require.NoError(t, err, "failed to start dd process")
153
154 err = cmd.Wait()
155 require.Error(t, err)
156
157 for ev := range evCh {
158 t.Logf("Received memory event: %+v", ev)
159 if ev.OOMKill > 0 {
160 break
161 }
162 }
163
164 done := false
165 for !done {
166 select {
167 case err := <-errCh:
168 require.NoError(t, err, "unexpected error on error channel")
169 done = true
170 case <-time.After(5 * time.Second):
171 t.Fatal("Timed out")
172 }
173 }
174 goleak.VerifyNone(t)
175}
176
177func TestSystemdFullPath(t *testing.T) {
178 tests := []struct {

Callers

nothing calls this directly

Calls 5

DeleteMethod · 0.95
EventChanMethod · 0.95
checkCgroupModeFunction · 0.85
NewManagerFunction · 0.85
toPtrFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…