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

Function TestEventChanCleanupOnCgroupRemoval

cgroup2/manager_test.go:79–119  ·  view source on GitHub ↗

nolint:staticcheck // Staticcheck false positives for nil pointer deference after t.Fatal

(t *testing.T)

Source from the content-addressed store, hash-verified

77
78//nolint:staticcheck // Staticcheck false positives for nil pointer deference after t.Fatal
79func TestEventChanCleanupOnCgroupRemoval(t *testing.T) {
80 checkCgroupMode(t)
81
82 cmd := exec.Command("cat")
83 stdin, err := cmd.StdinPipe()
84 require.NoError(t, err, "failed to create cat process")
85
86 err = cmd.Start()
87 require.NoError(t, err, "failed to start cat process")
88
89 proc := cmd.Process
90 require.NotNil(t, proc, "process was nil")
91
92 group := fmt.Sprintf("testing-watcher-%d.scope", proc.Pid)
93 c, err := NewSystemd("", group, proc.Pid, &Resources{})
94 require.NoError(t, err, "failed to init new cgroup manager")
95
96 evCh, errCh := c.EventChan()
97
98 // give event goroutine a chance to start
99 time.Sleep(500 * time.Millisecond)
100
101 err = stdin.Close()
102 require.NoError(t, err, "failed closing stdin")
103
104 err = cmd.Wait()
105 require.NoError(t, err, "failed waiting for cmd")
106
107 done := false
108 for !done {
109 select {
110 case <-evCh:
111 case err := <-errCh:
112 require.NoError(t, err, "unexpected error on error channel")
113 done = true
114 case <-time.After(5 * time.Second):
115 t.Fatal("Timed out")
116 }
117 }
118 goleak.VerifyNone(t)
119}
120
121func TestEventChanCleanupAfterOOMKill(t *testing.T) {
122 checkCgroupMode(t)

Callers

nothing calls this directly

Calls 3

checkCgroupModeFunction · 0.85
EventChanMethod · 0.80
NewSystemdFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…