diff --git a/tests/e2e/standalone/utils.go b/tests/e2e/standalone/utils.go index 4eff6287b..4f57615fd 100644 --- a/tests/e2e/standalone/utils.go +++ b/tests/e2e/standalone/utils.go @@ -23,6 +23,7 @@ import ( "path/filepath" "runtime" "strings" + "sync" "testing" "github.com/stretchr/testify/assert" @@ -101,10 +102,38 @@ func executeAgainstRunningDapr(t *testing.T, f func(), daprArgs ...string) { daprPath := common.GetDaprPath() cmd := exec.Command(daprPath, daprArgs...) - reader, _ := cmd.StdoutPipe() - scanner := bufio.NewScanner(reader) + stdoutReader, err := cmd.StdoutPipe() + require.NoError(t, err, "failed to get stdout pipe for dapr") + stderrReader, err := cmd.StderrPipe() + require.NoError(t, err, "failed to get stderr pipe for dapr") + scanner := bufio.NewScanner(stdoutReader) + + err = cmd.Start() + require.NoError(t, err, "failed to start dapr") + + var wg sync.WaitGroup + var stderrOutput strings.Builder + wg.Add(1) + go func() { + defer wg.Done() + stderrScanner := bufio.NewScanner(stderrReader) + for stderrScanner.Scan() { + line := stderrScanner.Text() + t.Log(line) + stderrOutput.WriteString(line + "\n") + } + if err := stderrScanner.Err(); err != nil { + t.Errorf("error while reading dapr stderr: %v", err) + } + }() - cmd.Start() + t.Cleanup(func() { + if cmd.Process != nil { + _ = cmd.Process.Kill() + _ = cmd.Wait() + } + wg.Wait() + }) daprOutput := "" for scanner.Scan() { @@ -113,25 +142,27 @@ func executeAgainstRunningDapr(t *testing.T, f func(), daprArgs ...string) { if strings.Contains(outputChunk, "You're up and running!") { f() } - daprOutput += outputChunk + daprOutput += outputChunk + "\n" } + if err := scanner.Err(); err != nil { + t.Errorf("error while reading dapr stdout: %v", err) + } + + wg.Wait() + daprOutput += stderrOutput.String() - err := cmd.Wait() - hasAppCommand := !strings.Contains(daprOutput, "WARNING: no application command found") + err = cmd.Wait() if err != nil { var exitErr *exec.ExitError if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 && strings.Contains(daprOutput, "Exited Dapr successfully") && - (!hasAppCommand || strings.Contains(daprOutput, "Exited App successfully")) { + !strings.Contains(daprOutput, "The App process exited with error") { err = nil } } require.NoError(t, err, "dapr didn't exit cleanly") - assert.NotContains(t, daprOutput, "The App process exited with error code: exit status", "Stop command should have been called before the app had a chance to exit") + assert.NotContains(t, daprOutput, "The App process exited with error", "Stop command should have been called before the app had a chance to exit") assert.Contains(t, daprOutput, "Exited Dapr successfully") - if hasAppCommand { - assert.Contains(t, daprOutput, "Exited App successfully") - } } // ensureDaprInstallation ensures that Dapr is installed.