stop_test.go 1010 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package container // import "github.com/docker/docker/integration/container"
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/docker/docker/integration/internal/container"
  7. "gotest.tools/assert"
  8. "gotest.tools/poll"
  9. )
  10. func TestStopContainerWithRestartPolicyAlways(t *testing.T) {
  11. defer setupTest(t)()
  12. client := testEnv.APIClient()
  13. ctx := context.Background()
  14. names := []string{"verifyRestart1-" + t.Name(), "verifyRestart2-" + t.Name()}
  15. for _, name := range names {
  16. container.Run(t, ctx, client,
  17. container.WithName(name),
  18. container.WithCmd("false"),
  19. container.WithRestartPolicy("always"),
  20. )
  21. }
  22. for _, name := range names {
  23. poll.WaitOn(t, container.IsInState(ctx, client, name, "running", "restarting"), poll.WithDelay(100*time.Millisecond))
  24. }
  25. for _, name := range names {
  26. err := client.ContainerStop(ctx, name, nil)
  27. assert.NilError(t, err)
  28. }
  29. for _, name := range names {
  30. poll.WaitOn(t, container.IsStopped(ctx, client, name), poll.WithDelay(100*time.Millisecond))
  31. }
  32. }