From ff156772f2022fb27acabdd8347d6c3e4faf9c31 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 13 Mar 2026 14:03:40 +0200 Subject: [PATCH] fix(coderd/database): move context creation to first use in migration tests (#23032) The timeout was started before the unbounded Stepper loop, so under CI load the deadline could expire before reaching the operations that actually use it. Also bumps TestMigration000387 from WaitLong to WaitSuperLong. Fixes coder/internal#1398 --- coderd/database/migrations/migrate_test.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/coderd/database/migrations/migrate_test.go b/coderd/database/migrations/migrate_test.go index 0260bbc10c..19f1a40755 100644 --- a/coderd/database/migrations/migrate_test.go +++ b/coderd/database/migrations/migrate_test.go @@ -295,10 +295,6 @@ func TestMigrateUpWithFixtures(t *testing.T) { db := testSQLDB(t) - // This test occasionally timed out in CI, which is understandable - // considering the amount of migrations and fixtures we have. - ctx := testutil.Context(t, testutil.WaitSuperLong) - // Prepare database for stepping up. err := migrations.Down(db) require.NoError(t, err) @@ -336,6 +332,8 @@ func TestMigrateUpWithFixtures(t *testing.T) { t.Logf("migrated to version %d, fixture version %d", version, fixtureVer) } + ctx := testutil.Context(t, testutil.WaitSuperLong) + // Gather number of rows for all existing tables // at the end of the migrations and fixtures. var tables pq.StringArray @@ -373,9 +371,6 @@ func TestMigration000362AggregateUsageEvents(t *testing.T) { const migrationVersion = 362 - // Similarly to the other test, this test will probably time out in CI. - ctx := testutil.Context(t, testutil.WaitSuperLong) - sqlDB := testSQLDB(t) db := database.New(sqlDB) @@ -430,6 +425,7 @@ func TestMigration000362AggregateUsageEvents(t *testing.T) { }, } + ctx := testutil.Context(t, testutil.WaitSuperLong) for _, usageEvent := range usageEvents { err := db.InsertUsageEvent(ctx, database.InsertUsageEventParams{ ID: uuid.New().String(), @@ -494,7 +490,6 @@ func TestMigration000387MigrateTaskWorkspaces(t *testing.T) { const migrationVersion = 387 - ctx := testutil.Context(t, testutil.WaitLong) sqlDB := testSQLDB(t) // Migrate up to the migration before the task workspace migration. @@ -562,6 +557,7 @@ func TestMigration000387MigrateTaskWorkspaces(t *testing.T) { wsAntBuild1ID := uuid.New() // Create all fixtures in a single transaction. + ctx := testutil.Context(t, testutil.WaitSuperLong) tx, err := sqlDB.BeginTx(ctx, nil) require.NoError(t, err) defer tx.Rollback()