From 7d08bf0afe79e75961aeda9407dae05ead3f8942 Mon Sep 17 00:00:00 2001 From: Hugo Dutka Date: Tue, 1 Apr 2025 13:23:06 +0200 Subject: [PATCH] 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. --- cli/server_test.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/cli/server_test.go b/cli/server_test.go index f224fcb43f..715cbe5c75 100644 --- a/cli/server_test.go +++ b/cli/server_test.go @@ -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