Support for concurrent databases (node.js)
First of all — awesome work! Having lightweight on-the-fly instances of PostgreSQL is a game changer.
We use pglite to run our DB tests. Our test runner is AVA. Even though AVA runs test cases in the same file in parallel, we find that pglite tests always complete serially. It appears that pglite only permits 1 in-memory DB to be used at a time.
Can pglite support multiple in-mem databases being created/connected/queried at once? Specifically for node.js, as the browser might understandably have different constraints.
What would it take for this to work?
Example usage:
// set up DB named neondb (required by migrations)
const db0 = await PGlite.create();
await db0.query('CREATE DATABASE neondb');
const dump0 = await db0.dumpDataDir();
await db0.close();
// apply migrations
const db1 = await PGlite.create({
loadDataDir: dump0,
database: 'neondb',
extensions: {
vector,
},
});
await applyMigrations(db1);
const dump1 = await db1.dumpDataDir();
await db1.close();
// the above runs once per test suite (reused)
// the below runs once per test case
export async function getTestSql(t) {
const db = await PGlite.create({
loadDataDir: dump1,
database: 'neondb',
extensions: {
vector,
},
});
t.teardown(async () => {
await db.close();
});
...
}
I'm having the same issue with jest and PGLite (with typeorm driver). If i run all tests in parallel, I'm getting tons of errors (timeous, weird things), but running all in sequence solve all of them (but our tests suite from 2 min to over 6 min)
Is there any update on this? We'd love to use it for testing but the concurrency issue is a stopper.
Thanks!
I'm also running into this in my tests. Some of my tests need multiple pglite clients. It seems that starting more than 1 pglite client with dataDir: "memory://" causes all sorts of undefined behavior. Is there a correct way to run multiple in-memory pglite instances?
Hey everyone, could you please see if this is still an issue with the latest version?
Just to chime in, I'm still having this issue in the latest version. Running into the same issue with Bun's test runner, which automatically runs tests from all files concurrently.
We use vitest on node which also runs tests in parallel and we don't see this behavior.