MCPcopy
hub / github.com/containerd/containerd / TestWaitStoppedTask

Function TestWaitStoppedTask

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

Source from the content-addressed store, hash-verified

1054}
1055
1056func TestWaitStoppedTask(t *testing.T) {
1057 t.Parallel()
1058
1059 client, err := newClient(t, address)
1060 if err != nil {
1061 t.Fatal(err)
1062 }
1063 defer client.Close()
1064
1065 var (
1066 image Image
1067 ctx, cancel = testContext(t)
1068 id = t.Name()
1069 )
1070 defer cancel()
1071
1072 image, err = client.GetImage(ctx, testImage)
1073 if err != nil {
1074 t.Fatal(err)
1075 }
1076
1077 container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), withExitStatus(7)))
1078 if err != nil {
1079 t.Fatal(err)
1080 }
1081 defer container.Delete(ctx, WithSnapshotCleanup)
1082
1083 task, err := container.NewTask(ctx, empty())
1084 if err != nil {
1085 t.Fatal(err)
1086 }
1087 defer task.Delete(ctx)
1088
1089 statusC, err := task.Wait(ctx)
1090 if err != nil {
1091 t.Fatal(err)
1092 }
1093
1094 if runtime.GOOS != "windows" {
1095 // Getting the pid is not currently implemented on windows
1096 if pid := task.Pid(); pid < 1 {
1097 t.Errorf("invalid task pid %d", pid)
1098 }
1099 }
1100 if err := task.Start(ctx); err != nil {
1101 t.Error(err)
1102 task.Delete(ctx)
1103 return
1104 }
1105
1106 // wait for the task to stop then call wait again
1107 <-statusC
1108 statusC, err = task.Wait(ctx)
1109 if err != nil {
1110 t.Fatal(err)
1111 }
1112 status := <-statusC
1113 code, _, err := status.Result()

Callers

nothing calls this directly

Calls 15

DeleteMethod · 0.95
NewTaskMethod · 0.95
WithImageConfigFunction · 0.92
newClientFunction · 0.85
testContextFunction · 0.85
WithNewSpecFunction · 0.85
emptyFunction · 0.85
FatalMethod · 0.80
ResultMethod · 0.80
withExitStatusFunction · 0.70
CloseMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…