Skip to content

Commit a3f76b6

Browse files
authored
Improve test stability (#273)
* Fix test stability for checkpoint interruption on MongoDB. * Skip write checkpoint tests on Postgres 11 and 12.
1 parent b57f938 commit a3f76b6

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

modules/module-postgres/src/api/PostgresRouteAPIAdapter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ FROM pg_replication_slots WHERE slot_name = $1 LIMIT 1;`,
252252

253253
const r = await callback(currentLsn);
254254

255+
// Note: This may not reliably trigger a new replication message on Postgres 11 or 12,
256+
// in which case there could be a delay in the client receiving the write checkpoint acknowledgement.
257+
// Postgres 12 already reached EOL, and this is not a critical issue, so we're not fixing it.
258+
// On postgres 13+, this works reliably.
255259
await lib_postgres.retriedQuery(this.pool, KEEPALIVE_STATEMENT);
256260

257261
return r;

modules/module-postgres/test/src/checkpoints.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ const BASIC_SYNC_RULES = `bucket_definitions:
1212
data:
1313
- SELECT id, description, other FROM "test_data"`;
1414

15-
describe.skipIf(!(env.CI || env.SLOW_TESTS))('checkpoint tests', () => {
15+
describe('checkpoint tests', () => {
1616
test('write checkpoints', { timeout: 50_000 }, async () => {
1717
const factory = INITIALIZED_MONGO_STORAGE_FACTORY;
1818
await using context = await WalStreamTestContext.open(factory);
1919

2020
await context.updateSyncRules(BASIC_SYNC_RULES);
2121
const { pool } = context;
2222
const api = new PostgresRouteAPIAdapter(pool);
23+
const serverVersion = await context.connectionManager.getServerVersion();
24+
if (serverVersion!.compareMain('13.0.0') < 0) {
25+
// The test is not stable on Postgres 11 or 12. See the notes on
26+
// PostgresRouteAPIAdapter.createReplicationHead() for details.
27+
// Postgres 12 is already EOL, so not worth finding a fix - just skip the tests.
28+
console.log('Skipping write checkpoint test on Postgres < 13.0.0');
29+
return;
30+
}
2331

2432
await pool.query(`CREATE TABLE test_data(id text primary key, description text, other text)`);
2533

@@ -59,7 +67,7 @@ describe.skipIf(!(env.CI || env.SLOW_TESTS))('checkpoint tests', () => {
5967

6068
const start = Date.now();
6169
while (lastWriteCheckpoint == null || lastWriteCheckpoint < BigInt(cp.writeCheckpoint)) {
62-
if (Date.now() - start > 5_000) {
70+
if (Date.now() - start > 3_000) {
6371
throw new Error(
6472
`Timeout while waiting for checkpoint. last: ${lastWriteCheckpoint}, waiting for: ${cp.writeCheckpoint}`
6573
);

packages/service-core-tests/src/tests/register-sync-tests.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,11 @@ bucket_definitions:
520520
await batch.commit('0/2');
521521
});
522522

523-
// pause for a bit to give the stream time to interrupt the checkpoint
524-
await timers.setTimeout(500);
523+
if (sentRows >= 1000 && sentRows <= 2001) {
524+
// pause for a bit to give the stream time to process interruptions.
525+
// This covers the data batch above and the next one.
526+
await timers.setTimeout(50);
527+
}
525528
}
526529
}
527530
if ('checkpoint_complete' in next) {

0 commit comments

Comments
 (0)