File tree 2 files changed +14
-30
lines changed
2 files changed +14
-30
lines changed Original file line number Diff line number Diff line change @@ -6,20 +6,6 @@ permissions:
6
6
contents : read
7
7
8
8
jobs :
9
- lint :
10
- timeout-minutes : 5
11
- runs-on : ubuntu-latest
12
- steps :
13
- - uses : actions/checkout@v4
14
- with :
15
- persist-credentials : false
16
- - name : Setup node
17
- uses : actions/setup-node@v4
18
- with :
19
- node-version : 18
20
- cache : yarn
21
- - run : yarn install --frozen-lockfile
22
- - run : yarn lint
23
9
build :
24
10
timeout-minutes : 15
25
11
needs : lint
38
24
fail-fast : false
39
25
matrix :
40
26
node :
41
- - ' 16'
42
- - ' 18'
43
- - ' 20'
44
27
- ' 22'
45
- - ' 23'
46
28
os :
47
29
- ubuntu-latest
48
30
name : Node.js ${{ matrix.node }}
72
54
node-version : ${{ matrix.node }}
73
55
cache : yarn
74
56
- run : yarn install --frozen-lockfile
75
- - run : yarn test
57
+ - run : cd packages/pg-pool && yarn test
Original file line number Diff line number Diff line change @@ -25,23 +25,25 @@ describe('idle timeout', () => {
25
25
it (
26
26
'times out and removes clients when others are also removed' ,
27
27
co . wrap ( function * ( ) {
28
- let currentClient = 1
29
28
const pool = new Pool ( { idleTimeoutMillis : 10 } )
30
29
const clientA = yield pool . connect ( )
31
30
const clientB = yield pool . connect ( )
32
- clientA . release ( )
33
- clientB . release ( new Error ( ) )
31
+ clientA . release ( ) // this will put clientA in the idle pool
32
+ clientB . release ( new Error ( ) ) // an error will cause clientB to be removed immediately
34
33
35
34
const removal = new Promise ( ( resolve ) => {
36
- pool . on ( 'remove' , ( ) => {
35
+ pool . on ( 'remove' , ( client ) => {
36
+ // clientB's stream may take a while to close, so we may get a remove
37
+ // event for it
38
+ // we only want to handle the remove event for clientA when it times out
39
+ // due to being idle
40
+ if ( client !== clientA ) {
41
+ return
42
+ }
43
+
37
44
expect ( pool . idleCount ) . to . equal ( 0 )
38
45
expect ( pool . totalCount ) . to . equal ( 0 )
39
-
40
- if ( currentClient >= 2 ) {
41
- resolve ( )
42
- } else {
43
- currentClient ++
44
- }
46
+ resolve ( )
45
47
} )
46
48
} )
47
49
@@ -50,7 +52,7 @@ describe('idle timeout', () => {
50
52
try {
51
53
yield Promise . race ( [ removal , timeout ] )
52
54
} finally {
53
- yield pool . end ( )
55
+ pool . end ( )
54
56
}
55
57
} )
56
58
)
You can’t perform that action at this time.
0 commit comments