Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 8d86f57

Browse files
authored
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
2 parents d99a510 + 6c5bd67 commit 8d86f57

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

local/e2e/compose/compose_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"net/http"
2323
"os"
2424
"path/filepath"
25-
"regexp"
2625
"runtime"
2726
"strings"
2827
"testing"
@@ -192,15 +191,16 @@ func TestDownComposefileInParentFolder(t *testing.T) {
192191
func TestAttachRestart(t *testing.T) {
193192
c := NewParallelE2eCLI(t, binDir)
194193

195-
res := c.RunDockerOrExitError("compose", "--ansi=never", "--project-directory", "./fixtures/attach-restart", "up")
194+
cmd := c.NewDockerCmd("compose", "--ansi=never", "--project-directory", "./fixtures/attach-restart", "up")
195+
res := icmd.StartCmd(cmd)
196196
defer c.RunDockerOrExitError("compose", "-p", "attach-restart", "down")
197-
output := res.Stdout()
198197

199-
exitRegex := regexp.MustCompile("another_1 exited with code 1")
200-
assert.Equal(t, len(exitRegex.FindAllStringIndex(output, -1)), 3, res.Combined())
198+
c.WaitForCondition(func() (bool, string) {
199+
debug := res.Combined()
200+
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)
201+
}, 2*time.Minute, 2*time.Second)
201202

202-
execRegex := regexp.MustCompile(`another_1 \| world`)
203-
assert.Equal(t, len(execRegex.FindAllStringIndex(output, -1)), 3, res.Combined())
203+
assert.Equal(t, strings.Count(res.Stdout(), "another_1 | world"), 3, res.Combined())
204204
}
205205

206206
func TestInitContainer(t *testing.T) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
simple:
33
image: alpine
4-
command: sh -c "sleep 5"
4+
command: sh -c "sleep infinity"
55
another:
66
image: alpine
77
command: sh -c "sleep 0.1 && echo world && /bin/false"

0 commit comments

Comments
 (0)