Files
ipal-kit/test/transactionPoolInTx.test.ts
Radosław SmolińskiandClaude Opus 5.5 32bb542e8e Postgres: many requests at once no longer stop the site
Each Payload transaction holds a pool connection; code inside it that runs
without its req needs a second one (Payload's own forgotPassword, the mail
adapter's settings read and status write, payload.kv). With the default pool
of 10, ten form submissions or ten "forgot password" requests at once held
every connection and waited for good.

- connectionReserve (default on): at most pool size − reserve transactions
  open at once; a waiter older than a second may use all but the last
  connection. Building blocks in modules/database/transactions.ts.
- Form e-mails go out right after the submission's transaction commits, in
  the same request (forms.emailsInTransaction: true = the old way).
- recordIntegrationStatus merges identical writes and does not hold its
  caller while the pool is busy.
- SMTP time-outs: 10 s connect, 30 s greeting, 60 s silence (smtp.timeouts).

Tests on Postgres 17: 30 submissions, 30 forgot-password, and both against
an SMTP server that never answers, finish while a page answers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-26 00:33:07 +01:00

32 lines
1.4 KiB
TypeScript

/**
* forms.emailsInTransaction: true — the e-mails of a form go out inside the submission's transaction, as
* before 1.17.0. Postgres only (IPAL_TEST_POSTGRES_URI); its own file, because one test process pushes the
* schema of one Payload (test/transactionPool.test.ts has the default).
*/
import { describe, expect, test, vi } from 'vitest'
import { submitForm } from '../src/modules/forms/submitForm.js'
import { site } from './transactionPoolSite.js'
vi.mock('server-only', () => ({}))
describe.runIf(Boolean(process.env.IPAL_TEST_POSTGRES_URI))('Postgres, forms.emailsInTransaction: true', () => {
test('forms.emailsInTransaction: true sends inside the transaction, as before 1.17.0', async () => {
const other = await site('txpoolin', { emailsInTransaction: true })
const send = vi.spyOn(other.payload, 'sendEmail')
const seen: number[] = []
send.mockImplementation(async () => {
seen.push((await other.payload.count({ collection: 'form-submissions' as never })).totalDocs)
return { sent: true }
})
try {
const result = await submitForm({ data: { email: '[email protected]', message: 'm' }, formId: other.formId, maxPerMinute: 0, payload: other.payload })
expect(result).toMatchObject({ success: true })
expect(seen).toEqual([0, 0]) // not committed yet when the e-mails went out
} finally {
send.mockRestore()
await other.payload.destroy()
}
}, 60_000)
})