avajs / ava

Node.js test runner that lets you develop with confidence 🚀
MIT License
20.73k stars 1.4k forks source link

timeouts with testcontainers #3332

Closed sombriks closed 3 months ago

sombriks commented 3 months ago

I am using ava combined with testcontainers so i can avoid sqlite and dialect issues for a sample app consuming postgresql.

I have proper test.before and test.after.always hooks, since i plan to keep the database container alive until the end of the test suite:

// imports

test.before(async t => {
    t.context.postgres = await new PostgreSqlContainer('postgres:16.3-alpine3.20')
        .withDatabase(process.env.PG_DATABASE)
        .withUsername(process.env.PG_USERNAME)
        .withPassword(process.env.PG_PASSWORD)
        .withBindMounts([{
            source: resolve('../sample-kanban-jvm/src/test/resources/initial-state.sql'),
            target: '/docker-entrypoint-initdb.d/init.sql',
        }])
        .start();
    t.context.db = prepareDatabase(t.context.postgres.getConnectionUri());
    const {app} = prepareApp({db: t.context.db});
    t.context.callback = app.callback();
});

test.after.always(async t => {
    await t.context.db.destroy();
    await t.context.postgres.stop({timeout: 500});
});

// test cases

It is however hanging and ending with timeout, even with all tests being successful.

Please check the full sample code here.

sombriks commented 3 months ago

False alarm, i was using the live postgres container instead of the testcontainer one. sample code corrected, if it worth anything