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

Function TestMoveTo

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

Source from the content-addressed store, hash-verified

293}
294
295func TestMoveTo(t *testing.T) {
296 checkCgroupMode(t)
297
298 src, err := NewManager(defaultCgroup2Path, "/test-moveto-src", ToResources(&specs.LinuxResources{}))
299 require.NoError(t, err)
300 t.Cleanup(func() {
301 _ = src.Kill()
302 _ = src.Delete()
303 })
304
305 cmd := exec.Command("sleep", "infinity")
306 // Don't leak the process if we fail to join the cg,
307 // send sigkill after tests over.
308 cmd.SysProcAttr = &syscall.SysProcAttr{
309 Pdeathsig: syscall.SIGKILL,
310 }
311 err = cmd.Start()
312 require.NoError(t, err)
313
314 proc := cmd.Process.Pid
315 err = src.AddProc(uint64(proc))
316 require.NoError(t, err)
317
318 destination, err := NewManager(defaultCgroup2Path, "/test-moveto-dest", ToResources(&specs.LinuxResources{}))
319 require.NoError(t, err)
320 t.Cleanup(func() {
321 _ = destination.Kill()
322 _ = destination.Delete()
323 })
324
325 err = src.MoveTo(destination)
326 require.NoError(t, err)
327
328 desProcs, err := destination.Procs(true)
329 require.NoError(t, err)
330
331 desMap := make(map[int]bool)
332 for _, p := range desProcs {
333 desMap[int(p)] = true
334 }
335 if !desMap[proc] {
336 t.Fatalf("process %v not in destination cgroup", proc)
337 }
338}
339
340func TestCgroupType(t *testing.T) {
341 checkCgroupMode(t)

Callers

nothing calls this directly

Calls 8

KillMethod · 0.95
DeleteMethod · 0.95
AddProcMethod · 0.95
MoveToMethod · 0.95
ProcsMethod · 0.95
checkCgroupModeFunction · 0.85
NewManagerFunction · 0.85
ToResourcesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…