You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
add test for RootNodesUnavailableError
This commit is contained in:
@@ -2,6 +2,7 @@ import RedisClient, { InstantiableRedisClient, RedisClientType } from '../client
|
|||||||
import { RedisClusterMasterNode, RedisClusterReplicaNode } from '../commands/CLUSTER_NODES';
|
import { RedisClusterMasterNode, RedisClusterReplicaNode } from '../commands/CLUSTER_NODES';
|
||||||
import { RedisClusterClientOptions, RedisClusterOptions } from '.';
|
import { RedisClusterClientOptions, RedisClusterOptions } from '.';
|
||||||
import { RedisCommandArgument, RedisModules, RedisScripts } from '../commands';
|
import { RedisCommandArgument, RedisModules, RedisScripts } from '../commands';
|
||||||
|
import { RootNodesUnavailableError } from '../errors';
|
||||||
|
|
||||||
// We need to use 'require', because it's not possible with Typescript to import
|
// We need to use 'require', because it's not possible with Typescript to import
|
||||||
// function that are exported as 'module.exports = function`, without esModuleInterop
|
// function that are exported as 'module.exports = function`, without esModuleInterop
|
||||||
@@ -39,7 +40,7 @@ export default class RedisClusterSlots<M extends RedisModules, S extends RedisSc
|
|||||||
if (await this.#discoverNodes(this.#clientOptionsDefaults(rootNode))) return;
|
if (await this.#discoverNodes(this.#clientOptionsDefaults(rootNode))) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('None of the root nodes is available');
|
throw new RootNodesUnavailableError();
|
||||||
}
|
}
|
||||||
|
|
||||||
async #discoverNodes(clientOptions?: RedisClusterClientOptions): Promise<boolean> {
|
async #discoverNodes(clientOptions?: RedisClusterClientOptions): Promise<boolean> {
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import RedisCluster from '.';
|
||||||
import { ClusterSlotStates } from '../commands/CLUSTER_SETSLOT';
|
import { ClusterSlotStates } from '../commands/CLUSTER_SETSLOT';
|
||||||
import { SQUARE_SCRIPT } from '../client/index.spec';
|
import { SQUARE_SCRIPT } from '../client/index.spec';
|
||||||
|
import { RootNodesUnavailableError } from '../errors';
|
||||||
|
|
||||||
// We need to use 'require', because it's not possible with Typescript to import
|
// We need to use 'require', because it's not possible with Typescript to import
|
||||||
// function that are exported as 'module.exports = function`, without esModuleInterop
|
// function that are exported as 'module.exports = function`, without esModuleInterop
|
||||||
@@ -10,20 +12,14 @@ const calculateSlot = require('cluster-key-slot');
|
|||||||
|
|
||||||
describe('Cluster', () => {
|
describe('Cluster', () => {
|
||||||
testUtils.testWithCluster('sendCommand', async cluster => {
|
testUtils.testWithCluster('sendCommand', async cluster => {
|
||||||
await cluster.connect();
|
await cluster.publish('channel', 'message');
|
||||||
|
await cluster.set('a', 'b');
|
||||||
try {
|
await cluster.set('a{a}', 'bb');
|
||||||
await cluster.publish('channel', 'message');
|
await cluster.set('aa', 'bb');
|
||||||
await cluster.set('a', 'b');
|
await cluster.get('aa');
|
||||||
await cluster.set('a{a}', 'bb');
|
await cluster.get('aa');
|
||||||
await cluster.set('aa', 'bb');
|
await cluster.get('aa');
|
||||||
await cluster.get('aa');
|
await cluster.get('aa');
|
||||||
await cluster.get('aa');
|
|
||||||
await cluster.get('aa');
|
|
||||||
await cluster.get('aa');
|
|
||||||
} finally {
|
|
||||||
await cluster.disconnect();
|
|
||||||
}
|
|
||||||
}, GLOBAL.CLUSTERS.OPEN);
|
}, GLOBAL.CLUSTERS.OPEN);
|
||||||
|
|
||||||
testUtils.testWithCluster('multi', async cluster => {
|
testUtils.testWithCluster('multi', async cluster => {
|
||||||
@@ -51,6 +47,22 @@ describe('Cluster', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw RootNodesUnavailableError', async () => {
|
||||||
|
const cluster = RedisCluster.create({
|
||||||
|
rootNodes: []
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await assert.rejects(
|
||||||
|
cluster.connect(),
|
||||||
|
RootNodesUnavailableError
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
await cluster.disconnect();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
testUtils.testWithCluster('should handle live resharding', async cluster => {
|
testUtils.testWithCluster('should handle live resharding', async cluster => {
|
||||||
const key = 'key',
|
const key = 'key',
|
||||||
value = 'value';
|
value = 'value';
|
||||||
|
@@ -39,3 +39,9 @@ export class AuthError extends Error {
|
|||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class RootNodesUnavailableError extends Error {
|
||||||
|
constructor() {
|
||||||
|
super('All the root nodes are unavailable');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user