| 307 | } |
| 308 | |
| 309 | func StopContainer(t *testing.T, pool *dockertest.Pool, id string, to time.Duration) { |
| 310 | t.Helper() |
| 311 | |
| 312 | err := pool.Client.KillContainer(docker.KillContainerOptions{ |
| 313 | ID: id, |
| 314 | Signal: docker.SIGTERM, |
| 315 | }) |
| 316 | require.NoError(t, err) |
| 317 | |
| 318 | ctx, cancel := context.WithTimeout(context.Background(), to) |
| 319 | defer cancel() |
| 320 | for r := retry.New(time.Second, time.Second); r.Wait(ctx); { |
| 321 | cnt, err := pool.Client.InspectContainer(id) |
| 322 | require.NoError(t, err) |
| 323 | |
| 324 | if cnt.State.Running { |
| 325 | continue |
| 326 | } |
| 327 | |
| 328 | return |
| 329 | } |
| 330 | |
| 331 | t.Fatalf("timed out waiting for container %s to stop", id) |
| 332 | } |
| 333 | |
| 334 | // cmdLineEnvs returns args passed to the /envbox command |
| 335 | // but using their env var alias. |