@@ -840,6 +840,7 @@ export const createIntegrationTests = (
840
840
t . deepEqual ( pool . state ( ) , {
841
841
acquiredConnections : 0 ,
842
842
idleConnections : 0 ,
843
+ pendingConnections : 0 ,
843
844
pendingDestroyConnections : 0 ,
844
845
pendingReleaseConnections : 0 ,
845
846
state : 'ACTIVE' ,
@@ -851,6 +852,7 @@ export const createIntegrationTests = (
851
852
t . deepEqual ( pool . state ( ) , {
852
853
acquiredConnections : 0 ,
853
854
idleConnections : 0 ,
855
+ pendingConnections : 0 ,
854
856
pendingDestroyConnections : 0 ,
855
857
pendingReleaseConnections : 0 ,
856
858
state : 'ENDED' ,
@@ -867,6 +869,7 @@ export const createIntegrationTests = (
867
869
t . deepEqual ( pool . state ( ) , {
868
870
acquiredConnections : 0 ,
869
871
idleConnections : 0 ,
872
+ pendingConnections : 0 ,
870
873
pendingDestroyConnections : 0 ,
871
874
pendingReleaseConnections : 0 ,
872
875
state : 'ACTIVE' ,
@@ -880,6 +883,7 @@ export const createIntegrationTests = (
880
883
t . deepEqual ( pool . state ( ) , {
881
884
acquiredConnections : 0 ,
882
885
idleConnections : 1 ,
886
+ pendingConnections : 0 ,
883
887
pendingDestroyConnections : 0 ,
884
888
pendingReleaseConnections : 0 ,
885
889
state : 'ACTIVE' ,
@@ -891,6 +895,7 @@ export const createIntegrationTests = (
891
895
t . deepEqual ( pool . state ( ) , {
892
896
acquiredConnections : 0 ,
893
897
idleConnections : 0 ,
898
+ pendingConnections : 0 ,
894
899
pendingDestroyConnections : 0 ,
895
900
pendingReleaseConnections : 0 ,
896
901
state : 'ENDED' ,
@@ -906,6 +911,7 @@ export const createIntegrationTests = (
906
911
t . deepEqual ( pool . state ( ) , {
907
912
acquiredConnections : 0 ,
908
913
idleConnections : 0 ,
914
+ pendingConnections : 0 ,
909
915
pendingDestroyConnections : 0 ,
910
916
pendingReleaseConnections : 0 ,
911
917
state : 'ACTIVE' ,
@@ -921,6 +927,7 @@ export const createIntegrationTests = (
921
927
t . deepEqual ( pool . state ( ) , {
922
928
acquiredConnections : 1 ,
923
929
idleConnections : 0 ,
930
+ pendingConnections : 0 ,
924
931
pendingDestroyConnections : 0 ,
925
932
pendingReleaseConnections : 0 ,
926
933
state : 'ACTIVE' ,
@@ -932,6 +939,7 @@ export const createIntegrationTests = (
932
939
t . deepEqual ( pool . state ( ) , {
933
940
acquiredConnections : 0 ,
934
941
idleConnections : 0 ,
942
+ pendingConnections : 0 ,
935
943
pendingDestroyConnections : 0 ,
936
944
pendingReleaseConnections : 0 ,
937
945
state : 'ENDED' ,
@@ -951,6 +959,7 @@ export const createIntegrationTests = (
951
959
t . deepEqual ( pool . state ( ) , {
952
960
acquiredConnections : 0 ,
953
961
idleConnections : 0 ,
962
+ pendingConnections : 0 ,
954
963
pendingDestroyConnections : 0 ,
955
964
pendingReleaseConnections : 0 ,
956
965
state : 'ACTIVE' ,
@@ -978,6 +987,7 @@ export const createIntegrationTests = (
978
987
t . deepEqual ( pool . state ( ) , {
979
988
acquiredConnections : 0 ,
980
989
idleConnections : 5 ,
990
+ pendingConnections : 0 ,
981
991
pendingDestroyConnections : 0 ,
982
992
pendingReleaseConnections : 0 ,
983
993
state : 'ACTIVE' ,
@@ -989,6 +999,7 @@ export const createIntegrationTests = (
989
999
t . deepEqual ( pool . state ( ) , {
990
1000
acquiredConnections : 0 ,
991
1001
idleConnections : 0 ,
1002
+ pendingConnections : 0 ,
992
1003
pendingDestroyConnections : 0 ,
993
1004
pendingReleaseConnections : 0 ,
994
1005
state : 'ENDED' ,
@@ -1442,6 +1453,7 @@ export const createIntegrationTests = (
1442
1453
{
1443
1454
acquiredConnections : 0 ,
1444
1455
idleConnections : 0 ,
1456
+ pendingConnections : 0 ,
1445
1457
pendingDestroyConnections : 0 ,
1446
1458
pendingReleaseConnections : 0 ,
1447
1459
state : 'ACTIVE' ,
@@ -1466,6 +1478,7 @@ export const createIntegrationTests = (
1466
1478
{
1467
1479
acquiredConnections : 1 ,
1468
1480
idleConnections : 0 ,
1481
+ pendingConnections : 0 ,
1469
1482
pendingDestroyConnections : 0 ,
1470
1483
pendingReleaseConnections : 0 ,
1471
1484
state : 'ACTIVE' ,
@@ -2004,6 +2017,7 @@ export const createIntegrationTests = (
2004
2017
{
2005
2018
acquiredConnections : 0 ,
2006
2019
idleConnections : 0 ,
2020
+ pendingConnections : 0 ,
2007
2021
pendingDestroyConnections : 0 ,
2008
2022
pendingReleaseConnections : 0 ,
2009
2023
state : 'ACTIVE' ,
@@ -2021,6 +2035,7 @@ export const createIntegrationTests = (
2021
2035
{
2022
2036
acquiredConnections : 0 ,
2023
2037
idleConnections : 1 ,
2038
+ pendingConnections : 0 ,
2024
2039
pendingDestroyConnections : 0 ,
2025
2040
pendingReleaseConnections : 0 ,
2026
2041
state : 'ACTIVE' ,
@@ -2036,6 +2051,7 @@ export const createIntegrationTests = (
2036
2051
{
2037
2052
acquiredConnections : 0 ,
2038
2053
idleConnections : 0 ,
2054
+ pendingConnections : 0 ,
2039
2055
pendingDestroyConnections : 0 ,
2040
2056
pendingReleaseConnections : 0 ,
2041
2057
state : 'ACTIVE' ,
@@ -2175,6 +2191,7 @@ export const createIntegrationTests = (
2175
2191
t . like ( pool . state ( ) , {
2176
2192
acquiredConnections : 0 ,
2177
2193
idleConnections : 0 ,
2194
+ pendingConnections : 0 ,
2178
2195
pendingDestroyConnections : 0 ,
2179
2196
pendingReleaseConnections : 0 ,
2180
2197
waitingClients : 0 ,
@@ -2193,6 +2210,7 @@ export const createIntegrationTests = (
2193
2210
t . like ( pool . state ( ) , {
2194
2211
acquiredConnections : 0 ,
2195
2212
idleConnections : 0 ,
2213
+ pendingConnections : 0 ,
2196
2214
pendingDestroyConnections : 0 ,
2197
2215
pendingReleaseConnections : 0 ,
2198
2216
waitingClients : 0 ,
@@ -2216,6 +2234,7 @@ export const createIntegrationTests = (
2216
2234
acquiredConnections : 0 ,
2217
2235
// TODO we might want to add an option to warm up the pool, in which case this value should be 1
2218
2236
idleConnections : 0 ,
2237
+ pendingConnections : 0 ,
2219
2238
pendingDestroyConnections : 0 ,
2220
2239
pendingReleaseConnections : 0 ,
2221
2240
state : 'ACTIVE' ,
@@ -2233,6 +2252,7 @@ export const createIntegrationTests = (
2233
2252
{
2234
2253
acquiredConnections : 0 ,
2235
2254
idleConnections : 1 ,
2255
+ pendingConnections : 0 ,
2236
2256
pendingDestroyConnections : 0 ,
2237
2257
pendingReleaseConnections : 0 ,
2238
2258
state : 'ACTIVE' ,
@@ -2248,6 +2268,7 @@ export const createIntegrationTests = (
2248
2268
{
2249
2269
acquiredConnections : 0 ,
2250
2270
idleConnections : 1 ,
2271
+ pendingConnections : 0 ,
2251
2272
pendingDestroyConnections : 0 ,
2252
2273
pendingReleaseConnections : 0 ,
2253
2274
state : 'ACTIVE' ,
@@ -2259,6 +2280,67 @@ export const createIntegrationTests = (
2259
2280
await pool . end ( ) ;
2260
2281
} ) ;
2261
2282
2283
+ test ( 'destroy creates a new connection to be used by waiting client' , async ( t ) => {
2284
+ const pool = await createPool ( t . context . dsn , {
2285
+ driverFactory,
2286
+ idleTimeout : 30_000 ,
2287
+ maximumPoolSize : 1 ,
2288
+ minimumPoolSize : 1 ,
2289
+ } ) ;
2290
+
2291
+ pool
2292
+ . query (
2293
+ sql . unsafe `
2294
+ DO $$
2295
+ BEGIN
2296
+ PERFORM pg_sleep(1); -- Sleep for 1 second
2297
+ RAISE EXCEPTION 'Test error after 1 second delay';
2298
+ END $$;
2299
+ ` ,
2300
+ )
2301
+ // eslint-disable-next-line promise/prefer-await-to-then
2302
+ . catch ( ( ) => {
2303
+ // Ignoring intentional error
2304
+ } ) ;
2305
+
2306
+ const waitingClientPromise = pool . oneFirst ( sql . unsafe `
2307
+ SELECT 1
2308
+ ` ) ;
2309
+
2310
+ t . deepEqual (
2311
+ pool . state ( ) ,
2312
+ {
2313
+ acquiredConnections : 0 ,
2314
+ idleConnections : 0 ,
2315
+ pendingConnections : 1 ,
2316
+ pendingDestroyConnections : 0 ,
2317
+ pendingReleaseConnections : 0 ,
2318
+ state : 'ACTIVE' ,
2319
+ waitingClients : 1 ,
2320
+ } ,
2321
+ 'pool state has waiting client' ,
2322
+ ) ;
2323
+
2324
+ const waitingClientResult = await waitingClientPromise ;
2325
+ t . is ( waitingClientResult , 1 ) ;
2326
+
2327
+ t . deepEqual (
2328
+ pool . state ( ) ,
2329
+ {
2330
+ acquiredConnections : 0 ,
2331
+ idleConnections : 1 ,
2332
+ pendingConnections : 0 ,
2333
+ pendingDestroyConnections : 0 ,
2334
+ pendingReleaseConnections : 0 ,
2335
+ state : 'ACTIVE' ,
2336
+ waitingClients : 0 ,
2337
+ } ,
2338
+ 'pool state after all queries complete' ,
2339
+ ) ;
2340
+
2341
+ await pool . end ( ) ;
2342
+ } ) ;
2343
+
2262
2344
test ( 'retains explicit transaction beyond the idle timeout' , async ( t ) => {
2263
2345
const pool = await createPool ( t . context . dsn , {
2264
2346
driverFactory,
@@ -2363,6 +2445,7 @@ export const createIntegrationTests = (
2363
2445
{
2364
2446
acquiredConnections : 0 ,
2365
2447
idleConnections : 1 ,
2448
+ pendingConnections : 0 ,
2366
2449
pendingDestroyConnections : 0 ,
2367
2450
pendingReleaseConnections : 0 ,
2368
2451
state : 'ACTIVE' ,
@@ -2408,6 +2491,7 @@ export const createIntegrationTests = (
2408
2491
t . deepEqual ( pool . state ( ) , {
2409
2492
acquiredConnections : 2 ,
2410
2493
idleConnections : 0 ,
2494
+ pendingConnections : 0 ,
2411
2495
pendingDestroyConnections : 0 ,
2412
2496
pendingReleaseConnections : 0 ,
2413
2497
state : 'ACTIVE' ,
0 commit comments