11/**
22 * @vitest -environment node
33 *
4- * Uses a disposable schema in local PostgreSQL 17 +. The paused callback models
4+ * Uses a disposable schema in local PostgreSQL 15 +. The paused callback models
55 * a client that stops progressing after writing usage but before COMMIT; the
66 * database must release its locks without waiting for that client to resume.
77 */
@@ -65,6 +65,7 @@ interface PausedTransaction {
6565}
6666
6767let nextPause : PausedTransaction | undefined
68+ let holderTimeoutSetting = 'transaction_timeout'
6869
6970function pauseNextTransaction ( lockOnly = false ) : PausedTransaction {
7071 const pause = { reached : deferred ( ) , release : deferred ( ) , lockOnly }
@@ -107,9 +108,14 @@ afterAll(async () => {
107108describe . skipIf ( ! databaseUrl ) ( 'Cumulative billing with PostgreSQL' , ( ) => {
108109 beforeAll ( async ( ) => {
109110 if ( ! connection || ! database ) throw new Error ( 'PostgreSQL fixture is unavailable' )
110- const [ version ] =
111- await connection `select current_setting('server_version_num')::integer as version`
112- expect ( version . version ) . toBeGreaterThanOrEqual ( 170000 )
111+ const [ version ] = await connection `
112+ select current_setting('server_version_num')::integer as version,
113+ current_setting('transaction_timeout', true) is not null as has_transaction_timeout
114+ `
115+ expect ( version . version ) . toBeGreaterThanOrEqual ( 150000 )
116+ holderTimeoutSetting = version . has_transaction_timeout
117+ ? 'transaction_timeout'
118+ : 'idle_in_transaction_session_timeout'
113119 await connection . unsafe ( `CREATE SCHEMA "${ schemaName } "` )
114120 await connection . unsafe ( `
115121 CREATE TABLE usage_log (
@@ -132,7 +138,7 @@ describe.skipIf(!databaseUrl)('Cumulative billing with PostgreSQL', () => {
132138 if ( pause ) {
133139 if ( pause . lockOnly ) {
134140 /** Reproduce the old policy: lock_timeout does not expire an idle holder. */
135- await tx . execute ( sql `select set_config('transaction_timeout' , '0', true)` )
141+ await tx . execute ( sql `select set_config(${ holderTimeoutSetting } , '0', true)` )
136142 }
137143 pause . reached . resolve ( )
138144 await pause . release . promise
@@ -164,7 +170,7 @@ describe.skipIf(!databaseUrl)('Cumulative billing with PostgreSQL', () => {
164170 const resumed = deferred ( )
165171 let resumedError : unknown
166172 const holder = pool . begin ( async ( tx ) => {
167- await tx `select set_config('transaction_timeout' , '150ms', true)`
173+ await tx `select set_config(${ holderTimeoutSetting } , '150ms', true)`
168174 await tx `select 1`
169175 await release . promise
170176 try {
0 commit comments