| 317 | } |
| 318 | |
| 319 | func (b *Base) EnsureContainerExited(con string, expectedExitCode int) { |
| 320 | b.T.Helper() |
| 321 | |
| 322 | const ( |
| 323 | maxRetry = 5 |
| 324 | sleep = time.Second |
| 325 | ) |
| 326 | var c dockercompat.Container |
| 327 | for i := 0; i < maxRetry; i++ { |
| 328 | c = b.InspectContainer(con) |
| 329 | if c.State.Status == "exited" { |
| 330 | b.T.Logf("container %s have exited with status %d", con, c.State.ExitCode) |
| 331 | if c.State.ExitCode == expectedExitCode { |
| 332 | return |
| 333 | } |
| 334 | break |
| 335 | } |
| 336 | b.T.Logf("(retry=%d)", i+1) |
| 337 | time.Sleep(sleep) |
| 338 | } |
| 339 | b.T.Fatalf("expected conainer %s to have exited with code %d, got status %+v", |
| 340 | con, expectedExitCode, c.State) |
| 341 | } |
| 342 | |
| 343 | type Cmd struct { |
| 344 | icmd.Cmd |