chore(e2e): fix flaky test & standalone behavior (#11382)

This commit is contained in:
Milas Bowman 2024-01-30 10:49:53 -05:00 committed by GitHub
parent a0954dc59d
commit 8fdd45cd4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 15 deletions

View File

@ -37,18 +37,26 @@ func TestComposeCancel(t *testing.T) {
c := NewParallelCLI(t) c := NewParallelCLI(t)
t.Run("metrics on cancel Compose build", func(t *testing.T) { t.Run("metrics on cancel Compose build", func(t *testing.T) {
c.RunDockerComposeCmd(t, "ls") const buildProjectPath = "fixtures/build-infinite/compose.yaml"
buildProjectPath := "fixtures/build-infinite/compose.yaml"
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// require a separate groupID from the process running tests, in order to simulate ctrl+C from a terminal. // require a separate groupID from the process running tests, in order to simulate ctrl+C from a terminal.
// sending kill signal // sending kill signal
stdout := &utils.SafeBuffer{} var stdout, stderr utils.SafeBuffer
stderr := &utils.SafeBuffer{} cmd, err := StartWithNewGroupID(
cmd, err := StartWithNewGroupID(context.Background(), ctx,
c.NewDockerComposeCmd(t, "-f", buildProjectPath, "build", "--progress", "plain"), c.NewDockerComposeCmd(t, "-f", buildProjectPath, "build", "--progress", "plain"),
stdout, &stdout,
stderr) &stderr,
)
assert.NilError(t, err) assert.NilError(t, err)
processDone := make(chan error, 1)
go func() {
defer close(processDone)
processDone <- cmd.Wait()
}()
c.WaitForCondition(t, func() (bool, string) { c.WaitForCondition(t, func() (bool, string) {
out := stdout.String() out := stdout.String()
@ -58,15 +66,21 @@ func TestComposeCancel(t *testing.T) {
errors) errors)
}, 30*time.Second, 1*time.Second) }, 30*time.Second, 1*time.Second)
err = syscall.Kill(-cmd.Process.Pid, syscall.SIGINT) // simulate Ctrl-C : send signal to processGroup, children will have same groupId by default // simulate Ctrl-C : send signal to processGroup, children will have same groupId by default
err = syscall.Kill(-cmd.Process.Pid, syscall.SIGINT)
assert.NilError(t, err) assert.NilError(t, err)
c.WaitForCondition(t, func() (bool, string) { select {
out := stdout.String() case <-ctx.Done():
errors := stderr.String() t.Fatal("test context canceled")
return strings.Contains(out, "CANCELED"), fmt.Sprintf("'CANCELED' not found in : \n%s\nStderr: \n%s\n", out, case err := <-processDone:
errors) // TODO(milas): Compose should really not return exit code 130 here,
}, 10*time.Second, 1*time.Second) // this is an old hack for the compose-cli wrapper
assert.Error(t, err, "exit status 130",
"STDOUT:\n%s\nSTDERR:\n%s\n", stdout.String(), stderr.String())
case <-time.After(10 * time.Second):
t.Fatal("timeout waiting for Compose exit")
}
}) })
} }

View File

@ -18,4 +18,4 @@
package e2e package e2e
const composeStandaloneMode = true const composeStandaloneMode = false