From 53411ebbf3d558123e4fc0eb492aba05bf0077c6 Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Mon, 19 Feb 2024 11:17:53 -0600 Subject: [PATCH 1/4] attempt to make insert/work test more reliable --- client_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client_test.go b/client_test.go index e1fbd395..2274f95a 100644 --- a/client_test.go +++ b/client_test.go @@ -2412,11 +2412,12 @@ func Test_Client_InsertTriggersImmediateWork(t *testing.T) { client := newTestClient(t, dbPool, config) statusUpdateCh := client.monitor.RegisterUpdates() + startClient(ctx, t, client) + waitForClientHealthy(ctx, t, statusUpdateCh) + insertedJob, err := client.Insert(ctx, callbackArgs{}, nil) require.NoError(err) - startClient(ctx, t, client) - // Wait for the client to be ready by waiting for a job to be executed: select { case jobID := <-startedCh: @@ -2424,7 +2425,6 @@ func Test_Client_InsertTriggersImmediateWork(t *testing.T) { case <-ctx.Done(): t.Fatal("timed out waiting for warmup job to start") } - waitForClientHealthy(ctx, t, statusUpdateCh) // Now that we've run one job, we shouldn't take longer than the cooldown to // fetch another after insertion. LISTEN/NOTIFY should ensure we find out From 94c27044d5cdc0a8402d9ad0838873d2df21f784 Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Thu, 22 Feb 2024 09:16:09 -0600 Subject: [PATCH 2/4] log client monitor status in tests --- client_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/client_test.go b/client_test.go index 2274f95a..e719f0c3 100644 --- a/client_test.go +++ b/client_test.go @@ -40,6 +40,7 @@ func waitForClientHealthy(ctx context.Context, t *testing.T, statusUpdateCh <-ch for { select { case status := <-statusUpdateCh: + t.Logf("Client status: elector=%d notifier=%d producers=%+v", status.Elector, status.Notifier, status.Producers) if status.Healthy() { return } From 4a9bb7a3e2e7ea4c3abb7db079bd8da960666f7e Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Thu, 22 Feb 2024 09:17:32 -0600 Subject: [PATCH 3/4] tests: log when await callback job is started --- client_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client_test.go b/client_test.go index e719f0c3..f8874fa9 100644 --- a/client_test.go +++ b/client_test.go @@ -81,6 +81,9 @@ type callbackFunc func(context.Context, *Job[callbackArgs]) error func makeAwaitCallback(startedCh chan<- int64, doneCh chan struct{}) callbackFunc { return func(ctx context.Context, job *Job[callbackArgs]) error { + client := ClientFromContext[pgx.Tx](ctx) + client.config.Logger.InfoContext(ctx, "callback job started with id="+fmt.Sprint(job.ID)) + select { case <-ctx.Done(): return ctx.Err() From 8158e232fce4eebd1ac5536615026c9a7daacb97 Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Thu, 22 Feb 2024 09:17:50 -0600 Subject: [PATCH 4/4] shorten ConnectTimeout in tests 10s -> 2s The intention here is to avoid attempts that are likely to hang forever, and instead give up while there's still enough time for the test to have a chance of succeeding. --- client_test.go | 3 ++- internal/riverinternaltest/riverinternaltest.go | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/client_test.go b/client_test.go index f8874fa9..067c1cc9 100644 --- a/client_test.go +++ b/client_test.go @@ -7,6 +7,7 @@ import ( "fmt" "log/slog" "os" + "strconv" "strings" "sync" "testing" @@ -82,7 +83,7 @@ type callbackFunc func(context.Context, *Job[callbackArgs]) error func makeAwaitCallback(startedCh chan<- int64, doneCh chan struct{}) callbackFunc { return func(ctx context.Context, job *Job[callbackArgs]) error { client := ClientFromContext[pgx.Tx](ctx) - client.config.Logger.InfoContext(ctx, "callback job started with id="+fmt.Sprint(job.ID)) + client.config.Logger.InfoContext(ctx, "callback job started with id="+strconv.FormatInt(job.ID, 10)) select { case <-ctx.Done(): diff --git a/internal/riverinternaltest/riverinternaltest.go b/internal/riverinternaltest/riverinternaltest.go index 7b8e0040..1c50ae81 100644 --- a/internal/riverinternaltest/riverinternaltest.go +++ b/internal/riverinternaltest/riverinternaltest.go @@ -69,7 +69,9 @@ func DatabaseConfig(databaseName string) *pgxpool.Config { panic(fmt.Sprintf("error parsing database URL: %v", err)) } config.MaxConns = dbPoolMaxConns - config.ConnConfig.ConnectTimeout = 10 * time.Second + // Use a short conn timeout here to attempt to quickly cancel attempts that + // are unlikely to succeed even with more time: + config.ConnConfig.ConnectTimeout = 2 * time.Second config.ConnConfig.RuntimeParams["timezone"] = "UTC" return config }