mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user