Browse Source

Merge pull request #1594 from gtardif/fix_test_race

Fix race in TestAttachRestart : wait for logs to appear rather than have a fixed TTL for the application
Guillaume Tardif 4 years ago
parent
commit
8d86f578ed

+ 7 - 7
local/e2e/compose/compose_test.go

@@ -22,7 +22,6 @@ import (
 	"net/http"
 	"os"
 	"path/filepath"
-	"regexp"
 	"runtime"
 	"strings"
 	"testing"
@@ -192,15 +191,16 @@ func TestDownComposefileInParentFolder(t *testing.T) {
 func TestAttachRestart(t *testing.T) {
 	c := NewParallelE2eCLI(t, binDir)
 
-	res := c.RunDockerOrExitError("compose", "--ansi=never", "--project-directory", "./fixtures/attach-restart", "up")
+	cmd := c.NewDockerCmd("compose", "--ansi=never", "--project-directory", "./fixtures/attach-restart", "up")
+	res := icmd.StartCmd(cmd)
 	defer c.RunDockerOrExitError("compose", "-p", "attach-restart", "down")
-	output := res.Stdout()
 
-	exitRegex := regexp.MustCompile("another_1 exited with code 1")
-	assert.Equal(t, len(exitRegex.FindAllStringIndex(output, -1)), 3, res.Combined())
+	c.WaitForCondition(func() (bool, string) {
+		debug := res.Combined()
+		return strings.Count(res.Stdout(), "another_1 exited with code 1") == 3, fmt.Sprintf("'another_1 exited with code 1' not found 3 times in : \n%s\n", debug)
+	}, 2*time.Minute, 2*time.Second)
 
-	execRegex := regexp.MustCompile(`another_1  \| world`)
-	assert.Equal(t, len(execRegex.FindAllStringIndex(output, -1)), 3, res.Combined())
+	assert.Equal(t, strings.Count(res.Stdout(), "another_1  | world"), 3, res.Combined())
 }
 
 func TestInitContainer(t *testing.T) {

+ 1 - 1
local/e2e/compose/fixtures/attach-restart/compose.yaml

@@ -1,7 +1,7 @@
 services:
   simple:
     image: alpine
-    command: sh -c "sleep 5"
+    command: sh -c "sleep infinity"
   another:
     image: alpine
     command: sh -c "sleep 0.1 && echo world && /bin/false"