(t *testing.T)
| 30 | ) |
| 31 | |
| 32 | func TestPause(t *testing.T) { |
| 33 | cli := NewParallelCLI(t, WithEnv( |
| 34 | "COMPOSE_PROJECT_NAME=e2e-pause", |
| 35 | "COMPOSE_FILE=./fixtures/pause/compose.yaml")) |
| 36 | |
| 37 | cleanup := func() { |
| 38 | cli.RunDockerComposeCmd(t, "down", "-v", "--remove-orphans", "-t", "0") |
| 39 | } |
| 40 | cleanup() |
| 41 | t.Cleanup(cleanup) |
| 42 | |
| 43 | // launch both services and verify that they are accessible |
| 44 | cli.RunDockerComposeCmd(t, "up", "-d") |
| 45 | urls := map[string]string{ |
| 46 | "a": urlForService(t, cli, "a", 80), |
| 47 | "b": urlForService(t, cli, "b", 80), |
| 48 | } |
| 49 | for _, url := range urls { |
| 50 | HTTPGetWithRetry(t, url, http.StatusOK, 50*time.Millisecond, 20*time.Second) |
| 51 | } |
| 52 | |
| 53 | // pause a and verify that it can no longer be hit but b still can |
| 54 | cli.RunDockerComposeCmd(t, "pause", "a") |
| 55 | httpClient := http.Client{Timeout: 250 * time.Millisecond} |
| 56 | resp, err := httpClient.Get(urls["a"]) |
| 57 | if resp != nil { |
| 58 | _ = resp.Body.Close() |
| 59 | } |
| 60 | assert.Assert(t, err != nil, "a should no longer respond") |
| 61 | var netErr net.Error |
| 62 | assert.ErrorType(t, err, &netErr, "expected a network error") |
| 63 | errors.As(err, &netErr) |
| 64 | assert.Assert(t, netErr.Timeout(), "Error should have indicated a timeout") |
| 65 | HTTPGetWithRetry(t, urls["b"], http.StatusOK, 50*time.Millisecond, 5*time.Second) |
| 66 | |
| 67 | // unpause a and verify that both containers work again |
| 68 | cli.RunDockerComposeCmd(t, "unpause", "a") |
| 69 | for _, url := range urls { |
| 70 | HTTPGetWithRetry(t, url, http.StatusOK, 50*time.Millisecond, 5*time.Second) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | func TestPauseServiceNotRunning(t *testing.T) { |
| 75 | cli := NewParallelCLI(t, WithEnv( |
nothing calls this directly
no test coverage detected