Skip to content

Commit ebcb604

Browse files
committed
feat: enhance test isolation by using unique schemas for concurrent tests
1 parent 13879f8 commit ebcb604

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

backend/test/ava-tests/non-saas-tests/non-saas-ai-settings-creation-stream-e2e.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,13 @@ test.serial(`${currentTest} streams human-readable progress and ends with a comp
193193

194194
test.serial(`${currentTest} streams a no-new-tables message when settings already exist`, async (t) => {
195195
const connectionToTestDB = getTestData(mockFactory).connectionToPostgresSchema;
196+
// Use a schema unique to this test so concurrently-running test files (which share the
197+
// same Postgres and the default "test_schema") cannot inject new tables between the two
198+
// scans below, which would otherwise make the "no new tables" assertion flaky.
199+
const isolatedSchema = `ai_stream_${faker.string.alphanumeric(10).toLowerCase()}`;
200+
connectionToTestDB.schema = isolatedSchema;
196201
const { token } = await registerUserAndReturnUserInfo(app);
197-
const { testTableName } = await createTestPostgresTableWithSchema(connectionToTestDB);
202+
const { testTableName } = await createTestPostgresTableWithSchema(connectionToTestDB, 42, 'Vasia', isolatedSchema);
198203
testTables.push(testTableName);
199204

200205
const createConnectionResponse = await request(app.getHttpServer())

backend/test/utils/create-test-table.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,10 @@ export async function createTestPostgresTableWithSchema(
569569
connectionParams: any,
570570
testEntitiesSeedsCount = 42,
571571
testSearchedUserName = 'Vasia',
572+
testSchema = 'test_schema',
572573
) {
573574
const Knex = getTestKnex(connectionParams);
574575
const testTableName = getRandomTestTableName();
575-
const testSchema = 'test_schema';
576576
await Knex.schema.dropTableIfExists(testTableName);
577577

578578
const testTableColumnName = 'name';
@@ -611,6 +611,7 @@ export async function createTestPostgresTableWithSchema(
611611
testTableColumnName: testTableColumnName,
612612
testTableSecondColumnName: testTableSecondColumnName,
613613
testEntitiesSeedsCount: testEntitiesSeedsCount,
614+
testSchema: testSchema,
614615
};
615616
}
616617

0 commit comments

Comments
 (0)