From b8bde5d8147b61ea5935869b6ca3083545b1876d Mon Sep 17 00:00:00 2001 From: Cezar Rata Date: Tue, 17 Sep 2024 18:02:35 +0000 Subject: [PATCH] chore: fix flaky e2e test Signed-off-by: Cezar Rata --- e2e/tests/container_create.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/e2e/tests/container_create.go b/e2e/tests/container_create.go index 1f0520b..b3686d0 100644 --- a/e2e/tests/container_create.go +++ b/e2e/tests/container_create.go @@ -464,20 +464,24 @@ 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() + for range ticker.C { + // 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 + } + } }) }) }