Skip to content

Commit 43b2e32

Browse files
authored
fix flaky standalone e2e by dropping "Exited App successfully" requirement (#1605)
* fix flaky standalone e2e by dropping "Exited App successfully" requirement Signed-off-by: Albert Callarisa <albert@diagrid.io> * consume stderr in e2e tests Signed-off-by: Albert Callarisa <albert@diagrid.io> * Address copilot comments Signed-off-by: Albert Callarisa <albert@diagrid.io> * Address copilot comments Signed-off-by: Albert Callarisa <albert@diagrid.io> * Address copilot comments Signed-off-by: Albert Callarisa <albert@diagrid.io> --------- Signed-off-by: Albert Callarisa <albert@diagrid.io>
1 parent 5ba93c7 commit 43b2e32

1 file changed

Lines changed: 40 additions & 12 deletions

File tree

tests/e2e/standalone/utils.go

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,38 @@ func executeAgainstRunningDapr(t *testing.T, f func(), daprArgs ...string) {
112112
daprPath := common.GetDaprPath()
113113

114114
cmd := exec.Command(daprPath, daprArgs...)
115-
reader, err := cmd.StdoutPipe()
116-
require.NoError(t, err, "failed to get stdout pipe")
117-
scanner := bufio.NewScanner(reader)
115+
stdoutReader, err := cmd.StdoutPipe()
116+
require.NoError(t, err, "failed to get stdout pipe for dapr")
117+
stderrReader, err := cmd.StderrPipe()
118+
require.NoError(t, err, "failed to get stderr pipe for dapr")
119+
scanner := bufio.NewScanner(stdoutReader)
118120

119-
require.NoError(t, cmd.Start(), "failed to start dapr process")
121+
err = cmd.Start()
122+
require.NoError(t, err, "failed to start dapr")
123+
124+
var wg sync.WaitGroup
125+
var stderrOutput strings.Builder
126+
wg.Add(1)
127+
go func() {
128+
defer wg.Done()
129+
stderrScanner := bufio.NewScanner(stderrReader)
130+
for stderrScanner.Scan() {
131+
line := stderrScanner.Text()
132+
t.Log(line)
133+
stderrOutput.WriteString(line + "\n")
134+
}
135+
if err := stderrScanner.Err(); err != nil {
136+
t.Errorf("error while reading dapr stderr: %v", err)
137+
}
138+
}()
139+
140+
t.Cleanup(func() {
141+
if cmd.Process != nil {
142+
_ = cmd.Process.Kill()
143+
_ = cmd.Wait()
144+
}
145+
wg.Wait()
146+
})
120147

121148
// scanDone is closed when the scanner.Scan loop finishes, meaning
122149
// the process has closed its stdout pipe (i.e., is exiting).
@@ -144,27 +171,28 @@ func executeAgainstRunningDapr(t *testing.T, f func(), daprArgs ...string) {
144171
if strings.Contains(outputChunk, "You're up and running!") {
145172
f()
146173
}
147-
daprOutput += outputChunk
174+
daprOutput += outputChunk + "\n"
175+
}
176+
if err := scanner.Err(); err != nil {
177+
t.Errorf("error while reading dapr stdout: %v", err)
148178
}
149179
close(scanDone)
150180

181+
wg.Wait()
182+
daprOutput += stderrOutput.String()
183+
151184
err = cmd.Wait()
152-
hasAppCommand := !strings.Contains(daprOutput, "WARNING: no application command found")
153-
terminatedBySignal := strings.Contains(daprOutput, "terminated signal received: shutting down")
154185
if err != nil {
155186
var exitErr *exec.ExitError
156187
if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 &&
157188
strings.Contains(daprOutput, "Exited Dapr successfully") &&
158-
(!hasAppCommand || terminatedBySignal || strings.Contains(daprOutput, "Exited App successfully")) {
189+
!strings.Contains(daprOutput, "The App process exited with error") {
159190
err = nil
160191
}
161192
}
162193
require.NoError(t, err, "dapr didn't exit cleanly")
163-
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")
194+
assert.NotContains(t, daprOutput, "The App process exited with error", "Stop command should have been called before the app had a chance to exit")
164195
assert.Contains(t, daprOutput, "Exited Dapr successfully")
165-
if hasAppCommand && !terminatedBySignal {
166-
assert.Contains(t, daprOutput, "Exited App successfully")
167-
}
168196
}
169197

170198
// waitForPortsFree polls until all given ports are available for binding.

0 commit comments

Comments
 (0)