fix: address review of the Postgres move

- close the pool on SIGTERM before exiting; query_timeout on the pool
- SIGTERM test fails instead of hanging; test cleanup in finally
- preStop sleep so rollouts don't drop form posts; Postgres startupProbe
- CI step timeout, clear error if test Postgres never starts, remove test image
- export stops on SQL errors; README note on changing the DB password

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfmHGGiYUjNcvJoyzdf
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 11:59:55 +08:00
1 parent 20e07e9d80
commit ad5996283e
7 files changed
+42 -14

No files matched your search

+18 -8
View File
@@ -29,7 +29,10 @@ before(async () => {
base = `http://127.0.0.1:${server.address().port}`;
});
after(async () => {
await new Promise((r) => server.close(r));
if (server) {
await new Promise((r) => server.close(r));
await server.pool.end();
}
await admin.query(`DROP SCHEMA ${schema} CASCADE`);
await admin.end();
});
@@ -119,22 +122,29 @@ test('honeypot submission is accepted but not stored', async () => {
test('missing page file fails at startup, not on a request', async () => {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ins-nopage-'));
fs.copyFileSync(path.join(__dirname, 'server.js'), path.join(tmp, 'server.js'));
fs.symlinkSync(path.join(__dirname, 'node_modules'), path.join(tmp, 'node_modules'));
const { createServer: create } = require(path.join(tmp, 'server.js'));
await assert.rejects(() => create(dbUrl), /ENOENT/);
fs.rmSync(tmp, { recursive: true, force: true });
try {
fs.copyFileSync(path.join(__dirname, 'server.js'), path.join(tmp, 'server.js'));
fs.symlinkSync(path.join(__dirname, 'node_modules'), path.join(tmp, 'node_modules'));
const { createServer: create } = require(path.join(tmp, 'server.js'));
await assert.rejects(() => create(dbUrl), /ENOENT/);
} finally {
fs.rmSync(tmp, { recursive: true, force: true });
}
});
test('unreachable database fails at startup', async () => {
await assert.rejects(() => createServer('postgres://nobody:nothing@127.0.0.1:1/none'));
});
test('exits promptly on SIGTERM', async () => {
test('exits promptly on SIGTERM', { timeout: 15000 }, async () => {
const child = spawn(process.execPath, [path.join(__dirname, 'server.js')], {
env: { ...process.env, PORT: '0', DATABASE_URL: dbUrl },
});
await new Promise((r) => child.stdout.once('data', r));
// fail instead of hanging if the server dies before it starts listening
await new Promise((resolve, reject) => {
child.stdout.once('data', resolve);
child.once('exit', (c) => reject(new Error(`server exited early with code ${c}`)));
});
const start = Date.now();
child.kill('SIGTERM');
const code = await new Promise((r) => child.on('exit', (c) => r(c)));