chore: improve error logging in TestServer/EphemeralDeployment (#17184)

There's a flake reported in https://github.com/coder/internal/issues/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.
This commit is contained in:
Hugo Dutka
2025-04-01 13:23:06 +02:00
committed by GitHub
parent e4cf18989c
commit 7d08bf0afe
+21 -2
View File
@@ -201,7 +201,16 @@ func TestServer(t *testing.T) {
go func() {
errCh <- inv.WithContext(ctx).Run()
}()
pty.ExpectMatch("Using an ephemeral deployment directory")
matchCh1 := make(chan string, 1)
go func() {
matchCh1 <- pty.ExpectMatchContext(ctx, "Using an ephemeral deployment directory")
}()
select {
case err := <-errCh:
require.NoError(t, err)
case <-matchCh1:
// OK!
}
rootDirLine := pty.ReadLine(ctx)
rootDir := strings.TrimPrefix(rootDirLine, "Using an ephemeral deployment directory")
rootDir = strings.TrimSpace(rootDir)
@@ -210,7 +219,17 @@ func TestServer(t *testing.T) {
require.NotEmpty(t, rootDir)
require.DirExists(t, rootDir)
pty.ExpectMatchContext(ctx, "View the Web UI")
matchCh2 := make(chan string, 1)
go func() {
// The "View the Web UI" log is a decent indicator that the server was successfully started.
matchCh2 <- pty.ExpectMatchContext(ctx, "View the Web UI")
}()
select {
case err := <-errCh:
require.NoError(t, err)
case <-matchCh2:
// OK!
}
cancelFunc()
<-errCh