Skip to content

Commit

Permalink
chore: fix flaky e2e test (#42)
Browse files Browse the repository at this point in the history
Signed-off-by: Cezar Rata <[email protected]>
  • Loading branch information
cezar-r authored Sep 17, 2024
1 parent 504dcaf commit 808a16b
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions e2e/tests/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,20 +464,29 @@ func ContainerCreate(opt *option.Option) {
// start and kill a container
command.Run(opt, "start", testContainerName)
command.Run(opt, "kill", "--signal=SIGKILL", testContainerName)
time.Sleep(5 * time.Second)

// inspect container
resp := command.Stdout(opt, "inspect", testContainerName)
var inspect []*dockercompat.Container
err := json.Unmarshal(resp, &inspect)
Expect(err).Should(BeNil())
Expect(inspect).Should(HaveLen(1))

// verify container is still running
Expect(inspect[0].State.Running).Should(BeTrue())

// verify restart count is 1
Expect(inspect[0].RestartCount).Should(Equal(1))
// check every 500 ms if container restarted
ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()
maxDuration := 10 * time.Second
startTime := time.Now()
for range ticker.C {
// fail testcase if 10 seconds have passed
Expect(time.Since(startTime) < maxDuration).Should(BeTrue())

// inspect container
resp := command.Stdout(opt, "inspect", testContainerName)
var inspect []*dockercompat.Container
err := json.Unmarshal(resp, &inspect)
Expect(err).Should(BeNil())
Expect(inspect).Should(HaveLen(1))

// if container is running, verify it was restarted
if inspect[0].State.Running {
Expect(inspect[0].RestartCount).Should(Equal(1))
return
}
}
})
})
}
Expand Down

0 comments on commit 808a16b

Please sign in to comment.