From 6cfc7b7e91d894699ffee09287c7e427ff14a511 Mon Sep 17 00:00:00 2001 From: Zai Shi Date: Fri, 1 Aug 2025 10:51:05 -0700 Subject: [PATCH] improve auto-migration test --- .../src/auto-migrations/auto-migration.tests.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/backend/src/auto-migrations/auto-migration.tests.ts b/apps/backend/src/auto-migrations/auto-migration.tests.ts index 53518d9c7..25df3e732 100644 --- a/apps/backend/src/auto-migrations/auto-migration.tests.ts +++ b/apps/backend/src/auto-migrations/auto-migration.tests.ts @@ -201,8 +201,8 @@ import.meta.vitest?.test("applies migrations concurrently", runTest(async ({ exp const l1 = result1.newlyAppliedMigrationNames.length; const l2 = result2.newlyAppliedMigrationNames.length; - // One of the two migrations should be applied, but not both - expect((l1 === 2 && l2 === 0) || (l1 === 0 && l2 === 2)).toBe(true); + // the sum of the two should be 2 + expect(l1 + l2).toBe(2); await prismaClient.$executeRaw`INSERT INTO test (name) VALUES ('test_value')`; const result = await prismaClient.$queryRaw`SELECT name FROM test` as { name: string }[]; @@ -222,9 +222,12 @@ import.meta.vitest?.test("applies migrations concurrently with 20 concurrent mig const appliedCounts = results.map(result => result.newlyAppliedMigrationNames.length); // Only one of the promises should have applied all migrations, the rest should have applied none - const appliedCounts = results.map(result => result.newlyAppliedMigrationNames.length); - const appliedSum = appliedCounts.reduce((sum, count) => sum + count, 0); + const successfulApplies = appliedCounts.filter(count => count > 0); + const emptyApplies = appliedCounts.filter(count => count === 0); + + const appliedSum = successfulApplies.reduce((sum, count) => sum + count, 0); expect(appliedSum).toBe(2); + expect(emptyApplies.length).toBe(19); await prismaClient.$executeRaw`INSERT INTO test (name) VALUES ('test_value')`; const result = await prismaClient.$queryRaw`SELECT name FROM test` as { name: string }[];