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
This commit is contained in:
Mathias Fredriksson
2026-03-13 14:03:40 +02:00
committed by GitHub
parent a5400b2208
commit ff156772f2
+4 -8
View File
@@ -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()