1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-10 11:43:01 +03:00
Files
node-redis/packages/client/lib/client/socket.spec.ts
Leibale Eidelman 5ade5dadc0 upgrade dependencies (#2057)
* upgrade dependencies

* fix "Property 'uninstall' does not exist on type 'SinonFakeTimers'."
2022-03-27 16:27:05 -04:00

39 lines
1.1 KiB
TypeScript

import { strict as assert } from 'assert';
import { SinonFakeTimers, useFakeTimers, spy } from 'sinon';
import RedisSocket from './socket';
describe('Socket', () => {
describe('reconnectStrategy', () => {
let clock: SinonFakeTimers;
beforeEach(() => clock = useFakeTimers());
afterEach(() => clock.restore());
it('custom strategy', () => {
const reconnectStrategy = spy((retries: number): number | Error => {
assert.equal(retries + 1, reconnectStrategy.callCount);
if (retries === 50) {
return Error('50');
}
const time = retries * 2;
queueMicrotask(() => clock.tick(time));
return time;
});
const socket = new RedisSocket(undefined, {
host: 'error',
reconnectStrategy
});
socket.on('error', () => {
// ignore errors
});
return assert.rejects(socket.connect(), {
message: '50'
});
});
});
});