TestIssue9103 is used as regression case for issue 9103. The runc-fp will kill the init process so that the shim should return stopped status after container.NewTask. It's used to simulate that the runc-init might be killed by oom-kill.
(t *testing.T)
| 1526 | // status after container.NewTask. It's used to simulate that the runc-init |
| 1527 | // might be killed by oom-kill. |
| 1528 | func TestIssue9103(t *testing.T) { |
| 1529 | if f := os.Getenv("RUNC_FLAVOR"); f != "" && f != "runc" { |
| 1530 | t.Skip("test requires runc") |
| 1531 | } |
| 1532 | |
| 1533 | client, err := newClient(t, address) |
| 1534 | require.NoError(t, err) |
| 1535 | defer client.Close() |
| 1536 | |
| 1537 | var ( |
| 1538 | image Image |
| 1539 | ctx, cancel = testContext(t) |
| 1540 | id = t.Name() |
| 1541 | ) |
| 1542 | defer cancel() |
| 1543 | |
| 1544 | image, err = client.GetImage(ctx, testImage) |
| 1545 | require.NoError(t, err) |
| 1546 | |
| 1547 | for idx, tc := range []struct { |
| 1548 | desc string |
| 1549 | cntrOpts []NewContainerOpts |
| 1550 | bakingFn func(ctx context.Context, t *testing.T, task Task) |
| 1551 | expectedStatus ProcessStatus |
| 1552 | }{ |
| 1553 | { |
| 1554 | desc: "should be created status", |
| 1555 | cntrOpts: []NewContainerOpts{ |
| 1556 | WithNewSpec(oci.WithImageConfig(image), |
| 1557 | withProcessArgs("sleep", "30"), |
| 1558 | ), |
| 1559 | }, |
| 1560 | bakingFn: func(context.Context, *testing.T, Task) {}, |
| 1561 | expectedStatus: Created, |
| 1562 | }, |
| 1563 | { |
| 1564 | desc: "should be stopped status if init has been killed", |
| 1565 | cntrOpts: []NewContainerOpts{ |
| 1566 | WithNewSpec(oci.WithImageConfig(image), |
| 1567 | withProcessArgs("sleep", "30"), |
| 1568 | oci.WithAnnotations(map[string]string{ |
| 1569 | "oci.runc.failpoint.profile": "issue9103", |
| 1570 | }), |
| 1571 | ), |
| 1572 | WithRuntime(client.Runtime(), &options.Options{ |
| 1573 | BinaryName: "runc-fp", |
| 1574 | }), |
| 1575 | }, |
| 1576 | bakingFn: func(ctx context.Context, t *testing.T, task Task) { |
| 1577 | waitCh, err := task.Wait(ctx) |
| 1578 | require.NoError(t, err) |
| 1579 | |
| 1580 | select { |
| 1581 | case <-time.After(30 * time.Second): |
| 1582 | t.Fatal("timeout") |
| 1583 | case e := <-waitCh: |
| 1584 | require.NoError(t, e.Error()) |
| 1585 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…