From 1254ff7ebd59bd3cdea05de41670e7b808250f37 Mon Sep 17 00:00:00 2001 From: Leibale Date: Wed, 26 Apr 2023 18:04:27 -0400 Subject: [PATCH] wip --- packages/client/lib/RESP/decoder.spec.ts | 346 ++-- packages/client/lib/client/index.spec.ts | 1732 +++++++++---------- packages/client/lib/cluster/index.spec.ts | 604 +++---- packages/client/lib/commands/APPEND.spec.ts | 2 +- packages/client/lib/commands/PING.spec.ts | 2 +- 5 files changed, 1343 insertions(+), 1343 deletions(-) diff --git a/packages/client/lib/RESP/decoder.spec.ts b/packages/client/lib/RESP/decoder.spec.ts index dcce9f6011..cff4fbe047 100644 --- a/packages/client/lib/RESP/decoder.spec.ts +++ b/packages/client/lib/RESP/decoder.spec.ts @@ -1,195 +1,195 @@ -import { strict as assert } from 'assert'; -import { SinonSpy, spy } from 'sinon'; -import RESP2Decoder from './decoder'; -import { ErrorReply } from '../../errors'; +// import { strict as assert } from 'assert'; +// import { SinonSpy, spy } from 'sinon'; +// import RESP2Decoder from './decoder'; +// import { ErrorReply } from '../../errors'; -interface DecoderAndSpies { - decoder: RESP2Decoder; - returnStringsAsBuffersSpy: SinonSpy; - onReplySpy: SinonSpy; -} +// interface DecoderAndSpies { +// decoder: RESP2Decoder; +// returnStringsAsBuffersSpy: SinonSpy; +// onReplySpy: SinonSpy; +// } -function createDecoderAndSpies(returnStringsAsBuffers: boolean): DecoderAndSpies { - const returnStringsAsBuffersSpy = spy(() => returnStringsAsBuffers), - onReplySpy = spy(); +// function createDecoderAndSpies(returnStringsAsBuffers: boolean): DecoderAndSpies { +// const returnStringsAsBuffersSpy = spy(() => returnStringsAsBuffers), +// onReplySpy = spy(); - return { - decoder: new RESP2Decoder({ - returnStringsAsBuffers: returnStringsAsBuffersSpy, - onReply: onReplySpy - }), - returnStringsAsBuffersSpy, - onReplySpy - }; -} +// return { +// decoder: new RESP2Decoder({ +// returnStringsAsBuffers: returnStringsAsBuffersSpy, +// onReply: onReplySpy +// }), +// returnStringsAsBuffersSpy, +// onReplySpy +// }; +// } -function writeChunks(stream: RESP2Decoder, buffer: Buffer) { - let i = 0; - while (i < buffer.length) { - stream.write(buffer.slice(i, ++i)); - } -} +// function writeChunks(stream: RESP2Decoder, buffer: Buffer) { +// let i = 0; +// while (i < buffer.length) { +// stream.write(buffer.slice(i, ++i)); +// } +// } -type Replies = Array>; +// type Replies = Array>; -interface TestsOptions { - toWrite: Buffer; - returnStringsAsBuffers: boolean; - replies: Replies; -} +// interface TestsOptions { +// toWrite: Buffer; +// returnStringsAsBuffers: boolean; +// replies: Replies; +// } -function generateTests({ - toWrite, - returnStringsAsBuffers, - replies -}: TestsOptions): void { - it('single chunk', () => { - const { decoder, returnStringsAsBuffersSpy, onReplySpy } = - createDecoderAndSpies(returnStringsAsBuffers); - decoder.write(toWrite); - assert.equal(returnStringsAsBuffersSpy.callCount, replies.length); - testReplies(onReplySpy, replies); - }); +// function generateTests({ +// toWrite, +// returnStringsAsBuffers, +// replies +// }: TestsOptions): void { +// it('single chunk', () => { +// const { decoder, returnStringsAsBuffersSpy, onReplySpy } = +// createDecoderAndSpies(returnStringsAsBuffers); +// decoder.write(toWrite); +// assert.equal(returnStringsAsBuffersSpy.callCount, replies.length); +// testReplies(onReplySpy, replies); +// }); - it('multiple chunks', () => { - const { decoder, returnStringsAsBuffersSpy, onReplySpy } = - createDecoderAndSpies(returnStringsAsBuffers); - writeChunks(decoder, toWrite); - assert.equal(returnStringsAsBuffersSpy.callCount, replies.length); - testReplies(onReplySpy, replies); - }); -} +// it('multiple chunks', () => { +// const { decoder, returnStringsAsBuffersSpy, onReplySpy } = +// createDecoderAndSpies(returnStringsAsBuffers); +// writeChunks(decoder, toWrite); +// assert.equal(returnStringsAsBuffersSpy.callCount, replies.length); +// testReplies(onReplySpy, replies); +// }); +// } -function testReplies(spy: SinonSpy, replies: Replies): void { - if (!replies) { - assert.equal(spy.callCount, 0); - return; - } +// function testReplies(spy: SinonSpy, replies: Replies): void { +// if (!replies) { +// assert.equal(spy.callCount, 0); +// return; +// } - assert.equal(spy.callCount, replies.length); - for (const [i, reply] of replies.entries()) { - assert.deepEqual( - spy.getCall(i).args, - reply - ); - } -} +// assert.equal(spy.callCount, replies.length); +// for (const [i, reply] of replies.entries()) { +// assert.deepEqual( +// spy.getCall(i).args, +// reply +// ); +// } +// } -describe('RESP2Parser', () => { - describe('Simple String', () => { - describe('as strings', () => { - generateTests({ - toWrite: Buffer.from('+OK\r\n'), - returnStringsAsBuffers: false, - replies: [['OK']] - }); - }); +// describe('RESP2Parser', () => { +// describe('Simple String', () => { +// describe('as strings', () => { +// generateTests({ +// toWrite: Buffer.from('+OK\r\n'), +// returnStringsAsBuffers: false, +// replies: [['OK']] +// }); +// }); - describe('as buffers', () => { - generateTests({ - toWrite: Buffer.from('+OK\r\n'), - returnStringsAsBuffers: true, - replies: [[Buffer.from('OK')]] - }); - }); - }); +// describe('as buffers', () => { +// generateTests({ +// toWrite: Buffer.from('+OK\r\n'), +// returnStringsAsBuffers: true, +// replies: [[Buffer.from('OK')]] +// }); +// }); +// }); - describe('Error', () => { - generateTests({ - toWrite: Buffer.from('-ERR\r\n'), - returnStringsAsBuffers: false, - replies: [[new ErrorReply('ERR')]] - }); - }); +// describe('Error', () => { +// generateTests({ +// toWrite: Buffer.from('-ERR\r\n'), +// returnStringsAsBuffers: false, +// replies: [[new ErrorReply('ERR')]] +// }); +// }); - describe('Integer', () => { - describe('-1', () => { - generateTests({ - toWrite: Buffer.from(':-1\r\n'), - returnStringsAsBuffers: false, - replies: [[-1]] - }); - }); +// describe('Integer', () => { +// describe('-1', () => { +// generateTests({ +// toWrite: Buffer.from(':-1\r\n'), +// returnStringsAsBuffers: false, +// replies: [[-1]] +// }); +// }); - describe('0', () => { - generateTests({ - toWrite: Buffer.from(':0\r\n'), - returnStringsAsBuffers: false, - replies: [[0]] - }); - }); - }); +// describe('0', () => { +// generateTests({ +// toWrite: Buffer.from(':0\r\n'), +// returnStringsAsBuffers: false, +// replies: [[0]] +// }); +// }); +// }); - describe('Bulk String', () => { - describe('null', () => { - generateTests({ - toWrite: Buffer.from('$-1\r\n'), - returnStringsAsBuffers: false, - replies: [[null]] - }); - }); +// describe('Bulk String', () => { +// describe('null', () => { +// generateTests({ +// toWrite: Buffer.from('$-1\r\n'), +// returnStringsAsBuffers: false, +// replies: [[null]] +// }); +// }); - describe('as strings', () => { - generateTests({ - toWrite: Buffer.from('$2\r\naa\r\n'), - returnStringsAsBuffers: false, - replies: [['aa']] - }); - }); +// describe('as strings', () => { +// generateTests({ +// toWrite: Buffer.from('$2\r\naa\r\n'), +// returnStringsAsBuffers: false, +// replies: [['aa']] +// }); +// }); - describe('as buffers', () => { - generateTests({ - toWrite: Buffer.from('$2\r\naa\r\n'), - returnStringsAsBuffers: true, - replies: [[Buffer.from('aa')]] - }); - }); - }); +// describe('as buffers', () => { +// generateTests({ +// toWrite: Buffer.from('$2\r\naa\r\n'), +// returnStringsAsBuffers: true, +// replies: [[Buffer.from('aa')]] +// }); +// }); +// }); - describe('Array', () => { - describe('null', () => { - generateTests({ - toWrite: Buffer.from('*-1\r\n'), - returnStringsAsBuffers: false, - replies: [[null]] - }); - }); +// describe('Array', () => { +// describe('null', () => { +// generateTests({ +// toWrite: Buffer.from('*-1\r\n'), +// returnStringsAsBuffers: false, +// replies: [[null]] +// }); +// }); - const arrayBuffer = Buffer.from( - '*5\r\n' + - '+OK\r\n' + - '-ERR\r\n' + - ':0\r\n' + - '$1\r\na\r\n' + - '*0\r\n' - ); +// const arrayBuffer = Buffer.from( +// '*5\r\n' + +// '+OK\r\n' + +// '-ERR\r\n' + +// ':0\r\n' + +// '$1\r\na\r\n' + +// '*0\r\n' +// ); - describe('as strings', () => { - generateTests({ - toWrite: arrayBuffer, - returnStringsAsBuffers: false, - replies: [[[ - 'OK', - new ErrorReply('ERR'), - 0, - 'a', - [] - ]]] - }); - }); +// describe('as strings', () => { +// generateTests({ +// toWrite: arrayBuffer, +// returnStringsAsBuffers: false, +// replies: [[[ +// 'OK', +// new ErrorReply('ERR'), +// 0, +// 'a', +// [] +// ]]] +// }); +// }); - describe('as buffers', () => { - generateTests({ - toWrite: arrayBuffer, - returnStringsAsBuffers: true, - replies: [[[ - Buffer.from('OK'), - new ErrorReply('ERR'), - 0, - Buffer.from('a'), - [] - ]]] - }); - }); - }); -}); +// describe('as buffers', () => { +// generateTests({ +// toWrite: arrayBuffer, +// returnStringsAsBuffers: true, +// replies: [[[ +// Buffer.from('OK'), +// new ErrorReply('ERR'), +// 0, +// Buffer.from('a'), +// [] +// ]]] +// }); +// }); +// }); +// }); diff --git a/packages/client/lib/client/index.spec.ts b/packages/client/lib/client/index.spec.ts index a0824e440b..8003590e70 100644 --- a/packages/client/lib/client/index.spec.ts +++ b/packages/client/lib/client/index.spec.ts @@ -1,981 +1,981 @@ -import { strict as assert } from 'assert'; -import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils'; -import RedisClient, { RedisClientType } from '.'; -import { RedisClientMultiCommandType } from './multi-command'; -import { RedisCommandRawReply, RedisModules, RedisFunctions, RedisScripts } from '../commands'; -import { AbortError, ClientClosedError, ClientOfflineError, ConnectionTimeoutError, DisconnectsClientError, SocketClosedUnexpectedlyError, WatchError } from '../errors'; -import { defineScript } from '../lua-script'; -import { spy } from 'sinon'; -import { once } from 'events'; -import { ClientKillFilters } from '../commands/CLIENT_KILL'; -import { promisify } from 'util'; +// import { strict as assert } from 'assert'; +// import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils'; +// import RedisClient, { RedisClientType } from '.'; +// import { RedisClientMultiCommandType } from './multi-command'; +// import { RedisCommandRawReply, RedisModules, RedisFunctions, RedisScripts } from '../commands'; +// import { AbortError, ClientClosedError, ClientOfflineError, ConnectionTimeoutError, DisconnectsClientError, SocketClosedUnexpectedlyError, WatchError } from '../errors'; +// import { defineScript } from '../lua-script'; +// import { spy } from 'sinon'; +// import { once } from 'events'; +// import { ClientKillFilters } from '../commands/CLIENT_KILL'; +// import { promisify } from 'util'; -export const SQUARE_SCRIPT = defineScript({ - SCRIPT: 'return ARGV[1] * ARGV[1];', - NUMBER_OF_KEYS: 0, - transformArguments(number: number): Array { - return [number.toString()]; - } -}); +// export const SQUARE_SCRIPT = defineScript({ +// SCRIPT: 'return ARGV[1] * ARGV[1];', +// NUMBER_OF_KEYS: 0, +// transformArguments(number: number): Array { +// return [number.toString()]; +// } +// }); -export const MATH_FUNCTION = { - name: 'math', - engine: 'LUA', - code: `#!LUA name=math - redis.register_function{ - function_name = "square", - callback = function(keys, args) return args[1] * args[1] end, - flags = { "no-writes" } - }`, - library: { - square: { - NAME: 'square', - IS_READ_ONLY: true, - NUMBER_OF_KEYS: 0, - transformArguments(number: number): Array { - return [number.toString()]; - } - } - } -}; +// export const MATH_FUNCTION = { +// name: 'math', +// engine: 'LUA', +// code: `#!LUA name=math +// redis.register_function{ +// function_name = "square", +// callback = function(keys, args) return args[1] * args[1] end, +// flags = { "no-writes" } +// }`, +// library: { +// square: { +// NAME: 'square', +// IS_READ_ONLY: true, +// NUMBER_OF_KEYS: 0, +// transformArguments(number: number): Array { +// return [number.toString()]; +// } +// } +// } +// }; -export async function loadMathFunction( - client: RedisClientType -): Promise { - await client.functionLoad( - MATH_FUNCTION.code, - { REPLACE: true } - ); -} +// export async function loadMathFunction( +// client: RedisClientType +// ): Promise { +// await client.functionLoad( +// MATH_FUNCTION.code, +// { REPLACE: true } +// ); +// } -describe('Client', () => { - describe('parseURL', () => { - it('redis://user:secret@localhost:6379/0', () => { - assert.deepEqual( - RedisClient.parseURL('redis://user:secret@localhost:6379/0'), - { - socket: { - host: 'localhost', - port: 6379 - }, - username: 'user', - password: 'secret', - database: 0 - } - ); - }); +// describe('Client', () => { +// describe('parseURL', () => { +// it('redis://user:secret@localhost:6379/0', () => { +// assert.deepEqual( +// RedisClient.parseURL('redis://user:secret@localhost:6379/0'), +// { +// socket: { +// host: 'localhost', +// port: 6379 +// }, +// username: 'user', +// password: 'secret', +// database: 0 +// } +// ); +// }); - it('rediss://user:secret@localhost:6379/0', () => { - assert.deepEqual( - RedisClient.parseURL('rediss://user:secret@localhost:6379/0'), - { - socket: { - host: 'localhost', - port: 6379, - tls: true - }, - username: 'user', - password: 'secret', - database: 0 - } - ); - }); +// it('rediss://user:secret@localhost:6379/0', () => { +// assert.deepEqual( +// RedisClient.parseURL('rediss://user:secret@localhost:6379/0'), +// { +// socket: { +// host: 'localhost', +// port: 6379, +// tls: true +// }, +// username: 'user', +// password: 'secret', +// database: 0 +// } +// ); +// }); - it('Invalid protocol', () => { - assert.throws( - () => RedisClient.parseURL('redi://user:secret@localhost:6379/0'), - TypeError - ); - }); +// it('Invalid protocol', () => { +// assert.throws( +// () => RedisClient.parseURL('redi://user:secret@localhost:6379/0'), +// TypeError +// ); +// }); - it('Invalid pathname', () => { - assert.throws( - () => RedisClient.parseURL('redis://user:secret@localhost:6379/NaN'), - TypeError - ); - }); +// it('Invalid pathname', () => { +// assert.throws( +// () => RedisClient.parseURL('redis://user:secret@localhost:6379/NaN'), +// TypeError +// ); +// }); - it('redis://localhost', () => { - assert.deepEqual( - RedisClient.parseURL('redis://localhost'), - { - socket: { - host: 'localhost', - } - } - ); - }); - }); +// it('redis://localhost', () => { +// assert.deepEqual( +// RedisClient.parseURL('redis://localhost'), +// { +// socket: { +// host: 'localhost', +// } +// } +// ); +// }); +// }); - describe('authentication', () => { - testUtils.testWithClient('Client should be authenticated', async client => { - assert.equal( - await client.ping(), - 'PONG' - ); - }, GLOBAL.SERVERS.PASSWORD); +// describe('authentication', () => { +// testUtils.testWithClient('Client should be authenticated', async client => { +// assert.equal( +// await client.ping(), +// 'PONG' +// ); +// }, GLOBAL.SERVERS.PASSWORD); - testUtils.testWithClient('should execute AUTH before SELECT', async client => { - assert.equal( - (await client.clientInfo()).db, - 2 - ); - }, { - ...GLOBAL.SERVERS.PASSWORD, - clientOptions: { - ...GLOBAL.SERVERS.PASSWORD.clientOptions, - database: 2 - }, - minimumDockerVersion: [6, 2] - }); - }); +// testUtils.testWithClient('should execute AUTH before SELECT', async client => { +// assert.equal( +// (await client.clientInfo()).db, +// 2 +// ); +// }, { +// ...GLOBAL.SERVERS.PASSWORD, +// clientOptions: { +// ...GLOBAL.SERVERS.PASSWORD.clientOptions, +// database: 2 +// }, +// minimumDockerVersion: [6, 2] +// }); +// }); - testUtils.testWithClient('should set connection name', async client => { - assert.equal( - await client.clientGetName(), - 'name' - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - name: 'name' - } - }); +// testUtils.testWithClient('should set connection name', async client => { +// assert.equal( +// await client.clientGetName(), +// 'name' +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// name: 'name' +// } +// }); - describe('legacyMode', () => { - testUtils.testWithClient('client.sendCommand should call the callback', async client => { - assert.equal( - await promisify(client.sendCommand).call(client, 'PING'), - 'PONG' - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// describe('legacyMode', () => { +// testUtils.testWithClient('client.sendCommand should call the callback', async client => { +// assert.equal( +// await promisify(client.sendCommand).call(client, 'PING'), +// 'PONG' +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.sendCommand should work without callback', async client => { - client.sendCommand(['PING']); - await client.v4.ping(); // make sure the first command was replied - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.sendCommand should work without callback', async client => { +// client.sendCommand(['PING']); +// await client.v4.ping(); // make sure the first command was replied +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.sendCommand should reply with error', async client => { - await assert.rejects( - promisify(client.sendCommand).call(client, '1', '2') - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.sendCommand should reply with error', async client => { +// await assert.rejects( +// promisify(client.sendCommand).call(client, '1', '2') +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.hGetAll should reply with error', async client => { - await assert.rejects( - promisify(client.hGetAll).call(client) - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.hGetAll should reply with error', async client => { +// await assert.rejects( +// promisify(client.hGetAll).call(client) +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.v4.sendCommand should return a promise', async client => { - assert.equal( - await client.v4.sendCommand(['PING']), - 'PONG' - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.v4.sendCommand should return a promise', async client => { +// assert.equal( +// await client.v4.sendCommand(['PING']), +// 'PONG' +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.v4.{command} should return a promise', async client => { - assert.equal( - await client.v4.ping(), - 'PONG' - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.v4.{command} should return a promise', async client => { +// assert.equal( +// await client.v4.ping(), +// 'PONG' +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.{command} should accept vardict arguments', async client => { - assert.equal( - await promisify(client.set).call(client, 'a', 'b'), - 'OK' - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.{command} should accept vardict arguments', async client => { +// assert.equal( +// await promisify(client.set).call(client, 'a', 'b'), +// 'OK' +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.{command} should accept arguments array', async client => { - assert.equal( - await promisify(client.set).call(client, ['a', 'b']), - 'OK' - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.{command} should accept arguments array', async client => { +// assert.equal( +// await promisify(client.set).call(client, ['a', 'b']), +// 'OK' +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.{command} should accept mix of arrays and arguments', async client => { - assert.equal( - await promisify(client.set).call(client, ['a'], 'b', ['EX', 1]), - 'OK' - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.{command} should accept mix of arrays and arguments', async client => { +// assert.equal( +// await promisify(client.set).call(client, ['a'], 'b', ['EX', 1]), +// 'OK' +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.hGetAll should return object', async client => { - await client.v4.hSet('key', 'field', 'value'); +// testUtils.testWithClient('client.hGetAll should return object', async client => { +// await client.v4.hSet('key', 'field', 'value'); - assert.deepEqual( - await promisify(client.hGetAll).call(client, 'key'), - Object.create(null, { - field: { - value: 'value', - configurable: true, - enumerable: true - } - }) - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// assert.deepEqual( +// await promisify(client.hGetAll).call(client, 'key'), +// Object.create(null, { +// field: { +// value: 'value', +// configurable: true, +// enumerable: true +// } +// }) +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - function multiExecAsync< - M extends RedisModules, - F extends RedisFunctions, - S extends RedisScripts - >(multi: RedisClientMultiCommandType): Promise> { - return new Promise((resolve, reject) => { - (multi as any).exec((err: Error | undefined, replies: Array) => { - if (err) return reject(err); +// function multiExecAsync< +// M extends RedisModules, +// F extends RedisFunctions, +// S extends RedisScripts +// >(multi: RedisClientMultiCommandType): Promise> { +// return new Promise((resolve, reject) => { +// (multi as any).exec((err: Error | undefined, replies: Array) => { +// if (err) return reject(err); - resolve(replies); - }); - }); - } +// resolve(replies); +// }); +// }); +// } - testUtils.testWithClient('client.multi.ping.exec should call the callback', async client => { - assert.deepEqual( - await multiExecAsync( - client.multi().ping() - ), - ['PONG'] - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.multi.ping.exec should call the callback', async client => { +// assert.deepEqual( +// await multiExecAsync( +// client.multi().ping() +// ), +// ['PONG'] +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.multi.ping.exec should call the callback', async client => { - client.multi() - .ping() - .exec(); - await client.v4.ping(); // make sure the first command was replied - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.multi.ping.exec should call the callback', async client => { +// client.multi() +// .ping() +// .exec(); +// await client.v4.ping(); // make sure the first command was replied +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.multi.ping.v4.ping.v4.exec should return a promise', async client => { - assert.deepEqual( - await client.multi() - .ping() - .v4.ping() - .v4.exec(), - ['PONG', 'PONG'] - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.multi.ping.v4.ping.v4.exec should return a promise', async client => { +// assert.deepEqual( +// await client.multi() +// .ping() +// .v4.ping() +// .v4.exec(), +// ['PONG', 'PONG'] +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.{script} should return a promise', async client => { - assert.equal( - await client.square(2), - 4 - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true, - scripts: { - square: SQUARE_SCRIPT - } - } - }); +// testUtils.testWithClient('client.{script} should return a promise', async client => { +// assert.equal( +// await client.square(2), +// 4 +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true, +// scripts: { +// square: SQUARE_SCRIPT +// } +// } +// }); - testUtils.testWithClient('client.multi.{command}.exec should flatten array arguments', async client => { - assert.deepEqual( - await client.multi() - .sAdd('a', ['b', 'c']) - .v4.exec(), - [2] - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); +// testUtils.testWithClient('client.multi.{command}.exec should flatten array arguments', async client => { +// assert.deepEqual( +// await client.multi() +// .sAdd('a', ['b', 'c']) +// .v4.exec(), +// [2] +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); - testUtils.testWithClient('client.multi.hGetAll should return object', async client => { - assert.deepEqual( - await multiExecAsync( - client.multi() - .hSet('key', 'field', 'value') - .hGetAll('key') - ), - [ - 1, - Object.create(null, { - field: { - value: 'value', - configurable: true, - enumerable: true - } - }) - ] - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - legacyMode: true - } - }); - }); +// testUtils.testWithClient('client.multi.hGetAll should return object', async client => { +// assert.deepEqual( +// await multiExecAsync( +// client.multi() +// .hSet('key', 'field', 'value') +// .hGetAll('key') +// ), +// [ +// 1, +// Object.create(null, { +// field: { +// value: 'value', +// configurable: true, +// enumerable: true +// } +// }) +// ] +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// legacyMode: true +// } +// }); +// }); - describe('events', () => { - testUtils.testWithClient('connect, ready, end', async client => { - await Promise.all([ - once(client, 'connect'), - once(client, 'ready'), - client.connect() - ]); +// describe('events', () => { +// testUtils.testWithClient('connect, ready, end', async client => { +// await Promise.all([ +// once(client, 'connect'), +// once(client, 'ready'), +// client.connect() +// ]); - await Promise.all([ - once(client, 'end'), - client.disconnect() - ]); - }, { - ...GLOBAL.SERVERS.OPEN, - disableClientSetup: true - }); - }); +// await Promise.all([ +// once(client, 'end'), +// client.disconnect() +// ]); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// disableClientSetup: true +// }); +// }); - describe('sendCommand', () => { - testUtils.testWithClient('PING', async client => { - assert.equal(await client.sendCommand(['PING']), 'PONG'); - }, GLOBAL.SERVERS.OPEN); +// describe('sendCommand', () => { +// testUtils.testWithClient('PING', async client => { +// assert.equal(await client.sendCommand(['PING']), 'PONG'); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('returnBuffers', async client => { - assert.deepEqual( - await client.sendCommand(['PING'], { - returnBuffers: true - }), - Buffer.from('PONG') - ); - }, GLOBAL.SERVERS.OPEN); +// testUtils.testWithClient('returnBuffers', async client => { +// assert.deepEqual( +// await client.sendCommand(['PING'], { +// returnBuffers: true +// }), +// Buffer.from('PONG') +// ); +// }, GLOBAL.SERVERS.OPEN); - describe('AbortController', () => { - before(function () { - if (!global.AbortController) { - this.skip(); - } - }); +// describe('AbortController', () => { +// before(function () { +// if (!global.AbortController) { +// this.skip(); +// } +// }); - testUtils.testWithClient('success', async client => { - await client.sendCommand(['PING'], { - signal: new AbortController().signal - }); - }, GLOBAL.SERVERS.OPEN); +// testUtils.testWithClient('success', async client => { +// await client.sendCommand(['PING'], { +// signal: new AbortController().signal +// }); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('AbortError', client => { - const controller = new AbortController(); - controller.abort(); +// testUtils.testWithClient('AbortError', client => { +// const controller = new AbortController(); +// controller.abort(); - return assert.rejects( - client.sendCommand(['PING'], { - signal: controller.signal - }), - AbortError - ); - }, GLOBAL.SERVERS.OPEN); - }); +// return assert.rejects( +// client.sendCommand(['PING'], { +// signal: controller.signal +// }), +// AbortError +// ); +// }, GLOBAL.SERVERS.OPEN); +// }); - testUtils.testWithClient('undefined and null should not break the client', async client => { - await assert.rejects( - client.sendCommand([null as any, undefined as any]), - TypeError - ); +// testUtils.testWithClient('undefined and null should not break the client', async client => { +// await assert.rejects( +// client.sendCommand([null as any, undefined as any]), +// TypeError +// ); - assert.equal( - await client.ping(), - 'PONG' - ); - }, GLOBAL.SERVERS.OPEN); - }); +// assert.equal( +// await client.ping(), +// 'PONG' +// ); +// }, GLOBAL.SERVERS.OPEN); +// }); - describe('multi', () => { - testUtils.testWithClient('simple', async client => { - assert.deepEqual( - await client.multi() - .ping() - .set('key', 'value') - .get('key') - .exec(), - ['PONG', 'OK', 'value'] - ); - }, GLOBAL.SERVERS.OPEN); +// describe('multi', () => { +// testUtils.testWithClient('simple', async client => { +// assert.deepEqual( +// await client.multi() +// .ping() +// .set('key', 'value') +// .get('key') +// .exec(), +// ['PONG', 'OK', 'value'] +// ); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('should reject the whole chain on error', client => { - return assert.rejects( - client.multi() - .ping() - .addCommand(['INVALID COMMAND']) - .ping() - .exec() - ); - }, GLOBAL.SERVERS.OPEN); +// testUtils.testWithClient('should reject the whole chain on error', client => { +// return assert.rejects( +// client.multi() +// .ping() +// .addCommand(['INVALID COMMAND']) +// .ping() +// .exec() +// ); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('should reject the whole chain upon client disconnect', async client => { - await client.disconnect(); +// testUtils.testWithClient('should reject the whole chain upon client disconnect', async client => { +// await client.disconnect(); - return assert.rejects( - client.multi() - .ping() - .set('key', 'value') - .get('key') - .exec(), - ClientClosedError - ); - }, GLOBAL.SERVERS.OPEN); +// return assert.rejects( +// client.multi() +// .ping() +// .set('key', 'value') +// .get('key') +// .exec(), +// ClientClosedError +// ); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('with script', async client => { - assert.deepEqual( - await client.multi() - .square(2) - .exec(), - [4] - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - scripts: { - square: SQUARE_SCRIPT - } - } - }); +// testUtils.testWithClient('with script', async client => { +// assert.deepEqual( +// await client.multi() +// .square(2) +// .exec(), +// [4] +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// scripts: { +// square: SQUARE_SCRIPT +// } +// } +// }); - testUtils.testWithClient('WatchError', async client => { - await client.watch('key'); +// testUtils.testWithClient('WatchError', async client => { +// await client.watch('key'); - await client.set( - RedisClient.commandOptions({ - isolated: true - }), - 'key', - '1' - ); +// await client.set( +// RedisClient.commandOptions({ +// isolated: true +// }), +// 'key', +// '1' +// ); - await assert.rejects( - client.multi() - .decr('key') - .exec(), - WatchError - ); - }, GLOBAL.SERVERS.OPEN); +// await assert.rejects( +// client.multi() +// .decr('key') +// .exec(), +// WatchError +// ); +// }, GLOBAL.SERVERS.OPEN); - describe('execAsPipeline', () => { - testUtils.testWithClient('exec(true)', async client => { - assert.deepEqual( - await client.multi() - .ping() - .exec(true), - ['PONG'] - ); - }, GLOBAL.SERVERS.OPEN); +// describe('execAsPipeline', () => { +// testUtils.testWithClient('exec(true)', async client => { +// assert.deepEqual( +// await client.multi() +// .ping() +// .exec(true), +// ['PONG'] +// ); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('empty execAsPipeline', async client => { - assert.deepEqual( - await client.multi().execAsPipeline(), - [] - ); - }, GLOBAL.SERVERS.OPEN); - }); +// testUtils.testWithClient('empty execAsPipeline', async client => { +// assert.deepEqual( +// await client.multi().execAsPipeline(), +// [] +// ); +// }, GLOBAL.SERVERS.OPEN); +// }); - testUtils.testWithClient('should remember selected db', async client => { - await client.multi() - .select(1) - .exec(); - await killClient(client); - assert.equal( - (await client.clientInfo()).db, - 1 - ); - }, { - ...GLOBAL.SERVERS.OPEN, - minimumDockerVersion: [6, 2] // CLIENT INFO - }); - }); +// testUtils.testWithClient('should remember selected db', async client => { +// await client.multi() +// .select(1) +// .exec(); +// await killClient(client); +// assert.equal( +// (await client.clientInfo()).db, +// 1 +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// minimumDockerVersion: [6, 2] // CLIENT INFO +// }); +// }); - testUtils.testWithClient('scripts', async client => { - assert.equal( - await client.square(2), - 4 - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - scripts: { - square: SQUARE_SCRIPT - } - } - }); +// testUtils.testWithClient('scripts', async client => { +// assert.equal( +// await client.square(2), +// 4 +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// scripts: { +// square: SQUARE_SCRIPT +// } +// } +// }); - const module = { - echo: { - transformArguments(message: string): Array { - return ['ECHO', message]; - }, - transformReply(reply: string): string { - return reply; - } - } - }; +// const module = { +// echo: { +// transformArguments(message: string): Array { +// return ['ECHO', message]; +// }, +// transformReply(reply: string): string { +// return reply; +// } +// } +// }; - testUtils.testWithClient('modules', async client => { - assert.equal( - await client.module.echo('message'), - 'message' - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - modules: { - module - } - } - }); +// testUtils.testWithClient('modules', async client => { +// assert.equal( +// await client.module.echo('message'), +// 'message' +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// modules: { +// module +// } +// } +// }); - testUtils.testWithClient('functions', async client => { - await loadMathFunction(client); +// testUtils.testWithClient('functions', async client => { +// await loadMathFunction(client); - assert.equal( - await client.math.square(2), - 4 - ); - }, { - ...GLOBAL.SERVERS.OPEN, - minimumDockerVersion: [7, 0], - clientOptions: { - functions: { - math: MATH_FUNCTION.library - } - } - }); +// assert.equal( +// await client.math.square(2), +// 4 +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// minimumDockerVersion: [7, 0], +// clientOptions: { +// functions: { +// math: MATH_FUNCTION.library +// } +// } +// }); - describe('isolationPool', () => { - testUtils.testWithClient('executeIsolated', async client => { - const id = await client.clientId(), - isolatedId = await client.executeIsolated(isolatedClient => isolatedClient.clientId()); - assert.ok(id !== isolatedId); - }, GLOBAL.SERVERS.OPEN); +// describe('isolationPool', () => { +// testUtils.testWithClient('executeIsolated', async client => { +// const id = await client.clientId(), +// isolatedId = await client.executeIsolated(isolatedClient => isolatedClient.clientId()); +// assert.ok(id !== isolatedId); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('should be able to use pool even before connect', async client => { - await client.executeIsolated(() => Promise.resolve()); - // make sure to destroy isolation pool - await client.connect(); - await client.disconnect(); - }, { - ...GLOBAL.SERVERS.OPEN, - disableClientSetup: true - }); +// testUtils.testWithClient('should be able to use pool even before connect', async client => { +// await client.executeIsolated(() => Promise.resolve()); +// // make sure to destroy isolation pool +// await client.connect(); +// await client.disconnect(); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// disableClientSetup: true +// }); - testUtils.testWithClient('should work after reconnect (#2406)', async client => { - await client.disconnect(); - await client.connect(); - await client.executeIsolated(() => Promise.resolve()); - }, GLOBAL.SERVERS.OPEN); +// testUtils.testWithClient('should work after reconnect (#2406)', async client => { +// await client.disconnect(); +// await client.connect(); +// await client.executeIsolated(() => Promise.resolve()); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('should throw ClientClosedError after disconnect', async client => { - await client.connect(); - await client.disconnect(); - await assert.rejects( - client.executeIsolated(() => Promise.resolve()), - ClientClosedError - ); - }, { - ...GLOBAL.SERVERS.OPEN, - disableClientSetup: true - }); - }); +// testUtils.testWithClient('should throw ClientClosedError after disconnect', async client => { +// await client.connect(); +// await client.disconnect(); +// await assert.rejects( +// client.executeIsolated(() => Promise.resolve()), +// ClientClosedError +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// disableClientSetup: true +// }); +// }); - async function killClient< - M extends RedisModules, - F extends RedisFunctions, - S extends RedisScripts - >( - client: RedisClientType, - errorClient: RedisClientType = client - ): Promise { - const onceErrorPromise = once(errorClient, 'error'); - await client.sendCommand(['QUIT']); - await Promise.all([ - onceErrorPromise, - assert.rejects(client.ping(), SocketClosedUnexpectedlyError) - ]); - } +// async function killClient< +// M extends RedisModules, +// F extends RedisFunctions, +// S extends RedisScripts +// >( +// client: RedisClientType, +// errorClient: RedisClientType = client +// ): Promise { +// const onceErrorPromise = once(errorClient, 'error'); +// await client.sendCommand(['QUIT']); +// await Promise.all([ +// onceErrorPromise, +// assert.rejects(client.ping(), SocketClosedUnexpectedlyError) +// ]); +// } - testUtils.testWithClient('should reconnect when socket disconnects', async client => { - await killClient(client); - await assert.doesNotReject(client.ping()); - }, GLOBAL.SERVERS.OPEN); +// testUtils.testWithClient('should reconnect when socket disconnects', async client => { +// await killClient(client); +// await assert.doesNotReject(client.ping()); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('should remember selected db', async client => { - await client.select(1); - await killClient(client); - assert.equal( - (await client.clientInfo()).db, - 1 - ); - }, { - ...GLOBAL.SERVERS.OPEN, - minimumDockerVersion: [6, 2] // CLIENT INFO - }); +// testUtils.testWithClient('should remember selected db', async client => { +// await client.select(1); +// await killClient(client); +// assert.equal( +// (await client.clientInfo()).db, +// 1 +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// minimumDockerVersion: [6, 2] // CLIENT INFO +// }); - testUtils.testWithClient('should propagated errors from "isolated" clients', client => { - client.on('error', () => { - // ignore errors - }); - return client.executeIsolated(isolated => killClient(isolated, client)); - }, GLOBAL.SERVERS.OPEN); +// testUtils.testWithClient('should propagated errors from "isolated" clients', client => { +// client.on('error', () => { +// // ignore errors +// }); +// return client.executeIsolated(isolated => killClient(isolated, client)); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('scanIterator', async client => { - const promises = [], - keys = new Set(); - for (let i = 0; i < 100; i++) { - const key = i.toString(); - keys.add(key); - promises.push(client.set(key, '')); - } +// testUtils.testWithClient('scanIterator', async client => { +// const promises = [], +// keys = new Set(); +// for (let i = 0; i < 100; i++) { +// const key = i.toString(); +// keys.add(key); +// promises.push(client.set(key, '')); +// } - await Promise.all(promises); +// await Promise.all(promises); - const results = new Set(); - for await (const key of client.scanIterator()) { - results.add(key); - } +// const results = new Set(); +// for await (const key of client.scanIterator()) { +// results.add(key); +// } - assert.deepEqual(keys, results); - }, GLOBAL.SERVERS.OPEN); +// assert.deepEqual(keys, results); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('hScanIterator', async client => { - const hash: Record = {}; - for (let i = 0; i < 100; i++) { - hash[i.toString()] = i.toString(); - } +// testUtils.testWithClient('hScanIterator', async client => { +// const hash: Record = {}; +// for (let i = 0; i < 100; i++) { +// hash[i.toString()] = i.toString(); +// } - await client.hSet('key', hash); +// await client.hSet('key', hash); - const results: Record = {}; - for await (const { field, value } of client.hScanIterator('key')) { - results[field] = value; - } +// const results: Record = {}; +// for await (const { field, value } of client.hScanIterator('key')) { +// results[field] = value; +// } - assert.deepEqual(hash, results); - }, GLOBAL.SERVERS.OPEN); +// assert.deepEqual(hash, results); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('sScanIterator', async client => { - const members = new Set(); - for (let i = 0; i < 100; i++) { - members.add(i.toString()); - } +// testUtils.testWithClient('sScanIterator', async client => { +// const members = new Set(); +// for (let i = 0; i < 100; i++) { +// members.add(i.toString()); +// } - await client.sAdd('key', Array.from(members)); +// await client.sAdd('key', Array.from(members)); - const results = new Set(); - for await (const key of client.sScanIterator('key')) { - results.add(key); - } +// const results = new Set(); +// for await (const key of client.sScanIterator('key')) { +// results.add(key); +// } - assert.deepEqual(members, results); - }, GLOBAL.SERVERS.OPEN); +// assert.deepEqual(members, results); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('zScanIterator', async client => { - const members = []; - for (let i = 0; i < 100; i++) { - members.push({ - score: 1, - value: i.toString() - }); - } +// testUtils.testWithClient('zScanIterator', async client => { +// const members = []; +// for (let i = 0; i < 100; i++) { +// members.push({ +// score: 1, +// value: i.toString() +// }); +// } - await client.zAdd('key', members); +// await client.zAdd('key', members); - const map = new Map(); - for await (const member of client.zScanIterator('key')) { - map.set(member.value, member.score); - } +// const map = new Map(); +// for await (const member of client.zScanIterator('key')) { +// map.set(member.value, member.score); +// } - type MemberTuple = [string, number]; +// type MemberTuple = [string, number]; - function sort(a: MemberTuple, b: MemberTuple) { - return Number(b[0]) - Number(a[0]); - } +// function sort(a: MemberTuple, b: MemberTuple) { +// return Number(b[0]) - Number(a[0]); +// } - assert.deepEqual( - [...map.entries()].sort(sort), - members.map(member => [member.value, member.score]).sort(sort) - ); - }, GLOBAL.SERVERS.OPEN); +// assert.deepEqual( +// [...map.entries()].sort(sort), +// members.map(member => [member.value, member.score]).sort(sort) +// ); +// }, GLOBAL.SERVERS.OPEN); - describe('PubSub', () => { - testUtils.testWithClient('should be able to publish and subscribe to messages', async publisher => { - function assertStringListener(message: string, channel: string) { - assert.equal(typeof message, 'string'); - assert.equal(typeof channel, 'string'); - } +// describe('PubSub', () => { +// testUtils.testWithClient('should be able to publish and subscribe to messages', async publisher => { +// function assertStringListener(message: string, channel: string) { +// assert.equal(typeof message, 'string'); +// assert.equal(typeof channel, 'string'); +// } - function assertBufferListener(message: Buffer, channel: Buffer) { - assert.ok(Buffer.isBuffer(message)); - assert.ok(Buffer.isBuffer(channel)); - } +// function assertBufferListener(message: Buffer, channel: Buffer) { +// assert.ok(Buffer.isBuffer(message)); +// assert.ok(Buffer.isBuffer(channel)); +// } - const subscriber = publisher.duplicate(); +// const subscriber = publisher.duplicate(); - await subscriber.connect(); +// await subscriber.connect(); - try { - const channelListener1 = spy(assertBufferListener), - channelListener2 = spy(assertStringListener), - patternListener = spy(assertStringListener); +// try { +// const channelListener1 = spy(assertBufferListener), +// channelListener2 = spy(assertStringListener), +// patternListener = spy(assertStringListener); - await Promise.all([ - subscriber.subscribe('channel', channelListener1, true), - subscriber.subscribe('channel', channelListener2), - subscriber.pSubscribe('channel*', patternListener) - ]); - await Promise.all([ - waitTillBeenCalled(channelListener1), - waitTillBeenCalled(channelListener2), - waitTillBeenCalled(patternListener), - publisher.publish(Buffer.from('channel'), Buffer.from('message')) - ]); +// await Promise.all([ +// subscriber.subscribe('channel', channelListener1, true), +// subscriber.subscribe('channel', channelListener2), +// subscriber.pSubscribe('channel*', patternListener) +// ]); +// await Promise.all([ +// waitTillBeenCalled(channelListener1), +// waitTillBeenCalled(channelListener2), +// waitTillBeenCalled(patternListener), +// publisher.publish(Buffer.from('channel'), Buffer.from('message')) +// ]); - assert.ok(channelListener1.calledOnceWithExactly(Buffer.from('message'), Buffer.from('channel'))); - assert.ok(channelListener2.calledOnceWithExactly('message', 'channel')); - assert.ok(patternListener.calledOnceWithExactly('message', 'channel')); +// assert.ok(channelListener1.calledOnceWithExactly(Buffer.from('message'), Buffer.from('channel'))); +// assert.ok(channelListener2.calledOnceWithExactly('message', 'channel')); +// assert.ok(patternListener.calledOnceWithExactly('message', 'channel')); - await subscriber.unsubscribe('channel', channelListener1, true); - await Promise.all([ - waitTillBeenCalled(channelListener2), - waitTillBeenCalled(patternListener), - publisher.publish('channel', 'message') - ]); - assert.ok(channelListener1.calledOnce); - assert.ok(channelListener2.calledTwice); - assert.ok(channelListener2.secondCall.calledWithExactly('message', 'channel')); - assert.ok(patternListener.calledTwice); - assert.ok(patternListener.secondCall.calledWithExactly('message', 'channel')); - await subscriber.unsubscribe('channel'); - await Promise.all([ - waitTillBeenCalled(patternListener), - publisher.publish('channel', 'message') - ]); - assert.ok(channelListener1.calledOnce); - assert.ok(channelListener2.calledTwice); - assert.ok(patternListener.calledThrice); - assert.ok(patternListener.thirdCall.calledWithExactly('message', 'channel')); - await subscriber.pUnsubscribe(); - await publisher.publish('channel', 'message'); - assert.ok(channelListener1.calledOnce); - assert.ok(channelListener2.calledTwice); - assert.ok(patternListener.calledThrice); - // should be able to send commands when unsubsribed from all channels (see #1652) - await assert.doesNotReject(subscriber.ping()); - } finally { - await subscriber.disconnect(); - } - }, GLOBAL.SERVERS.OPEN); +// await subscriber.unsubscribe('channel', channelListener1, true); +// await Promise.all([ +// waitTillBeenCalled(channelListener2), +// waitTillBeenCalled(patternListener), +// publisher.publish('channel', 'message') +// ]); +// assert.ok(channelListener1.calledOnce); +// assert.ok(channelListener2.calledTwice); +// assert.ok(channelListener2.secondCall.calledWithExactly('message', 'channel')); +// assert.ok(patternListener.calledTwice); +// assert.ok(patternListener.secondCall.calledWithExactly('message', 'channel')); +// await subscriber.unsubscribe('channel'); +// await Promise.all([ +// waitTillBeenCalled(patternListener), +// publisher.publish('channel', 'message') +// ]); +// assert.ok(channelListener1.calledOnce); +// assert.ok(channelListener2.calledTwice); +// assert.ok(patternListener.calledThrice); +// assert.ok(patternListener.thirdCall.calledWithExactly('message', 'channel')); +// await subscriber.pUnsubscribe(); +// await publisher.publish('channel', 'message'); +// assert.ok(channelListener1.calledOnce); +// assert.ok(channelListener2.calledTwice); +// assert.ok(patternListener.calledThrice); +// // should be able to send commands when unsubsribed from all channels (see #1652) +// await assert.doesNotReject(subscriber.ping()); +// } finally { +// await subscriber.disconnect(); +// } +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('should resubscribe', async publisher => { - const subscriber = publisher.duplicate(); +// testUtils.testWithClient('should resubscribe', async publisher => { +// const subscriber = publisher.duplicate(); - await subscriber.connect(); +// await subscriber.connect(); - try { - const channelListener = spy(); - await subscriber.subscribe('channel', channelListener); +// try { +// const channelListener = spy(); +// await subscriber.subscribe('channel', channelListener); - const patternListener = spy(); - await subscriber.pSubscribe('channe*', patternListener); +// const patternListener = spy(); +// await subscriber.pSubscribe('channe*', patternListener); - await Promise.all([ - once(subscriber, 'error'), - publisher.clientKill({ - filter: ClientKillFilters.SKIP_ME, - skipMe: true - }) - ]); +// await Promise.all([ +// once(subscriber, 'error'), +// publisher.clientKill({ +// filter: ClientKillFilters.SKIP_ME, +// skipMe: true +// }) +// ]); - await once(subscriber, 'ready'); +// await once(subscriber, 'ready'); - await Promise.all([ - waitTillBeenCalled(channelListener), - waitTillBeenCalled(patternListener), - publisher.publish('channel', 'message') - ]); - } finally { - await subscriber.disconnect(); - } - }, GLOBAL.SERVERS.OPEN); +// await Promise.all([ +// waitTillBeenCalled(channelListener), +// waitTillBeenCalled(patternListener), +// publisher.publish('channel', 'message') +// ]); +// } finally { +// await subscriber.disconnect(); +// } +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('should not fail when message arrives right after subscribe', async publisher => { - const subscriber = publisher.duplicate(); +// testUtils.testWithClient('should not fail when message arrives right after subscribe', async publisher => { +// const subscriber = publisher.duplicate(); - await subscriber.connect(); +// await subscriber.connect(); - try { - await assert.doesNotReject(Promise.all([ - subscriber.subscribe('channel', () => { - // noop - }), - publisher.publish('channel', 'message') - ])); - } finally { - await subscriber.disconnect(); - } - }, GLOBAL.SERVERS.OPEN); +// try { +// await assert.doesNotReject(Promise.all([ +// subscriber.subscribe('channel', () => { +// // noop +// }), +// publisher.publish('channel', 'message') +// ])); +// } finally { +// await subscriber.disconnect(); +// } +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('should be able to quit in PubSub mode', async client => { - await client.subscribe('channel', () => { - // noop - }); +// testUtils.testWithClient('should be able to quit in PubSub mode', async client => { +// await client.subscribe('channel', () => { +// // noop +// }); - await assert.doesNotReject(client.quit()); +// await assert.doesNotReject(client.quit()); - assert.equal(client.isOpen, false); - }, GLOBAL.SERVERS.OPEN); - }); +// assert.equal(client.isOpen, false); +// }, GLOBAL.SERVERS.OPEN); +// }); - testUtils.testWithClient('ConnectionTimeoutError', async client => { - const promise = assert.rejects(client.connect(), ConnectionTimeoutError), - start = process.hrtime.bigint(); +// testUtils.testWithClient('ConnectionTimeoutError', async client => { +// const promise = assert.rejects(client.connect(), ConnectionTimeoutError), +// start = process.hrtime.bigint(); - while (process.hrtime.bigint() - start < 1_000_000) { - // block the event loop for 1ms, to make sure the connection will timeout - } +// while (process.hrtime.bigint() - start < 1_000_000) { +// // block the event loop for 1ms, to make sure the connection will timeout +// } - await promise; - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - socket: { - connectTimeout: 1 - } - }, - disableClientSetup: true - }); +// await promise; +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// socket: { +// connectTimeout: 1 +// } +// }, +// disableClientSetup: true +// }); - testUtils.testWithClient('client.quit', async client => { - await client.connect(); +// testUtils.testWithClient('client.quit', async client => { +// await client.connect(); - const pingPromise = client.ping(), - quitPromise = client.quit(); - assert.equal(client.isOpen, false); +// const pingPromise = client.ping(), +// quitPromise = client.quit(); +// assert.equal(client.isOpen, false); - const [ping, quit] = await Promise.all([ - pingPromise, - quitPromise, - assert.rejects(client.ping(), ClientClosedError) - ]); +// const [ping, quit] = await Promise.all([ +// pingPromise, +// quitPromise, +// assert.rejects(client.ping(), ClientClosedError) +// ]); - assert.equal(ping, 'PONG'); - assert.equal(quit, 'OK'); - }, { - ...GLOBAL.SERVERS.OPEN, - disableClientSetup: true - }); +// assert.equal(ping, 'PONG'); +// assert.equal(quit, 'OK'); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// disableClientSetup: true +// }); - testUtils.testWithClient('client.disconnect', async client => { - const pingPromise = client.ping(), - disconnectPromise = client.disconnect(); - assert.equal(client.isOpen, false); - await Promise.all([ - assert.rejects(pingPromise, DisconnectsClientError), - assert.doesNotReject(disconnectPromise), - assert.rejects(client.ping(), ClientClosedError) - ]); - }, GLOBAL.SERVERS.OPEN); +// testUtils.testWithClient('client.disconnect', async client => { +// const pingPromise = client.ping(), +// disconnectPromise = client.disconnect(); +// assert.equal(client.isOpen, false); +// await Promise.all([ +// assert.rejects(pingPromise, DisconnectsClientError), +// assert.doesNotReject(disconnectPromise), +// assert.rejects(client.ping(), ClientClosedError) +// ]); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('should be able to connect after disconnect (see #1801)', async client => { - await client.disconnect(); - await client.connect(); - }, GLOBAL.SERVERS.OPEN); +// testUtils.testWithClient('should be able to connect after disconnect (see #1801)', async client => { +// await client.disconnect(); +// await client.connect(); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('should be able to use ref and unref', client => { - client.unref(); - client.ref(); - }, GLOBAL.SERVERS.OPEN); +// testUtils.testWithClient('should be able to use ref and unref', client => { +// client.unref(); +// client.ref(); +// }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('pingInterval', async client => { - assert.deepEqual( - await once(client, 'ping-interval'), - ['PONG'] - ); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - pingInterval: 1 - } - }); +// testUtils.testWithClient('pingInterval', async client => { +// assert.deepEqual( +// await once(client, 'ping-interval'), +// ['PONG'] +// ); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// pingInterval: 1 +// } +// }); - testUtils.testWithClient('should reject commands in connect phase when `disableOfflineQueue`', async client => { - const connectPromise = client.connect(); - await assert.rejects( - client.ping(), - ClientOfflineError - ); - await connectPromise; - await client.disconnect(); - }, { - ...GLOBAL.SERVERS.OPEN, - clientOptions: { - disableOfflineQueue: true - }, - disableClientSetup: true - }); -}); +// testUtils.testWithClient('should reject commands in connect phase when `disableOfflineQueue`', async client => { +// const connectPromise = client.connect(); +// await assert.rejects( +// client.ping(), +// ClientOfflineError +// ); +// await connectPromise; +// await client.disconnect(); +// }, { +// ...GLOBAL.SERVERS.OPEN, +// clientOptions: { +// disableOfflineQueue: true +// }, +// disableClientSetup: true +// }); +// }); diff --git a/packages/client/lib/cluster/index.spec.ts b/packages/client/lib/cluster/index.spec.ts index 8200375056..4c06dc8c91 100644 --- a/packages/client/lib/cluster/index.spec.ts +++ b/packages/client/lib/cluster/index.spec.ts @@ -1,362 +1,362 @@ -import { strict as assert } from 'assert'; -import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils'; -import RedisCluster from '.'; -import { ClusterSlotStates } from '../commands/CLUSTER_SETSLOT'; -import { commandOptions } from '../command-options'; -import { SQUARE_SCRIPT } from '../client/index.spec'; -import { RootNodesUnavailableError } from '../errors'; -import { spy } from 'sinon'; -import { promiseTimeout } from '../utils'; -import RedisClient from '../client'; +// import { strict as assert } from 'assert'; +// import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils'; +// import RedisCluster from '.'; +// import { ClusterSlotStates } from '../commands/CLUSTER_SETSLOT'; +// import { commandOptions } from '../command-options'; +// import { SQUARE_SCRIPT } from '../client/index.spec'; +// import { RootNodesUnavailableError } from '../errors'; +// import { spy } from 'sinon'; +// import { promiseTimeout } from '../utils'; +// import RedisClient from '../client'; -describe('Cluster', () => { - testUtils.testWithCluster('sendCommand', async cluster => { - assert.equal( - await cluster.sendCommand(undefined, true, ['PING']), - 'PONG' - ); - }, GLOBAL.CLUSTERS.OPEN); +// describe('Cluster', () => { +// testUtils.testWithCluster('sendCommand', async cluster => { +// assert.equal( +// await cluster.sendCommand(undefined, true, ['PING']), +// 'PONG' +// ); +// }, GLOBAL.CLUSTERS.OPEN); - testUtils.testWithCluster('isOpen', async cluster => { - assert.equal(cluster.isOpen, true); - await cluster.disconnect(); - assert.equal(cluster.isOpen, false); - }, GLOBAL.CLUSTERS.OPEN); +// testUtils.testWithCluster('isOpen', async cluster => { +// assert.equal(cluster.isOpen, true); +// await cluster.disconnect(); +// assert.equal(cluster.isOpen, false); +// }, GLOBAL.CLUSTERS.OPEN); - testUtils.testWithCluster('connect should throw if already connected', async cluster => { - await assert.rejects(cluster.connect()); - }, GLOBAL.CLUSTERS.OPEN); +// testUtils.testWithCluster('connect should throw if already connected', async cluster => { +// await assert.rejects(cluster.connect()); +// }, GLOBAL.CLUSTERS.OPEN); - testUtils.testWithCluster('multi', async cluster => { - const key = 'key'; - assert.deepEqual( - await cluster.multi() - .set(key, 'value') - .get(key) - .exec(), - ['OK', 'value'] - ); - }, GLOBAL.CLUSTERS.OPEN); +// testUtils.testWithCluster('multi', async cluster => { +// const key = 'key'; +// assert.deepEqual( +// await cluster.multi() +// .set(key, 'value') +// .get(key) +// .exec(), +// ['OK', 'value'] +// ); +// }, GLOBAL.CLUSTERS.OPEN); - testUtils.testWithCluster('scripts', async cluster => { - assert.equal( - await cluster.square(2), - 4 - ); - }, { - ...GLOBAL.CLUSTERS.OPEN, - clusterConfiguration: { - scripts: { - square: SQUARE_SCRIPT - } - } - }); +// testUtils.testWithCluster('scripts', async cluster => { +// assert.equal( +// await cluster.square(2), +// 4 +// ); +// }, { +// ...GLOBAL.CLUSTERS.OPEN, +// clusterConfiguration: { +// scripts: { +// square: SQUARE_SCRIPT +// } +// } +// }); - it('should throw RootNodesUnavailableError', async () => { - const cluster = RedisCluster.create({ - rootNodes: [] - }); +// it('should throw RootNodesUnavailableError', async () => { +// const cluster = RedisCluster.create({ +// rootNodes: [] +// }); - try { - await assert.rejects( - cluster.connect(), - RootNodesUnavailableError - ); - } catch (err) { - await cluster.disconnect(); - throw err; - } - }); +// try { +// await assert.rejects( +// cluster.connect(), +// RootNodesUnavailableError +// ); +// } catch (err) { +// await cluster.disconnect(); +// throw err; +// } +// }); - testUtils.testWithCluster('should handle live resharding', async cluster => { - const slot = 12539, - key = 'key', - value = 'value'; - await cluster.set(key, value); +// testUtils.testWithCluster('should handle live resharding', async cluster => { +// const slot = 12539, +// key = 'key', +// value = 'value'; +// await cluster.set(key, value); - const importing = cluster.slots[0].master, - migrating = cluster.slots[slot].master, - [ importingClient, migratingClient ] = await Promise.all([ - cluster.nodeClient(importing), - cluster.nodeClient(migrating) - ]); +// const importing = cluster.slots[0].master, +// migrating = cluster.slots[slot].master, +// [ importingClient, migratingClient ] = await Promise.all([ +// cluster.nodeClient(importing), +// cluster.nodeClient(migrating) +// ]); - await Promise.all([ - importingClient.clusterSetSlot(slot, ClusterSlotStates.IMPORTING, migrating.id), - migratingClient.clusterSetSlot(slot, ClusterSlotStates.MIGRATING, importing.id) - ]); +// await Promise.all([ +// importingClient.clusterSetSlot(slot, ClusterSlotStates.IMPORTING, migrating.id), +// migratingClient.clusterSetSlot(slot, ClusterSlotStates.MIGRATING, importing.id) +// ]); - // should be able to get the key from the migrating node - assert.equal( - await cluster.get(key), - value - ); +// // should be able to get the key from the migrating node +// assert.equal( +// await cluster.get(key), +// value +// ); - await migratingClient.migrate( - importing.host, - importing.port, - key, - 0, - 10 - ); +// await migratingClient.migrate( +// importing.host, +// importing.port, +// key, +// 0, +// 10 +// ); - // should be able to get the key from the importing node using `ASKING` - assert.equal( - await cluster.get(key), - value - ); +// // should be able to get the key from the importing node using `ASKING` +// assert.equal( +// await cluster.get(key), +// value +// ); - await Promise.all([ - importingClient.clusterSetSlot(slot, ClusterSlotStates.NODE, importing.id), - migratingClient.clusterSetSlot(slot, ClusterSlotStates.NODE, importing.id), - ]); +// await Promise.all([ +// importingClient.clusterSetSlot(slot, ClusterSlotStates.NODE, importing.id), +// migratingClient.clusterSetSlot(slot, ClusterSlotStates.NODE, importing.id), +// ]); - // should handle `MOVED` errors - assert.equal( - await cluster.get(key), - value - ); - }, { - serverArguments: [], - numberOfMasters: 2 - }); +// // should handle `MOVED` errors +// assert.equal( +// await cluster.get(key), +// value +// ); +// }, { +// serverArguments: [], +// numberOfMasters: 2 +// }); - testUtils.testWithCluster('getRandomNode should spread the the load evenly', async cluster => { - const totalNodes = cluster.masters.length + cluster.replicas.length, - ids = new Set(); - for (let i = 0; i < totalNodes; i++) { - ids.add(cluster.getRandomNode().id); - } +// testUtils.testWithCluster('getRandomNode should spread the the load evenly', async cluster => { +// const totalNodes = cluster.masters.length + cluster.replicas.length, +// ids = new Set(); +// for (let i = 0; i < totalNodes; i++) { +// ids.add(cluster.getRandomNode().id); +// } - assert.equal(ids.size, totalNodes); - }, GLOBAL.CLUSTERS.WITH_REPLICAS); +// assert.equal(ids.size, totalNodes); +// }, GLOBAL.CLUSTERS.WITH_REPLICAS); - testUtils.testWithCluster('getSlotRandomNode should spread the the load evenly', async cluster => { - const totalNodes = 1 + cluster.slots[0].replicas!.length, - ids = new Set(); - for (let i = 0; i < totalNodes; i++) { - ids.add(cluster.getSlotRandomNode(0).id); - } +// testUtils.testWithCluster('getSlotRandomNode should spread the the load evenly', async cluster => { +// const totalNodes = 1 + cluster.slots[0].replicas!.length, +// ids = new Set(); +// for (let i = 0; i < totalNodes; i++) { +// ids.add(cluster.getSlotRandomNode(0).id); +// } - assert.equal(ids.size, totalNodes); - }, GLOBAL.CLUSTERS.WITH_REPLICAS); +// assert.equal(ids.size, totalNodes); +// }, GLOBAL.CLUSTERS.WITH_REPLICAS); - testUtils.testWithCluster('cluster topology', async cluster => { - assert.equal(cluster.slots.length, 16384); - const { numberOfMasters, numberOfReplicas } = GLOBAL.CLUSTERS.WITH_REPLICAS; - assert.equal(cluster.shards.length, numberOfMasters); - assert.equal(cluster.masters.length, numberOfMasters); - assert.equal(cluster.replicas.length, numberOfReplicas * numberOfMasters); - assert.equal(cluster.nodeByAddress.size, numberOfMasters + numberOfMasters * numberOfReplicas); - }, GLOBAL.CLUSTERS.WITH_REPLICAS); +// testUtils.testWithCluster('cluster topology', async cluster => { +// assert.equal(cluster.slots.length, 16384); +// const { numberOfMasters, numberOfReplicas } = GLOBAL.CLUSTERS.WITH_REPLICAS; +// assert.equal(cluster.shards.length, numberOfMasters); +// assert.equal(cluster.masters.length, numberOfMasters); +// assert.equal(cluster.replicas.length, numberOfReplicas * numberOfMasters); +// assert.equal(cluster.nodeByAddress.size, numberOfMasters + numberOfMasters * numberOfReplicas); +// }, GLOBAL.CLUSTERS.WITH_REPLICAS); - testUtils.testWithCluster('getMasters should be backwards competiable (without `minimizeConnections`)', async cluster => { - const masters = cluster.getMasters(); - assert.ok(Array.isArray(masters)); - for (const master of masters) { - assert.equal(typeof master.id, 'string'); - assert.ok(master.client instanceof RedisClient); - } - }, { - ...GLOBAL.CLUSTERS.OPEN, - clusterConfiguration: { - minimizeConnections: undefined // reset to default - } - }); +// testUtils.testWithCluster('getMasters should be backwards competiable (without `minimizeConnections`)', async cluster => { +// const masters = cluster.getMasters(); +// assert.ok(Array.isArray(masters)); +// for (const master of masters) { +// assert.equal(typeof master.id, 'string'); +// assert.ok(master.client instanceof RedisClient); +// } +// }, { +// ...GLOBAL.CLUSTERS.OPEN, +// clusterConfiguration: { +// minimizeConnections: undefined // reset to default +// } +// }); - testUtils.testWithCluster('getSlotMaster should be backwards competiable (without `minimizeConnections`)', async cluster => { - const master = cluster.getSlotMaster(0); - assert.equal(typeof master.id, 'string'); - assert.ok(master.client instanceof RedisClient); - }, { - ...GLOBAL.CLUSTERS.OPEN, - clusterConfiguration: { - minimizeConnections: undefined // reset to default - } - }); +// testUtils.testWithCluster('getSlotMaster should be backwards competiable (without `minimizeConnections`)', async cluster => { +// const master = cluster.getSlotMaster(0); +// assert.equal(typeof master.id, 'string'); +// assert.ok(master.client instanceof RedisClient); +// }, { +// ...GLOBAL.CLUSTERS.OPEN, +// clusterConfiguration: { +// minimizeConnections: undefined // reset to default +// } +// }); - testUtils.testWithCluster('should throw CROSSSLOT error', async cluster => { - await assert.rejects(cluster.mGet(['a', 'b'])); - }, GLOBAL.CLUSTERS.OPEN); +// testUtils.testWithCluster('should throw CROSSSLOT error', async cluster => { +// await assert.rejects(cluster.mGet(['a', 'b'])); +// }, GLOBAL.CLUSTERS.OPEN); - testUtils.testWithCluster('should send commands with commandOptions to correct cluster slot (without redirections)', async cluster => { - // 'a' and 'b' hash to different cluster slots (see previous unit test) - // -> maxCommandRedirections 0: rejects on MOVED/ASK reply - await cluster.set(commandOptions({ isolated: true }), 'a', '1'), - await cluster.set(commandOptions({ isolated: true }), 'b', '2'), +// testUtils.testWithCluster('should send commands with commandOptions to correct cluster slot (without redirections)', async cluster => { +// // 'a' and 'b' hash to different cluster slots (see previous unit test) +// // -> maxCommandRedirections 0: rejects on MOVED/ASK reply +// await cluster.set(commandOptions({ isolated: true }), 'a', '1'), +// await cluster.set(commandOptions({ isolated: true }), 'b', '2'), - assert.equal(await cluster.get('a'), '1'); - assert.equal(await cluster.get('b'), '2'); - }, { - ...GLOBAL.CLUSTERS.OPEN, - clusterConfiguration: { - maxCommandRedirections: 0 - } - }); +// assert.equal(await cluster.get('a'), '1'); +// assert.equal(await cluster.get('b'), '2'); +// }, { +// ...GLOBAL.CLUSTERS.OPEN, +// clusterConfiguration: { +// maxCommandRedirections: 0 +// } +// }); - describe('minimizeConnections', () => { - testUtils.testWithCluster('false', async cluster => { - for (const master of cluster.masters) { - assert.ok(master.client instanceof RedisClient); - } - }, { - ...GLOBAL.CLUSTERS.OPEN, - clusterConfiguration: { - minimizeConnections: false - } - }); +// describe('minimizeConnections', () => { +// testUtils.testWithCluster('false', async cluster => { +// for (const master of cluster.masters) { +// assert.ok(master.client instanceof RedisClient); +// } +// }, { +// ...GLOBAL.CLUSTERS.OPEN, +// clusterConfiguration: { +// minimizeConnections: false +// } +// }); - testUtils.testWithCluster('true', async cluster => { - for (const master of cluster.masters) { - assert.equal(master.client, undefined); - } - }, { - ...GLOBAL.CLUSTERS.OPEN, - clusterConfiguration: { - minimizeConnections: true - } - }); - }); +// testUtils.testWithCluster('true', async cluster => { +// for (const master of cluster.masters) { +// assert.equal(master.client, undefined); +// } +// }, { +// ...GLOBAL.CLUSTERS.OPEN, +// clusterConfiguration: { +// minimizeConnections: true +// } +// }); +// }); - describe('PubSub', () => { - testUtils.testWithCluster('subscribe & unsubscribe', async cluster => { - const listener = spy(); +// describe('PubSub', () => { +// testUtils.testWithCluster('subscribe & unsubscribe', async cluster => { +// const listener = spy(); - await cluster.subscribe('channel', listener); +// await cluster.subscribe('channel', listener); - await Promise.all([ - waitTillBeenCalled(listener), - cluster.publish('channel', 'message') - ]); +// await Promise.all([ +// waitTillBeenCalled(listener), +// cluster.publish('channel', 'message') +// ]); - assert.ok(listener.calledOnceWithExactly('message', 'channel')); +// assert.ok(listener.calledOnceWithExactly('message', 'channel')); - await cluster.unsubscribe('channel', listener); +// await cluster.unsubscribe('channel', listener); - assert.equal(cluster.pubSubNode, undefined); - }, GLOBAL.CLUSTERS.OPEN); +// assert.equal(cluster.pubSubNode, undefined); +// }, GLOBAL.CLUSTERS.OPEN); - testUtils.testWithCluster('psubscribe & punsubscribe', async cluster => { - const listener = spy(); +// testUtils.testWithCluster('psubscribe & punsubscribe', async cluster => { +// const listener = spy(); - await cluster.pSubscribe('channe*', listener); +// await cluster.pSubscribe('channe*', listener); - await Promise.all([ - waitTillBeenCalled(listener), - cluster.publish('channel', 'message') - ]); +// await Promise.all([ +// waitTillBeenCalled(listener), +// cluster.publish('channel', 'message') +// ]); - assert.ok(listener.calledOnceWithExactly('message', 'channel')); +// assert.ok(listener.calledOnceWithExactly('message', 'channel')); - await cluster.pUnsubscribe('channe*', listener); +// await cluster.pUnsubscribe('channe*', listener); - assert.equal(cluster.pubSubNode, undefined); - }, GLOBAL.CLUSTERS.OPEN); +// assert.equal(cluster.pubSubNode, undefined); +// }, GLOBAL.CLUSTERS.OPEN); - testUtils.testWithCluster('should move listeners when PubSub node disconnects from the cluster', async cluster => { - const listener = spy(); - await cluster.subscribe('channel', listener); +// testUtils.testWithCluster('should move listeners when PubSub node disconnects from the cluster', async cluster => { +// const listener = spy(); +// await cluster.subscribe('channel', listener); - assert.ok(cluster.pubSubNode); - const [ migrating, importing ] = cluster.masters[0].address === cluster.pubSubNode.address ? - cluster.masters : - [cluster.masters[1], cluster.masters[0]], - [ migratingClient, importingClient ] = await Promise.all([ - cluster.nodeClient(migrating), - cluster.nodeClient(importing) - ]); +// assert.ok(cluster.pubSubNode); +// const [ migrating, importing ] = cluster.masters[0].address === cluster.pubSubNode.address ? +// cluster.masters : +// [cluster.masters[1], cluster.masters[0]], +// [ migratingClient, importingClient ] = await Promise.all([ +// cluster.nodeClient(migrating), +// cluster.nodeClient(importing) +// ]); - const range = cluster.slots[0].master === migrating ? { - key: 'bar', // 5061 - start: 0, - end: 8191 - } : { - key: 'foo', // 12182 - start: 8192, - end: 16383 - }; +// const range = cluster.slots[0].master === migrating ? { +// key: 'bar', // 5061 +// start: 0, +// end: 8191 +// } : { +// key: 'foo', // 12182 +// start: 8192, +// end: 16383 +// }; - await Promise.all([ - migratingClient.clusterDelSlotsRange(range), - importingClient.clusterDelSlotsRange(range), - importingClient.clusterAddSlotsRange(range) - ]); +// await Promise.all([ +// migratingClient.clusterDelSlotsRange(range), +// importingClient.clusterDelSlotsRange(range), +// importingClient.clusterAddSlotsRange(range) +// ]); - // wait for migrating node to be notified about the new topology - while ((await migratingClient.clusterInfo()).state !== 'ok') { - await promiseTimeout(50); - } +// // wait for migrating node to be notified about the new topology +// while ((await migratingClient.clusterInfo()).state !== 'ok') { +// await promiseTimeout(50); +// } - // make sure to cause `MOVED` error - await cluster.get(range.key); +// // make sure to cause `MOVED` error +// await cluster.get(range.key); - await Promise.all([ - cluster.publish('channel', 'message'), - waitTillBeenCalled(listener) - ]); +// await Promise.all([ +// cluster.publish('channel', 'message'), +// waitTillBeenCalled(listener) +// ]); - assert.ok(listener.calledOnceWithExactly('message', 'channel')); - }, { - serverArguments: [], - numberOfMasters: 2, - minimumDockerVersion: [7] - }); +// assert.ok(listener.calledOnceWithExactly('message', 'channel')); +// }, { +// serverArguments: [], +// numberOfMasters: 2, +// minimumDockerVersion: [7] +// }); - testUtils.testWithCluster('ssubscribe & sunsubscribe', async cluster => { - const listener = spy(); +// testUtils.testWithCluster('ssubscribe & sunsubscribe', async cluster => { +// const listener = spy(); - await cluster.sSubscribe('channel', listener); +// await cluster.sSubscribe('channel', listener); - await Promise.all([ - waitTillBeenCalled(listener), - cluster.sPublish('channel', 'message') - ]); +// await Promise.all([ +// waitTillBeenCalled(listener), +// cluster.sPublish('channel', 'message') +// ]); - assert.ok(listener.calledOnceWithExactly('message', 'channel')); +// assert.ok(listener.calledOnceWithExactly('message', 'channel')); - await cluster.sUnsubscribe('channel', listener); +// await cluster.sUnsubscribe('channel', listener); - // 10328 is the slot of `channel` - assert.equal(cluster.slots[10328].master.pubSubClient, undefined); - }, { - ...GLOBAL.CLUSTERS.OPEN, - minimumDockerVersion: [7] - }); +// // 10328 is the slot of `channel` +// assert.equal(cluster.slots[10328].master.pubSubClient, undefined); +// }, { +// ...GLOBAL.CLUSTERS.OPEN, +// minimumDockerVersion: [7] +// }); - testUtils.testWithCluster('should handle sharded-channel-moved events', async cluster => { - const SLOT = 10328, - migrating = cluster.slots[SLOT].master, - importing = cluster.masters.find(master => master !== migrating)!, - [ migratingClient, importingClient ] = await Promise.all([ - cluster.nodeClient(migrating), - cluster.nodeClient(importing) - ]); +// testUtils.testWithCluster('should handle sharded-channel-moved events', async cluster => { +// const SLOT = 10328, +// migrating = cluster.slots[SLOT].master, +// importing = cluster.masters.find(master => master !== migrating)!, +// [ migratingClient, importingClient ] = await Promise.all([ +// cluster.nodeClient(migrating), +// cluster.nodeClient(importing) +// ]); - await Promise.all([ - migratingClient.clusterDelSlots(SLOT), - importingClient.clusterDelSlots(SLOT), - importingClient.clusterAddSlots(SLOT) - ]); +// await Promise.all([ +// migratingClient.clusterDelSlots(SLOT), +// importingClient.clusterDelSlots(SLOT), +// importingClient.clusterAddSlots(SLOT) +// ]); - // wait for migrating node to be notified about the new topology - while ((await migratingClient.clusterInfo()).state !== 'ok') { - await promiseTimeout(50); - } +// // wait for migrating node to be notified about the new topology +// while ((await migratingClient.clusterInfo()).state !== 'ok') { +// await promiseTimeout(50); +// } - const listener = spy(); +// const listener = spy(); - // will trigger `MOVED` error - await cluster.sSubscribe('channel', listener); +// // will trigger `MOVED` error +// await cluster.sSubscribe('channel', listener); - await Promise.all([ - waitTillBeenCalled(listener), - cluster.sPublish('channel', 'message') - ]); +// await Promise.all([ +// waitTillBeenCalled(listener), +// cluster.sPublish('channel', 'message') +// ]); - assert.ok(listener.calledOnceWithExactly('message', 'channel')); - }, { - serverArguments: [], - minimumDockerVersion: [7] - }); - }); -}); +// assert.ok(listener.calledOnceWithExactly('message', 'channel')); +// }, { +// serverArguments: [], +// minimumDockerVersion: [7] +// }); +// }); +// }); diff --git a/packages/client/lib/commands/APPEND.spec.ts b/packages/client/lib/commands/APPEND.spec.ts index 4481c0571e..c85501f4a0 100644 --- a/packages/client/lib/commands/APPEND.spec.ts +++ b/packages/client/lib/commands/APPEND.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import APPEND from './APPEND'; -describe.only('APPEND', () => { +describe('APPEND', () => { it('transformArguments', () => { assert.deepEqual( APPEND.transformArguments('key', 'value'), diff --git a/packages/client/lib/commands/PING.spec.ts b/packages/client/lib/commands/PING.spec.ts index fa2a8b172f..5ea68074d7 100644 --- a/packages/client/lib/commands/PING.spec.ts +++ b/packages/client/lib/commands/PING.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import PING from './PING'; -describe.only('PING', () => { +describe('PING', () => { describe('transformArguments', () => { it('default', () => { assert.deepEqual(