diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5191e7d2..6b2376b0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,7 +21,7 @@ jobs: go-version: - "1.24" - "1.25" - postgres-version: [17, 16, 15] + postgres-version: [18, 17, 16] fail-fast: false timeout-minutes: 5 diff --git a/handler_api_endpoint_test.go b/handler_api_endpoint_test.go index 8c9c5247..b555f54d 100644 --- a/handler_api_endpoint_test.go +++ b/handler_api_endpoint_test.go @@ -36,11 +36,16 @@ type setupEndpointTestBundle struct { func setupEndpoint[TEndpoint any](ctx context.Context, t *testing.T, initFunc func(bundle apibundle.APIBundle[pgx.Tx]) *TEndpoint) (*TEndpoint, *setupEndpointTestBundle) { t.Helper() + return setupEndpointWithOpts(ctx, t, initFunc, nil) +} + +func setupEndpointWithOpts[TEndpoint any](ctx context.Context, t *testing.T, initFunc func(bundle apibundle.APIBundle[pgx.Tx]) *TEndpoint, opts *riverdbtest.TestTxOpts) (*TEndpoint, *setupEndpointTestBundle) { + t.Helper() var ( logger = riversharedtest.Logger(t) driver = riverpgxv5.New(riversharedtest.DBPool(ctx, t)) - tx, _ = riverdbtest.TestTxPgxDriver(ctx, t, driver, nil) + tx, _ = riverdbtest.TestTxPgxDriver(ctx, t, driver, opts) exec = driver.UnwrapExecutor(tx) ) @@ -234,9 +239,11 @@ func TestAPIHandlerFeaturesGet(t *testing.T) { ctx := context.Background() - t.Run("SuccessWithEverythingFalse", func(t *testing.T) { //nolint:paralleltest - // This can't be parallelized because it tries to make DB schema changes. - endpoint, bundle := setupEndpoint(ctx, t, newFeaturesGetEndpoint) + t.Run("SuccessWithEverythingFalse", func(t *testing.T) { + t.Parallel() + + // DisableSchemaSharing is required because we're making DB schema changes. + endpoint, bundle := setupEndpointWithOpts(ctx, t, newFeaturesGetEndpoint, &riverdbtest.TestTxOpts{DisableSchemaSharing: true}) _, err := bundle.tx.Exec(ctx, `DROP TABLE IF EXISTS river_client CASCADE;`) require.NoError(t, err) @@ -257,9 +264,11 @@ func TestAPIHandlerFeaturesGet(t *testing.T) { }, resp) }) - t.Run("SuccessWithEverythingTrue", func(t *testing.T) { //nolint:paralleltest - // This can't be parallelized because it tries to make DB schema changes. - endpoint, bundle := setupEndpoint(ctx, t, newFeaturesGetEndpoint) + t.Run("SuccessWithEverythingTrue", func(t *testing.T) { + t.Parallel() + + // DisableSchemaSharing is required because we're making DB schema changes. + endpoint, bundle := setupEndpointWithOpts(ctx, t, newFeaturesGetEndpoint, &riverdbtest.TestTxOpts{DisableSchemaSharing: true}) _, err := bundle.tx.Exec(ctx, `CREATE TABLE IF NOT EXISTS river_client (id SERIAL PRIMARY KEY);`) require.NoError(t, err) diff --git a/internal/riveruicmd/auth_middleware_test.go b/internal/riveruicmd/auth_middleware_test.go index c153a2f7..85a88a2a 100644 --- a/internal/riveruicmd/auth_middleware_test.go +++ b/internal/riveruicmd/auth_middleware_test.go @@ -20,7 +20,8 @@ import ( "riverqueue.com/riverui/uiendpoints" ) -func TestAuthMiddleware(t *testing.T) { +func TestAuthMiddleware(t *testing.T) { //nolint:tparallel + // Cannot be parallelized because of Setenv calls. var ( ctx = context.Background() databaseURL = cmp.Or(os.Getenv("TEST_DATABASE_URL"), "postgres://localhost/river_test") @@ -49,7 +50,9 @@ func TestAuthMiddleware(t *testing.T) { return initRes.httpServer.Handler } - t.Run("Unauthorized", func(t *testing.T) { //nolint:paralleltest + t.Run("Unauthorized", func(t *testing.T) { + t.Parallel() + handler := setup(t, "/") req := httptest.NewRequest(http.MethodGet, "/api/jobs", nil) recorder := httptest.NewRecorder() @@ -59,7 +62,9 @@ func TestAuthMiddleware(t *testing.T) { require.Equal(t, http.StatusUnauthorized, recorder.Code) }) - t.Run("Authorized", func(t *testing.T) { //nolint:paralleltest + t.Run("Authorized", func(t *testing.T) { + t.Parallel() + handler := setup(t, "/") req := httptest.NewRequest(http.MethodGet, "/api/jobs", nil) req.SetBasicAuth(basicAuthUser, basicAuthPassword) @@ -71,7 +76,9 @@ func TestAuthMiddleware(t *testing.T) { require.Equal(t, http.StatusOK, recorder.Code) }) - t.Run("Healthcheck exemption", func(t *testing.T) { //nolint:paralleltest + t.Run("Healthcheck exemption", func(t *testing.T) { + t.Parallel() + handler := setup(t, "/") req := httptest.NewRequest(http.MethodGet, "/api/health-checks/complete", nil) recorder := httptest.NewRecorder() @@ -81,7 +88,9 @@ func TestAuthMiddleware(t *testing.T) { require.Equal(t, http.StatusOK, recorder.Code) }) - t.Run("Healthcheck exemption with prefix", func(t *testing.T) { //nolint:paralleltest + t.Run("Healthcheck exemption with prefix", func(t *testing.T) { + t.Parallel() + handler := setup(t, "/test-prefix") req := httptest.NewRequest(http.MethodGet, "/test-prefix/api/health-checks/complete", nil) recorder := httptest.NewRecorder() diff --git a/internal/riveruicmd/riveruicmd_test.go b/internal/riveruicmd/riveruicmd_test.go index 4b9de38c..cf12ee2f 100644 --- a/internal/riveruicmd/riveruicmd_test.go +++ b/internal/riveruicmd/riveruicmd_test.go @@ -22,8 +22,8 @@ import ( "riverqueue.com/riverui/uiendpoints" ) -func TestInitServer(t *testing.T) { - // TODO: this should be upgradeable to our latest test patterns to be parallelizable. +func TestInitServer(t *testing.T) { //nolint:tparallel + // Cannot be parallelized because of Setenv calls. var ( ctx = context.Background() databaseURL = cmp.Or(os.Getenv("TEST_DATABASE_URL"), "postgres://localhost/river_test") @@ -51,14 +51,16 @@ func TestInitServer(t *testing.T) { return initRes, &testBundle{} } - t.Run("WithDatabaseURL", func(t *testing.T) { //nolint:paralleltest + t.Run("WithDatabaseURL", func(t *testing.T) { + t.Parallel() initRes, _ := setup(t) _, err := initRes.dbPool.Exec(ctx, "SELECT 1") require.NoError(t, err) }) - t.Run("WithPGEnvVars", func(t *testing.T) { + t.Run("WithPGEnvVars", func(t *testing.T) { //nolint:paralleltest + // Cannot be parallelized because of Setenv calls. t.Setenv("DATABASE_URL", "") parsedURL, err := url.Parse(databaseURL) @@ -79,7 +81,9 @@ func TestInitServer(t *testing.T) { }) t.Run("JobListHideArgsByDefault", func(t *testing.T) { - t.Run("default value is false", func(t *testing.T) { //nolint:paralleltest + t.Run("DefaultValueIsFalse", func(t *testing.T) { + t.Parallel() + initRes, _ := setup(t) req := httptest.NewRequest(http.MethodGet, "/api/features", nil) recorder := httptest.NewRecorder() @@ -94,7 +98,8 @@ func TestInitServer(t *testing.T) { require.False(t, resp.JobListHideArgsByDefault) }) - t.Run("set to true with true", func(t *testing.T) { + t.Run("SetToTrueWithTrue", func(t *testing.T) { //nolint:paralleltest + // Cannot be parallelized because of Setenv calls. t.Setenv("RIVER_JOB_LIST_HIDE_ARGS_BY_DEFAULT", "true") initRes, _ := setup(t) req := httptest.NewRequest(http.MethodGet, "/api/features", nil) @@ -110,7 +115,8 @@ func TestInitServer(t *testing.T) { require.True(t, resp.JobListHideArgsByDefault) }) - t.Run("set to true with 1", func(t *testing.T) { + t.Run("SetToTrueWith1", func(t *testing.T) { //nolint:paralleltest + // Cannot be parallelized because of Setenv calls. t.Setenv("RIVER_JOB_LIST_HIDE_ARGS_BY_DEFAULT", "1") initRes, _ := setup(t) req := httptest.NewRequest(http.MethodGet, "/api/features", nil)