UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

66 lines 2.7 kB
import { setupAppWithCustomConfig } from './helpers/test-helper.js'; import dbInit from './helpers/database-init.js'; let db; describe('DB is up', () => { beforeAll(async () => { db = await dbInit(); }); test('when checkDb is disabled, returns ready', async () => { const { request } = await setupAppWithCustomConfig(db.stores, undefined, db.rawDatabase); await request .get('/ready') .expect('Content-Type', /json/) .expect(200) .expect('{"health":"GOOD"}'); }); test('when checkDb is enabled, returns ready', async () => { const { request } = await setupAppWithCustomConfig(db.stores, { checkDbOnReady: true }, db.rawDatabase); await request.get('/ready').expect(200).expect('{"health":"GOOD"}'); }); test('fails fast when readiness query hangs', async () => { const { request } = await setupAppWithCustomConfig(db.stores, { checkDbOnReady: true }, db.rawDatabase); const pool = db.rawDatabase.client.pool; const originalAcquire = pool.acquire.bind(pool); pool.acquire = () => { const pending = originalAcquire(); pending.promise = pending.promise.then((conn) => { const originalQuery = conn.query; conn.query = (queryConfig, ...args) => { const isSelectOne = queryConfig?.toUpperCase() === 'SELECT 1'; if (isSelectOne) { return originalQuery.call(conn, 'SELECT pg_sleep(1)', ...args); } return originalQuery.call(conn, queryConfig, ...args); }; return conn; }); return pending; }; try { await request.get('/ready').expect(503); } finally { pool.acquire = originalAcquire; } }); }); describe('DB is down', () => { beforeAll(async () => { db = await dbInit(); }); test('when checkDb is disabled, returns readiness good', async () => { const { request } = await setupAppWithCustomConfig(db.stores, undefined, db.rawDatabase); await db.destroy(); await request .get('/ready') .expect('Content-Type', /json/) .expect(200) .expect('{"health":"GOOD"}'); }); test('when checkDb is enabled, fails readiness check', async () => { const { request } = await setupAppWithCustomConfig(db.stores, { checkDbOnReady: true }, db.rawDatabase); await db.destroy(); await request.get('/ready').expect(503); }); }); //# sourceMappingURL=ready.e2e.test.js.map