From 8b3daad88a70bf5e31c2a8e80d5f3000d0d2660c Mon Sep 17 00:00:00 2001 From: leibale Date: Tue, 9 Nov 2021 13:38:08 -0500 Subject: [PATCH] uncomment "should handle live resharding" test --- packages/client/lib/cluster/index.spec.ts | 71 ++++++++++++----------- packages/test-utils/lib/index.ts | 6 +- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/packages/client/lib/cluster/index.spec.ts b/packages/client/lib/cluster/index.spec.ts index 43492a6500..a4c4489ee7 100644 --- a/packages/client/lib/cluster/index.spec.ts +++ b/packages/client/lib/cluster/index.spec.ts @@ -47,47 +47,48 @@ describe('Cluster', () => { } }); - // testUtils.testWithCluster('should handle live resharding', async cluster => { - // const key = 'key', - // value = 'value'; - // await cluster.set(key, value); + 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); + 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); + 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 - // ); + // 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); + 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 - // ); + // 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 } = to!.client.options!.socket; + const { port: toPort } = to!.client.options!.socket; - // await from.client.migrate( - // '127.0.0.1', - // toPort, - // key, - // 0, - // 10 - // ); + 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: [] - // }); + // should be able to get the key from the new node + assert.equal( + await cluster.get(key), + value + ); + }, { + serverArguments: [], + numberOfNodes: 2 + }); }); diff --git a/packages/test-utils/lib/index.ts b/packages/test-utils/lib/index.ts index d6692cace6..f9a1fc1dbd 100644 --- a/packages/test-utils/lib/index.ts +++ b/packages/test-utils/lib/index.ts @@ -26,6 +26,7 @@ interface ClientTestOptions exte interface ClusterTestOptions extends CommonTestOptions { serverArguments: Array; clusterConfiguration?: Partial>; + numberOfNodes?: number; } export default class TestUtils { @@ -144,7 +145,10 @@ export default class TestUtils { before(function () { this.timeout(30000); - dockersPromise = spawnRedisCluster(dockerImage, options.serverArguments); + dockersPromise = spawnRedisCluster({ + ...dockerImage, + numberOfNodes: options?.numberOfNodes + }, options.serverArguments); return dockersPromise; }); }