mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
DittoPglite: test that queries reject after it's closed
This commit is contained in:
parent
4e0479f7c8
commit
0b72533b05
2 changed files with 24 additions and 6 deletions
|
|
@ -1,14 +1,22 @@
|
|||
import { assertEquals } from '@std/assert';
|
||||
import { assertEquals, assertRejects } from '@std/assert';
|
||||
|
||||
import { DittoPglite } from './DittoPglite.ts';
|
||||
|
||||
Deno.test('DittoPglite', async () => {
|
||||
const db = new DittoPglite('memory://');
|
||||
await using db = new DittoPglite('memory://');
|
||||
await db.migrate();
|
||||
|
||||
assertEquals(db.poolSize, 1);
|
||||
assertEquals(db.availableConnections, 1);
|
||||
|
||||
await db.kysely.destroy();
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
Deno.test('DittoPglite query after closing', async () => {
|
||||
const db = new DittoPglite('memory://');
|
||||
await db[Symbol.asyncDispose]();
|
||||
|
||||
await assertRejects(
|
||||
() => db.kysely.selectFrom('nostr_events').selectAll().execute(),
|
||||
Error,
|
||||
'PGlite is closed',
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -47,6 +47,16 @@ export class DittoPglite implements DittoDB {
|
|||
}
|
||||
|
||||
async [Symbol.asyncDispose](): Promise<void> {
|
||||
try {
|
||||
// FIXME: `kysely.destroy()` calls `pglite.close()` internally, but it doesn't work.
|
||||
await this.pglite.close();
|
||||
await this.kysely.destroy();
|
||||
} catch (e) {
|
||||
if (e instanceof Error && e.message === 'PGlite is closed') {
|
||||
// Make dispose idempotent.
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue