You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-10 11:43:01 +03:00
* upgrade dependencies * fix "Property 'uninstall' does not exist on type 'SinonFakeTimers'."
39 lines
1.1 KiB
TypeScript
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'
|
|
});
|
|
});
|
|
});
|
|
});
|