From a1dcfd47a1a35d47c51c10cc644d70f177bfdc0f Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Thu, 20 Feb 2020 14:19:24 -0700 Subject: Flake fix: race condition in same-IP test 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 --- test/e2e/create_staticip_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/e2e/create_staticip_test.go b/test/e2e/create_staticip_test.go index 72a0638f9..693795637 100644 --- a/test/e2e/create_staticip_test.go +++ b/test/e2e/create_staticip_test.go @@ -4,6 +4,7 @@ package integration import ( "os" + "time" . "github.com/containers/libpod/test/utils" . "github.com/onsi/ginkgo" @@ -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")) }) }) -- cgit v1.2.3-54-g00ecf