1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

fix live resharding test

This commit is contained in:
leibale
2021-11-10 14:42:53 -05:00
parent f1f9c7ac24
commit 3d009780ee

View File

@@ -53,42 +53,43 @@ describe('Cluster', () => {
await cluster.set(key, value); await cluster.set(key, value);
const slot = calculateSlot(key), const slot = calculateSlot(key),
from = cluster.getSlotMaster(slot), source = cluster.getSlotMaster(slot),
to = cluster.getMasters().find(node => node.id !== from.id); destination = cluster.getMasters().find(node => node.id !== source.id)!;
await to!.client.clusterSetSlot(slot, ClusterSlotStates.IMPORTING, from.id); await Promise.all([
source.client.clusterSetSlot(slot, ClusterSlotStates.MIGRATING, destination.id),
destination.client.clusterSetSlot(slot, ClusterSlotStates.IMPORTING, destination.id)
]);
// should be able to get the key from the original node before it was migrated // should be able to get the key from the source node using "ASKING"
assert.equal( assert.equal(
await cluster.get(key), await cluster.get(key),
value value
); );
await from.client.clusterSetSlot(slot, ClusterSlotStates.MIGRATING, to!.id); await Promise.all([
source.client.migrate(
'127.0.0.1',
(<any>destination.client.options).socket.port,
key,
0,
10
)
]);
// should be able to get the key from the original node using the "ASKING" command // should be able to get the key from the destination node using the "ASKING" command
assert.equal( assert.equal(
await cluster.get(key), await cluster.get(key),
value value
); );
const { port: toPort } = <any>to!.client.options!.socket;
await from.client.migrate(
'127.0.0.1',
toPort,
key,
0,
10
);
await Promise.all( await Promise.all(
cluster.getMasters().map(({ client }) => { cluster.getMasters().map(({ client }) => {
return client.clusterSetSlot(slot, ClusterSlotStates.NODE, to!.id); return client.clusterSetSlot(slot, ClusterSlotStates.NODE, destination.id);
}) })
); );
// should be able to get the key from the new node // should handle "MOVED" errors
assert.equal( assert.equal(
await cluster.get(key), await cluster.get(key),
value value