1
1
import { strict as assert } from 'assert' ;
2
2
import testUtils , { GLOBAL } from '../test-utils' ;
3
+ import RedisCluster from '.' ;
3
4
import { ClusterSlotStates } from '../commands/CLUSTER_SETSLOT' ;
4
5
import { SQUARE_SCRIPT } from '../client/index.spec' ;
6
+ import { RootNodesUnavailableError } from '../errors' ;
5
7
6
8
// We need to use 'require', because it's not possible with Typescript to import
7
9
// function that are exported as 'module.exports = function`, without esModuleInterop
@@ -10,20 +12,14 @@ const calculateSlot = require('cluster-key-slot');
10
12
11
13
describe ( 'Cluster' , ( ) => {
12
14
testUtils . testWithCluster ( 'sendCommand' , async cluster => {
13
- await cluster . connect ( ) ;
14
-
15
- try {
16
- await cluster . publish ( 'channel' , 'message' ) ;
17
- await cluster . set ( 'a' , 'b' ) ;
18
- await cluster . set ( 'a{a}' , 'bb' ) ;
19
- await cluster . set ( 'aa' , 'bb' ) ;
20
- await cluster . get ( 'aa' ) ;
21
- await cluster . get ( 'aa' ) ;
22
- await cluster . get ( 'aa' ) ;
23
- await cluster . get ( 'aa' ) ;
24
- } finally {
25
- await cluster . disconnect ( ) ;
26
- }
15
+ await cluster . publish ( 'channel' , 'message' ) ;
16
+ await cluster . set ( 'a' , 'b' ) ;
17
+ await cluster . set ( 'a{a}' , 'bb' ) ;
18
+ await cluster . set ( 'aa' , 'bb' ) ;
19
+ await cluster . get ( 'aa' ) ;
20
+ await cluster . get ( 'aa' ) ;
21
+ await cluster . get ( 'aa' ) ;
22
+ await cluster . get ( 'aa' ) ;
27
23
} , GLOBAL . CLUSTERS . OPEN ) ;
28
24
29
25
testUtils . testWithCluster ( 'multi' , async cluster => {
@@ -51,6 +47,22 @@ describe('Cluster', () => {
51
47
}
52
48
} ) ;
53
49
50
+ it ( 'should throw RootNodesUnavailableError' , async ( ) => {
51
+ const cluster = RedisCluster . create ( {
52
+ rootNodes : [ ]
53
+ } ) ;
54
+
55
+ try {
56
+ await assert . rejects (
57
+ cluster . connect ( ) ,
58
+ RootNodesUnavailableError
59
+ ) ;
60
+ } catch ( err ) {
61
+ await cluster . disconnect ( ) ;
62
+ throw err ;
63
+ }
64
+ } ) ;
65
+
54
66
testUtils . testWithCluster ( 'should handle live resharding' , async cluster => {
55
67
const key = 'key' ,
56
68
value = 'value' ;
0 commit comments