Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/client/lib/client/pool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import { RESP_TYPES } from '../RESP/decoder';
import { RedisClientPool } from './pool';
import { TimeoutError } from '../errors';

describe('RedisClientPool', () => {
it('chained withCommandOptions(...).withTypeMapping(...) preserves earlier overrides at dispatch', () => {
Expand Down Expand Up @@ -295,4 +296,28 @@ describe('RedisClientPool', () => {
},
GLOBAL.SERVERS.OPEN
);

testUtils.testWithClientPool(
'rejects with TimeoutError when acquireTimeout expires',
async (pool) => {
const longRunningTask = pool.execute(async () => {
await new Promise((resolve) => setTimeout(resolve, 200));
});

await assert.rejects(
pool.execute(async () => {}),
(err: unknown) => {
assert(err instanceof TimeoutError);
assert.equal(err.message, 'Timeout waiting for a client after 50ms');
return true;
}
);

await longRunningTask;
},
{
...GLOBAL.SERVERS.OPEN,
poolOptions: { minimum: 1, maximum: 1, acquireTimeout: 50 },
}
);
});
2 changes: 1 addition & 1 deletion packages/client/lib/client/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export class RedisClientPool<
timeout = setTimeout(
() => {
this._self.#tasksQueue.remove(task, tail);
reject(new TimeoutError('Timeout waiting for a client')); // TODO: message
reject(new TimeoutError(`Timeout waiting for a client after ${this._self.#options.acquireTimeout}ms`));
},
this._self.#options.acquireTimeout
);
Expand Down