Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f087b5e

Browse files
committed
fix: handle idle timeout test data race
1 parent 243ffee commit f087b5e

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

‎.github/workflows/ci.yml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@ permissions:
66
contents: read
77

88
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
239
build:
2410
timeout-minutes: 15
2511
needs: lint
@@ -38,11 +24,7 @@ jobs:
3824
fail-fast: false
3925
matrix:
4026
node:
41-
- '16'
42-
- '18'
43-
- '20'
4427
- '22'
45-
- '23'
4628
os:
4729
- ubuntu-latest
4830
name: Node.js ${{ matrix.node }}
@@ -72,4 +54,4 @@ jobs:
7254
node-version: ${{ matrix.node }}
7355
cache: yarn
7456
- run: yarn install --frozen-lockfile
75-
- run: yarn test
57+
- run: cd packages/pg-pool && yarn test

‎packages/pg-pool/test/idle-timeout.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,25 @@ describe('idle timeout', () => {
2525
it(
2626
'times out and removes clients when others are also removed',
2727
co.wrap(function* () {
28-
let currentClient = 1
2928
const pool = new Pool({ idleTimeoutMillis: 10 })
3029
const clientA = yield pool.connect()
3130
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
3433

3534
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+
3744
expect(pool.idleCount).to.equal(0)
3845
expect(pool.totalCount).to.equal(0)
39-
40-
if (currentClient >= 2) {
41-
resolve()
42-
} else {
43-
currentClient++
44-
}
46+
resolve()
4547
})
4648
})
4749

@@ -50,7 +52,7 @@ describe('idle timeout', () => {
5052
try {
5153
yield Promise.race([removal, timeout])
5254
} finally {
53-
yieldpool.end()
55+
pool.end()
5456
}
5557
})
5658
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /