MCPcopy
hub / github.com/moby/moby / TestWaitRestartedContainer

Function TestWaitRestartedContainer

integration/container/wait_test.go:182–247  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

180}
181
182func TestWaitRestartedContainer(t *testing.T) {
183 ctx := setupTest(t)
184 cli := request.NewAPIClient(t)
185
186 tests := []struct {
187 doc string
188 waitCond containertypes.WaitCondition
189 }{
190 {
191 doc: "default",
192 },
193 {
194 doc: "not-running",
195 waitCond: containertypes.WaitConditionNotRunning,
196 },
197 {
198 doc: "next-exit",
199 waitCond: containertypes.WaitConditionNextExit,
200 },
201 }
202
203 // We can't catch the SIGTERM in the Windows based busybox image
204 isWindowDaemon := testEnv.DaemonInfo.OSType == "windows"
205
206 for _, tc := range tests {
207 t.Run(tc.doc, func(t *testing.T) {
208 // TODO(vvoland): Verify why this helps for flakiness
209 // t.Parallel()
210 ctx := testutil.StartSpan(ctx, t)
211 containerID := container.Run(ctx, t, cli,
212 container.WithCmd("sh", "-c", "trap 'exit 5' SIGTERM; echo ready; while true; do sleep 0.1; done"),
213 )
214 defer cli.ContainerRemove(ctx, containerID, client.ContainerRemoveOptions{Force: true})
215 poll.WaitOn(t, logsContains(ctx, cli, containerID, "ready"))
216
217 // Container is running now, wait for exit
218 wait := cli.ContainerWait(ctx, containerID, client.ContainerWaitOptions{Condition: tc.waitCond})
219
220 timeout := 10
221 // On Windows it will always timeout, because our process won't receive SIGTERM
222 // Skip to force killing immediately
223 if isWindowDaemon {
224 timeout = 0
225 }
226
227 _, err := cli.ContainerRestart(ctx, containerID, client.ContainerRestartOptions{
228 Timeout: &timeout,
229 Signal: "SIGTERM",
230 })
231 assert.NilError(t, err)
232
233 select {
234 case err := <-wait.Error:
235 t.Fatalf("Unexpected error: %v", err)
236 case <-time.After(time.Second * 3):
237 t.Fatalf("Wait should end after restart")
238 case waitRes := <-wait.Result:
239 expectedCode := int64(5)

Callers

nothing calls this directly

Calls 12

NewAPIClientFunction · 0.92
StartSpanFunction · 0.92
RunFunction · 0.92
WithCmdFunction · 0.92
logsContainsFunction · 0.85
CheckMethod · 0.80
EqualMethod · 0.80
setupTestFunction · 0.70
RunMethod · 0.65
ContainerRemoveMethod · 0.65
ContainerWaitMethod · 0.65
ContainerRestartMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…