MCPcopy
hub / github.com/containerd/containerd / TestContainerWait

Function TestContainerWait

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

Source from the content-addressed store, hash-verified

365}
366
367func TestContainerWait(t *testing.T) {
368 t.Parallel()
369
370 client, err := newClient(t, address)
371 if err != nil {
372 t.Fatal(err)
373 }
374 defer client.Close()
375
376 var (
377 image Image
378 ctx, cancel = testContext(t)
379 id = t.Name()
380 )
381 defer cancel()
382
383 image, err = client.GetImage(ctx, testImage)
384 if err != nil {
385 t.Fatal(err)
386 }
387
388 container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), longCommand))
389 if err != nil {
390 t.Fatal(err)
391 }
392 defer container.Delete(ctx)
393
394 task, err := container.NewTask(ctx, empty())
395 if err != nil {
396 t.Fatal(err)
397 }
398 defer task.Delete(ctx)
399
400 ctx2, cancle2 := context.WithCancel(ctx)
401 cancle2()
402 statusErrC, _ := task.Wait(ctx2)
403 s := <-statusErrC
404 require.Error(t, s.Error(), "expected wait error, but got nil")
405
406 statusC, err := task.Wait(ctx)
407 if err != nil {
408 t.Fatal(err)
409 }
410
411 if err := task.Start(ctx); err != nil {
412 t.Fatal(err)
413 }
414 if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
415 t.Fatal(err)
416 }
417 <-statusC
418
419 err = task.Kill(ctx, syscall.SIGTERM)
420 if err == nil {
421 t.Fatal("second call to kill should return an error")
422 }
423 if !errdefs.IsNotFound(err) {
424 t.Errorf("expected error %q but received %q", errdefs.ErrNotFound, err)

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
CloseMethod · 0.65
NameMethod · 0.65
GetImageMethod · 0.65
NewContainerMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…