You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
use dockers for tests, use npm workspaces, add rejson & redisearch modules, fix some bugs
This commit is contained in:
93
packages/client/lib/cluster/index.spec.ts
Normal file
93
packages/client/lib/cluster/index.spec.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import calculateSlot from 'cluster-key-slot';
|
||||
import { ClusterSlotStates } from '../commands/CLUSTER_SETSLOT';
|
||||
import { SQUARE_SCRIPT } from '../client/index.spec';
|
||||
|
||||
describe('Cluster', () => {
|
||||
testUtils.testWithCluster('sendCommand', async cluster => {
|
||||
await cluster.connect();
|
||||
|
||||
try {
|
||||
await cluster.publish('channel', 'message');
|
||||
await cluster.set('a', 'b');
|
||||
await cluster.set('a{a}', 'bb');
|
||||
await cluster.set('aa', 'bb');
|
||||
await cluster.get('aa');
|
||||
await cluster.get('aa');
|
||||
await cluster.get('aa');
|
||||
await cluster.get('aa');
|
||||
} finally {
|
||||
await cluster.disconnect();
|
||||
}
|
||||
}, 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('should handle live resharding', async cluster => {
|
||||
// const key = 'key',
|
||||
// value = 'value';
|
||||
// await cluster.set(key, value);
|
||||
|
||||
// const slot = calculateSlot(key),
|
||||
// from = cluster.getSlotMaster(slot),
|
||||
// to = cluster.getMasters().find(node => node.id !== from.id);
|
||||
|
||||
// await to!.client.clusterSetSlot(slot, ClusterSlotStates.IMPORTING, from.id);
|
||||
|
||||
// // should be able to get the key from the original node before it was migrated
|
||||
// assert.equal(
|
||||
// await cluster.get(key),
|
||||
// value
|
||||
// );
|
||||
|
||||
// await from.client.clusterSetSlot(slot, ClusterSlotStates.MIGRATING, to!.id);
|
||||
|
||||
// // should be able to get the key from the original node using the "ASKING" command
|
||||
// assert.equal(
|
||||
// await cluster.get(key),
|
||||
// value
|
||||
// );
|
||||
|
||||
// const { port: toPort } = <any>to!.client.options!.socket;
|
||||
|
||||
// await from.client.migrate(
|
||||
// '127.0.0.1',
|
||||
// toPort,
|
||||
// key,
|
||||
// 0,
|
||||
// 10
|
||||
// );
|
||||
|
||||
// // should be able to get the key from the new node
|
||||
// assert.equal(
|
||||
// await cluster.get(key),
|
||||
// value
|
||||
// );
|
||||
// }, {
|
||||
// serverArguments: []
|
||||
// });
|
||||
});
|
Reference in New Issue
Block a user