Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d08bf0

Browse files
authored
chore: improve error logging in TestServer/EphemeralDeployment (#17184)
There's a flake reported in coder/internal#549 that was caused by the built-in Postgres failing to start. However, the test was written in a way that didn't log the actual error which caused Postgres to fail. This PR improves error logging in the affected test so that the next time the error happens, we know what it is.
1 parent e4cf189 commit 7d08bf0

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

cli/server_test.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,16 @@ func TestServer(t *testing.T) {
201201
go func() {
202202
errCh <- inv.WithContext(ctx).Run()
203203
}()
204-
pty.ExpectMatch("Using an ephemeral deployment directory")
204+
matchCh1 := make(chan string, 1)
205+
go func() {
206+
matchCh1 <- pty.ExpectMatchContext(ctx, "Using an ephemeral deployment directory")
207+
}()
208+
select {
209+
case err := <-errCh:
210+
require.NoError(t, err)
211+
case <-matchCh1:
212+
// OK!
213+
}
205214
rootDirLine := pty.ReadLine(ctx)
206215
rootDir := strings.TrimPrefix(rootDirLine, "Using an ephemeral deployment directory")
207216
rootDir = strings.TrimSpace(rootDir)
@@ -210,7 +219,17 @@ func TestServer(t *testing.T) {
210219
require.NotEmpty(t, rootDir)
211220
require.DirExists(t, rootDir)
212221

213-
pty.ExpectMatchContext(ctx, "View the Web UI")
222+
matchCh2 := make(chan string, 1)
223+
go func() {
224+
// The "View the Web UI" log is a decent indicator that the server was successfully started.
225+
matchCh2 <- pty.ExpectMatchContext(ctx, "View the Web UI")
226+
}()
227+
select {
228+
case err := <-errCh:
229+
require.NoError(t, err)
230+
case <-matchCh2:
231+
// OK!
232+
}
214233

215234
cancelFunc()
216235
<-errCh

0 commit comments

Comments
 (0)