aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilip Tehlar <ftehlar@cisco.com>2023-12-06 11:35:11 +0100
committerFlorin Coras <florin.coras@gmail.com>2024-01-11 10:27:09 +0000
commit4fa0ba6ac0f78a49a3481063105020a9b585476c (patch)
tree49d4c1acb19be08512ffa53e580c31790cf87d48
parentafefe22e5d0ed0004d21b974d601c81f8a2b66b9 (diff)
hs-test: retry command on test setup failure
Type: test Change-Id: Iad744c4b3f79820e8bd0dd2ef9f18e4f7718e845 Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
-rw-r--r--extras/hs-test/container.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/extras/hs-test/container.go b/extras/hs-test/container.go
index 76d08c7d2d6..812198d62db 100644
--- a/extras/hs-test/container.go
+++ b/extras/hs-test/container.go
@@ -6,6 +6,7 @@ import (
"os/exec"
"strings"
"text/template"
+ "time"
"github.com/edwarnicke/exechelper"
)
@@ -137,6 +138,18 @@ func (c *Container) getContainerArguments() string {
return args
}
+func (c *Container) runWithRetry(cmd string) error {
+ nTries := 5
+ for i := 0; i < nTries; i++ {
+ err := exechelper.Run(cmd)
+ if err == nil {
+ return nil
+ }
+ time.Sleep(1 * time.Second)
+ }
+ return fmt.Errorf("failed to run container command")
+}
+
func (c *Container) create() error {
cmd := "docker create " + c.getContainerArguments()
c.suite.log(cmd)
@@ -146,7 +159,7 @@ func (c *Container) create() error {
func (c *Container) start() error {
cmd := "docker start " + c.name
c.suite.log(cmd)
- return exechelper.Run(cmd)
+ return c.runWithRetry(cmd)
}
func (c *Container) prepareCommand() (string, error) {
@@ -179,8 +192,7 @@ func (c *Container) run() error {
if err != nil {
return err
}
-
- return exechelper.Run(cmd)
+ return c.runWithRetry(cmd)
}
func (c *Container) addVolume(hostDir string, containerDir string, isDefaultWorkDir bool) {