stop_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package container // import "github.com/docker/docker/integration/container"
  2. import (
  3. "testing"
  4. "time"
  5. containertypes "github.com/docker/docker/api/types/container"
  6. "github.com/docker/docker/integration/internal/container"
  7. "gotest.tools/v3/assert"
  8. "gotest.tools/v3/poll"
  9. )
  10. // hcs can sometimes take a long time to stop container.
  11. const StopContainerWindowsPollTimeout = 75 * time.Second
  12. func TestStopContainerWithRestartPolicyAlways(t *testing.T) {
  13. ctx := setupTest(t)
  14. apiClient := testEnv.APIClient()
  15. names := []string{"verifyRestart1-" + t.Name(), "verifyRestart2-" + t.Name()}
  16. for _, name := range names {
  17. container.Run(ctx, t, apiClient,
  18. container.WithName(name),
  19. container.WithCmd("false"),
  20. container.WithRestartPolicy(containertypes.RestartPolicyAlways),
  21. )
  22. }
  23. for _, name := range names {
  24. poll.WaitOn(t, container.IsInState(ctx, apiClient, name, "running", "restarting"), poll.WithDelay(100*time.Millisecond))
  25. }
  26. for _, name := range names {
  27. err := apiClient.ContainerStop(ctx, name, containertypes.StopOptions{})
  28. assert.NilError(t, err)
  29. }
  30. for _, name := range names {
  31. poll.WaitOn(t, container.IsStopped(ctx, apiClient, name), poll.WithDelay(100*time.Millisecond))
  32. }
  33. }