Skip to content

Commit a3b15b7

Browse files
committed
fix tests
1 parent 1ad4c8d commit a3b15b7

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

packages/client/lib/client/index.spec.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,9 @@ describe('Client', () => {
253253
}, GLOBAL.SERVERS.OPEN);
254254

255255
testUtils.testWithClient('AbortError', async client => {
256-
const abortIn = 10;
257-
await delaySetImmediate(abortIn * 2, async () => {
256+
await blockSetImmediate(async () => {
258257
await assert.rejects(client.sendCommand(['PING'], {
259-
abortSignal: AbortSignal.timeout(abortIn)
258+
abortSignal: AbortSignal.timeout(5)
260259
}), AbortError);
261260
})
262261
}, GLOBAL.SERVERS.OPEN);
@@ -265,19 +264,18 @@ describe('Client', () => {
265264

266265

267266
testUtils.testWithClient('Timeout with custom timeout config', async client => {
268-
const timeoutIn = 5;
269-
await delaySetImmediate(timeoutIn * 2, async () => {
267+
await blockSetImmediate(async () => {
270268
await assert.rejects(client.sendCommand(['PING'], {
271-
timeout: timeoutIn
269+
timeout: 5
272270
}), TimeoutError);
273271
})
274272
}, GLOBAL.SERVERS.OPEN);
275273

276274
testUtils.testWithClient('Timeout with global timeout config', async client => {
277-
await delaySetImmediate(10, async () => {
278-
await assert.rejects(client.sendCommand(['PING']), TimeoutError);
275+
await blockSetImmediate(async () => {
279276
await assert.rejects(client.ping(), TimeoutError);
280-
})
277+
await assert.rejects(client.sendCommand(['PING']), TimeoutError);
278+
});
281279
}, {
282280
...GLOBAL.SERVERS.OPEN,
283281
clientOptions: {
@@ -923,17 +921,17 @@ describe('Client', () => {
923921
});
924922
});
925923

926-
async function delaySetImmediate(ms: number, fn: () => Promise<void>) {
927-
// Stub setImmediate to delay execution, allowing AbortError to trigger
928-
const originalSetImmediate = global.setImmediate;
924+
/**
925+
* Executes the provided function in a context where setImmediate is stubbed to not do anything.
926+
* This blocks setImmediate callbacks from executing
927+
*/
928+
async function blockSetImmediate(fn: () => Promise<unknown>) {
929929
let setImmediateStub: any;
930930

931931
try {
932932
setImmediateStub = stub(global, 'setImmediate');
933-
setImmediateStub.callsFake((callback: (...args: any[]) => void, ...args: any[]) => {
934-
return originalSetImmediate(() => {
935-
setTimeout(() => callback(...args), ms);
936-
});
933+
setImmediateStub.callsFake(() => {
934+
//Dont call the callback, effectively blocking execution
937935
});
938936
await fn();
939937
} finally {

packages/client/lib/client/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,13 @@ export default class RedisClient<
889889
return Promise.reject(new ClientOfflineError());
890890
}
891891

892-
const promise = this._self.#queue.addCommand<T>(args, options);
892+
// Merge global options with provided options
893+
const opts = {
894+
...this._self._commandOptions,
895+
...options
896+
}
897+
898+
const promise = this._self.#queue.addCommand<T>(args, opts);
893899
this._self.#scheduleWrite();
894900
return promise;
895901
}

0 commit comments

Comments
 (0)