MCPcopy
hub / github.com/containerd/containerd / TestContainerPids

Function TestContainerPids

integration/client/container_test.go:589–700  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

587}
588
589func TestContainerPids(t *testing.T) {
590 t.Parallel()
591
592 client, err := newClient(t, address)
593 if err != nil {
594 t.Fatal(err)
595 }
596 defer client.Close()
597
598 var (
599 image Image
600 ctx, cancel = testContext(t)
601 id = t.Name()
602 )
603 defer cancel()
604
605 image, err = client.GetImage(ctx, testImage)
606 if err != nil {
607 t.Fatal(err)
608 }
609
610 container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), longCommand))
611 if err != nil {
612 t.Fatal(err)
613 }
614 defer container.Delete(ctx, WithSnapshotCleanup)
615
616 task, err := container.NewTask(ctx, empty())
617 if err != nil {
618 t.Fatal(err)
619 }
620 defer task.Delete(ctx)
621
622 statusC, err := task.Wait(ctx)
623 if err != nil {
624 t.Fatal(err)
625 }
626
627 if err := task.Start(ctx); err != nil {
628 t.Fatal(err)
629 }
630
631 taskPid := task.Pid()
632 if taskPid < 1 {
633 t.Errorf("invalid task pid %d", taskPid)
634 }
635
636 tryUntil := time.Now().Add(time.Second)
637 checkPids := func() bool {
638 processes, err := task.Pids(ctx)
639 if err != nil {
640 t.Fatal(err)
641 }
642
643 l := len(processes)
644 // The point of this test is to see that we successfully can get all of
645 // the pids running in the container and they match the number expected,
646 // but for Windows this concept is a bit different. Windows containers

Callers

nothing calls this directly

Calls 15

DeleteMethod · 0.95
NewTaskMethod · 0.95
PidsMethod · 0.95
WithImageConfigFunction · 0.92
newClientFunction · 0.85
testContextFunction · 0.85
WithNewSpecFunction · 0.85
emptyFunction · 0.85
FatalMethod · 0.80
LogMethod · 0.80
ResultMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…