Skip to content

Commit 22812c1

Browse files
authored
Made automations test database more reliable (TryGhost#28520)
ref https://github.com/TryGhost/Ghost/actions/runs/27375153163/ This database will soon be removed, but let's make it a little more reliable in the meantime because CI is flaky. Let's ensure there's just one connection at a time.
1 parent fab1248 commit 22812c1

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

ghost/core/core/server/services/automations/automations-api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ const editAutomationDataSchema = z.object({
7171
edges: z.array(edgeSchema)
7272
}).strict();
7373

74-
let testDatabase: Knex | null = null;
74+
let testDatabasePromise: Promise<Knex> | null = null;
7575

7676
const repository = createFakeDatabaseAutomationsRepository({
7777
getDatabase: async () => {
7878
if (process.env.NODE_ENV?.startsWith('testing')) {
79-
testDatabase ??= await temporaryFakeAutomationsDatabase.createTemporaryFakeAutomationsDatabase();
80-
return testDatabase;
79+
testDatabasePromise ??= temporaryFakeAutomationsDatabase.createTemporaryFakeAutomationsDatabase();
80+
return await testDatabasePromise;
8181
}
8282
return await temporaryFakeAutomationsDatabase.getTemporaryFakeAutomationsDatabase();
8383
}
@@ -320,6 +320,6 @@ export async function retryStep(...args: Parameters<AutomationsRepository['retry
320320

321321
export function _resetTestDatabase() {
322322
if (process.env.NODE_ENV?.startsWith('testing')) {
323-
testDatabase = null;
323+
testDatabasePromise = null;
324324
}
325325
}

ghost/core/core/server/services/automations/temporary-fake-database.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export async function createTemporaryFakeAutomationsDatabase(): Promise<Knex> {
2020
connection: {
2121
filename: ':memory:'
2222
},
23+
pool: {
24+
min: 1,
25+
max: 1
26+
},
2327
useNullAsDefault: true
2428
});
2529

0 commit comments

Comments
 (0)