Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Feb 7, 2021
1 parent ea37a5a commit 25856c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,22 @@ class Pool extends EventEmitter {
}

get busy () {
return this[kPending] > 0
return this[kPending] > 0 || (
this[kConnections] &&
this[kClients].length === this[kConnections] &&
this[kClients].every(({ busy }) => busy)
)
}

get pending () {
// TODO (perf): This is slow.
return this[kPending] + this[kClients].reduce((acc, { pending }) => acc + pending, 0)
}

get running () {
// TODO (perf): This is slow.
return this[kClients].reduce((acc, { running }) => acc + running, 0)
}

get size () {
// TODO (perf): This is slow.
return this[kPending] + this[kClients].reduce((acc, { size }) => acc + size, 0)
}

Expand Down
8 changes: 5 additions & 3 deletions test/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ test('backpressure algorithm', (t) => {
function noop () {}

test('busy', (t) => {
t.plan(8 * 8 + 2 + 1)
t.plan(8 * 10 + 2 + 1)

const server = createServer((req, res) => {
t.strictEqual('/', req.url)
Expand Down Expand Up @@ -379,8 +379,10 @@ test('busy', (t) => {
t.strictEqual('hello', Buffer.concat(bufs).toString('utf8'))
})
})
t.strictEqual(client.pending, Math.max(n - 2, 0))
t.strictEqual(client.busy, n > 2)
t.strictEqual(client.pending, n)
t.strictEqual(client.size, n)
t.strictEqual(client.running, 0)
t.strictEqual(client.busy, n >= 2)
}
})
})
Expand Down

0 comments on commit 25856c3

Please sign in to comment.