Skip to content

Commit 52189a2

Browse files
authored
chore(integration): AS-696 address integration test flakes (#392)
1 parent c20d2d7 commit 52189a2

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

tests/integration/compose/common_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package integration
55

66
import (
7+
"fmt"
8+
"strings"
79
"testing"
810
"time"
911

@@ -42,3 +44,30 @@ func get_logs(t *testing.T, dockerOptions *docker.Options, container string) str
4244
output := docker.RunDockerComposeAndGetStdOut(t, dockerOptions, "logs", container)
4345
return output
4446
}
47+
48+
func checkContainerLogsWithRetries(subT *testing.T, dockerOptions *docker.Options, container string, tc string, expected string) {
49+
maxRetries := 6
50+
retryDelay := 2 * time.Second
51+
52+
var log string
53+
54+
for i := 0; i < maxRetries; i++ {
55+
log = get_logs(subT, dockerOptions, container)
56+
if strings.Contains(log, expected) {
57+
// Log entry found, proceed to next container
58+
break
59+
}
60+
61+
// Log entry not found, wait before retrying
62+
if i < maxRetries-1 {
63+
time.Sleep(retryDelay)
64+
}
65+
}
66+
67+
// Final assertion
68+
subT.Run(fmt.Sprintf("%s - %s", tc, container), func(t *testing.T) {
69+
if !strings.Contains(log, expected) {
70+
t.Errorf("%s - %s - log should contain matching entry:\n\t%s", tc, container, expected)
71+
}
72+
})
73+
}

tests/integration/compose/docker-compose-internal-auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (s *commonServicesInternalAuthDockerComposeUpTest) TestDockerComposeUp() {
339339
validate_endpoint(subT, expected.url, expected.responsePayload, expected.httpResponseCode)
340340
}
341341
// Validate log output is expected
342-
s.Contains(get_logs(subT, dockerOptions, expected.name), expected.log, fmt.Sprintf("%s - %s - log should contain matching entry", testCase.name, expected.name))
342+
checkContainerLogsWithRetries(subT, dockerOptions, expected.name, testCase.name, expected.log)
343343
}
344344
})
345345
}

tests/integration/compose/docker-compose-legacy-auth_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,7 @@ func (s *commonServicesLegacyAuthDockerComposeUpTest) TestDockerComposeUp() {
337337
}
338338

339339
// Validate log output is expected
340-
s.Contains(
341-
get_logs(subT, dockerOptions, expected.name),
342-
expected.log,
343-
fmt.Sprintf("%s - %s - log should contain matching entry", testCase.name, expected.name),
344-
)
340+
checkContainerLogsWithRetries(subT, dockerOptions, expected.name, testCase.name, expected.log)
345341
}
346342
})
347343
}

0 commit comments

Comments
 (0)