mirror of https://github.com/containers/podman.git
Robustify nginx tests
[skip ci] While chasing a flake, I discovered that our alpine_nginx image is broken: it returns 404 on all requests. We never caught this because--surprise!--curl exits 0 even when server returns 4xx/5xx status. Let's be strict: add -f (--fail) option to all invocations of curl. And, although I couldn't identify the root cause of the flake (in "run two containers with the same IP" test), I can at least fix the broken wait-for-nginx loop, bump up the number of retries, and improve diagnostics on failure. And add a strict error-message check. Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
parent
181c9d3ee3
commit
ee9d755c5b
|
@ -462,7 +462,8 @@ func (p *PodmanTestIntegration) RunNginxWithHealthCheck(name string) (*PodmanSes
|
||||||
if name != "" {
|
if name != "" {
|
||||||
podmanArgs = append(podmanArgs, "--name", name)
|
podmanArgs = append(podmanArgs, "--name", name)
|
||||||
}
|
}
|
||||||
podmanArgs = append(podmanArgs, "-dt", "-P", "--health-cmd", "curl http://localhost/", nginx)
|
// curl without -f exits 0 even if http code >= 400!
|
||||||
|
podmanArgs = append(podmanArgs, "-dt", "-P", "--health-cmd", "curl -f http://localhost/", nginx)
|
||||||
session := p.Podman(podmanArgs)
|
session := p.Podman(podmanArgs)
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
return session, session.OutputToString()
|
return session, session.OutputToString()
|
||||||
|
|
|
@ -119,11 +119,11 @@ var _ = Describe("Podman pod create", func() {
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
session = podmanTest.Podman([]string{"run", "--pod", podID, fedoraMinimal, "curl", "localhost:80"})
|
session = podmanTest.Podman([]string{"run", "--pod", podID, fedoraMinimal, "curl", "-f", "localhost:80"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
session = podmanTest.Podman([]string{"run", fedoraMinimal, "curl", "localhost"})
|
session = podmanTest.Podman([]string{"run", fedoraMinimal, "curl", "-f", "localhost"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).To(ExitWithError())
|
Expect(session).To(ExitWithError())
|
||||||
})
|
})
|
||||||
|
@ -219,7 +219,7 @@ var _ = Describe("Podman pod create", func() {
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
session = podmanTest.Podman([]string{"run", "--pod", podID, "--network", "bridge", nginx, "curl", "localhost"})
|
session = podmanTest.Podman([]string{"run", "--pod", podID, "--network", "bridge", nginx, "curl", "-f", "localhost"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).To(ExitWithError())
|
Expect(session).To(ExitWithError())
|
||||||
})
|
})
|
||||||
|
|
|
@ -102,22 +102,33 @@ var _ = Describe("Podman run with --ip flag", func() {
|
||||||
|
|
||||||
It("Podman run two containers with the same IP", func() {
|
It("Podman run two containers with the same IP", func() {
|
||||||
ip := GetRandomIPAddress()
|
ip := GetRandomIPAddress()
|
||||||
result := podmanTest.Podman([]string{"run", "-dt", "--ip", ip, nginx})
|
result := podmanTest.Podman([]string{"run", "-d", "--name", "nginx", "--ip", ip, nginx})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
Expect(result).Should(Exit(0))
|
Expect(result).Should(Exit(0))
|
||||||
for i := 0; i < 10; i++ {
|
|
||||||
fmt.Println("Waiting for nginx", err)
|
for retries := 20; retries > 0; retries-- {
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
response, err := http.Get(fmt.Sprintf("http://%s", ip))
|
response, err := http.Get(fmt.Sprintf("http://%s", ip))
|
||||||
if err != nil {
|
if err == nil && response.StatusCode == http.StatusOK {
|
||||||
continue
|
|
||||||
}
|
|
||||||
if response.StatusCode == http.StatusOK {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if retries == 1 {
|
||||||
|
logps := podmanTest.Podman([]string{"ps", "-a"})
|
||||||
|
logps.WaitWithDefaultTimeout()
|
||||||
|
logps = podmanTest.Podman([]string{"logs", "nginx"})
|
||||||
|
logps.WaitWithDefaultTimeout()
|
||||||
|
Fail("Timed out waiting for nginx container, see ps & log above.")
|
||||||
}
|
}
|
||||||
result = podmanTest.Podman([]string{"run", "-ti", "--ip", ip, ALPINE, "ip", "addr"})
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("nginx not ready yet; error=%v; %d retries left...\n", err, retries)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("nginx not ready yet; response=%v; %d retries left...\n", response.StatusCode, retries)
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
result = podmanTest.Podman([]string{"run", "--ip", ip, ALPINE, "ip", "addr"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
Expect(result).To(ExitWithError())
|
Expect(result).To(ExitWithError())
|
||||||
|
Expect(result.ErrorToString()).To(ContainSubstring(" address %s ", ip))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue