MCPcopy
hub / github.com/moby/moby / TestExecInspectID

Method TestExecInspectID

integration-cli/docker_cli_exec_test.go:323–387  ·  view source on GitHub ↗
(c *testing.T)

Source from the content-addressed store, hash-verified

321}
322
323func (s *DockerCLIExecSuite) TestExecInspectID(c *testing.T) {
324 id := runSleepingContainer(c, "-d")
325
326 out := inspectField(c, id, "ExecIDs")
327 assert.Equal(c, out, "[]", "ExecIDs should be empty, got: %s", out)
328
329 // Start an exec, have it block waiting so we can do some checking
330 cmd := exec.Command(dockerBinary, "exec", id, "sh", "-c",
331 "while ! test -e /execid1; do sleep 1; done")
332
333 err := cmd.Start()
334 assert.NilError(c, err, "failed to start the exec cmd")
335
336 // Give the exec 10 chances/seconds to start then give up and stop the test
337 tries := 10
338 for i := range tries {
339 // Since its still running we should see exec as part of the container
340 out = strings.TrimSpace(inspectField(c, id, "ExecIDs"))
341
342 if out != "[]" && out != "<no value>" {
343 break
344 }
345 assert.Check(c, i+1 != tries, "ExecIDs still empty after 10 second")
346 time.Sleep(1 * time.Second)
347 }
348
349 // Save execID for later
350 execID, err := inspectFilter(id, "index .ExecIDs 0")
351 assert.NilError(c, err, "failed to get the exec id")
352
353 // End the exec by creating the missing file
354 err = exec.Command(dockerBinary, "exec", id, "sh", "-c", "touch /execid1").Run()
355 assert.NilError(c, err, "failed to run the 2nd exec cmd")
356
357 // Wait for 1st exec to complete
358 cmd.Wait()
359
360 // Give the exec 10 chances/seconds to stop then give up and stop the test
361 for i := range tries {
362 // Since its still running we should see exec as part of the container
363 out = strings.TrimSpace(inspectField(c, id, "ExecIDs"))
364
365 if out == "[]" {
366 break
367 }
368 assert.Check(c, i+1 != tries, "ExecIDs still empty after 10 second")
369 time.Sleep(1 * time.Second)
370 }
371
372 // But we should still be able to query the execID
373 apiClient, err := client.New(client.FromEnv)
374 assert.NilError(c, err)
375 defer apiClient.Close()
376
377 _, err = apiClient.ExecInspect(testutil.GetContext(c), execID, client.ExecInspectOptions{})
378 assert.NilError(c, err)
379
380 // Now delete the container and then an 'inspect' on the exec should

Callers

nothing calls this directly

Calls 15

GetContextFunction · 0.92
DockerCmdFunction · 0.92
runSleepingContainerFunction · 0.85
inspectFieldFunction · 0.85
inspectFilterFunction · 0.85
EqualMethod · 0.80
CheckMethod · 0.80
SleepMethod · 0.80
CombinedMethod · 0.80
StartMethod · 0.65
RunMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected