Skip to content

Commit

Permalink
Flake fix: race condition in same-IP test
Browse files Browse the repository at this point in the history
The "create two containers with the same IP" test failed:

   https://api.cirrus-ci.com/v1/task/5992323062431744/logs/integration_test.log#t--Podman-create-two-containers-with-the-same-IP
   ...
   (basically, expected error exit code, got 0)

Analysis: the sequence is 'start test1, start test2'. Perhaps it's
possible that 'podman start' exits before the test1 container has
an IP address assigned? There are no checks in the test, so it's
impossible to know what happened.

Solution: add a wait-loop invoking 'podman inspect', waiting
for a nonempty IP address on test 1; then assert that it's
what we expect it to be.

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago authored and snj33v committed May 31, 2020
1 parent 1f08053 commit c6f2567
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/e2e/create_staticip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package integration

import (
"os"
"time"

. "github.com/containers/libpod/test/utils"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -86,8 +87,23 @@ var _ = Describe("Podman create with --ip flag", func() {
result = podmanTest.Podman([]string{"start", "test1"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))

// race prevention: wait until IP address is assigned
for i := 0; i < 5; i++ {
result = podmanTest.Podman([]string{"inspect", "--format", "{{.NetworkSettings.IPAddress}}", "test1"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
if result.OutputToString() != "" {
break
}
time.Sleep(1 * time.Second)
}
Expect(result.OutputToString()).To(Equal(ip))

// test1 container is running with the given IP.
result = podmanTest.Podman([]string{"start", "test2"})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
Expect(result.ErrorToString()).To(ContainSubstring("requested IP address " + ip + " is not available"))
})
})

0 comments on commit c6f2567

Please sign in to comment.