@@ -8,10 +8,12 @@ import { vi } from 'vitest'
88import {
99 getPgCancelConnectionTarget ,
1010 PgPoolExecutor ,
11+ PgPoolManager ,
1112 PgPoolStrategy ,
1213 PgTenantConnection ,
1314 PgTransaction ,
1415} from './pg-connection'
16+ import type { TenantConnectionOptions } from './pool'
1517
1618class TestablePgPoolStrategy extends PgPoolStrategy {
1719 getCurrentPoolForTest ( ) : Pool {
@@ -24,8 +26,8 @@ class TestablePgPoolStrategy extends PgPoolStrategy {
2426}
2527
2628function createPoolStrategySettings (
27- overrides : Partial < ConstructorParameters < typeof PgPoolStrategy > [ 0 ] > = { }
28- ) : ConstructorParameters < typeof PgPoolStrategy > [ 0 ] {
29+ overrides : Partial < TenantConnectionOptions > = { }
30+ ) : TenantConnectionOptions {
2931 return {
3032 tenantId : 'pg-pool-strategy-test' ,
3133 dbUrl : 'postgres://postgres:postgres@localhost:5432/postgres' ,
@@ -741,6 +743,38 @@ describe('PgTenantConnection', () => {
741743 } )
742744} )
743745
746+ describe ( 'PgPoolManager' , ( ) => {
747+ it ( 'caches strategies without retaining request-scoped options' , async ( ) => {
748+ const manager = new PgPoolManager ( )
749+ const tenantId = 'pg-pool-manager-prune-test'
750+ const request = { operation : { type : 'upload' } }
751+
752+ const strategy = manager . getPool (
753+ createPoolStrategySettings ( {
754+ tenantId,
755+ headers : { authorization : 'Bearer secret' } ,
756+ method : 'POST' ,
757+ path : '/object/bucket/key' ,
758+ operation : ( ) => request . operation . type ,
759+ } )
760+ )
761+
762+ try {
763+ const retained = ( strategy as unknown as { options : Record < string , unknown > } ) . options
764+ expect ( Object . keys ( retained ) . sort ( ) ) . toEqual ( [
765+ 'clusterSize' ,
766+ 'dbUrl' ,
767+ 'isExternalPool' ,
768+ 'maxConnections' ,
769+ 'numWorkers' ,
770+ 'tenantId' ,
771+ ] )
772+ } finally {
773+ await manager . destroy ( tenantId )
774+ }
775+ } )
776+ } )
777+
744778describe ( 'PgPoolStrategy' , ( ) => {
745779 it ( 'logs idle pg pool errors without rethrowing them' , async ( ) => {
746780 const strategy = new TestablePgPoolStrategy ( createPoolStrategySettings ( ) )
0 commit comments