@@ -27,74 +27,76 @@ describe('e2e direct connection', () => {
27
27
} ) ;
28
28
} ) ;
29
29
30
- it ( 'allows to initialize the replica set' , async ( ) => {
31
- const replSetConfig = {
32
- _id : replSetId ,
33
- version : 1 ,
34
- members : [
35
- { _id : 0 , host : await rs0 . hostport ( ) , priority : 1 } ,
36
- { _id : 1 , host : await rs1 . hostport ( ) , priority : 0 } ,
37
- { _id : 2 , host : await rs2 . hostport ( ) , priority : 0 } ,
38
- ]
39
- } ;
30
+ context ( 'after rs.initiate()' , ( ) => {
31
+ before ( async ( ) => {
32
+ const replSetConfig = {
33
+ _id : replSetId ,
34
+ version : 1 ,
35
+ members : [
36
+ { _id : 0 , host : await rs0 . hostport ( ) , priority : 1 } ,
37
+ { _id : 1 , host : await rs1 . hostport ( ) , priority : 0 } ,
38
+ { _id : 2 , host : await rs2 . hostport ( ) , priority : 0 } ,
39
+ ]
40
+ } ;
40
41
41
- const shell = TestShell . start ( { args : [ await rs0 . connectionString ( ) ] } ) ;
42
- await shell . waitForPrompt ( ) ;
43
- await shell . executeLine ( `rs.initiate(${ JSON . stringify ( replSetConfig ) } )` ) ;
44
- shell . assertContainsOutput ( 'ok: 1' ) ;
45
- await eventually ( async ( ) => {
46
- await shell . executeLine ( 'db.isMaster()' ) ;
47
- shell . assertContainsOutput ( 'ismaster: true' ) ;
48
- shell . assertContainsOutput ( `me: '${ await rs0 . hostport ( ) } '` ) ;
49
- shell . assertContainsOutput ( `setName: '${ replSetId } '` ) ;
50
- } ) ;
51
- } ) ;
52
-
53
- context ( 'connecting to secondary members directly' , ( ) => {
54
- it ( 'works when specifying a connection string' , async ( ) => {
55
- const shell = TestShell . start ( { args : [ await rs1 . connectionString ( ) ] } ) ;
42
+ const shell = TestShell . start ( { args : [ await rs0 . connectionString ( ) ] } ) ;
56
43
await shell . waitForPrompt ( ) ;
57
- await shell . executeLine ( 'db.isMaster()' ) ;
58
- shell . assertContainsOutput ( 'ismaster: false' ) ;
59
- shell . assertContainsOutput ( `me: '${ await rs1 . hostport ( ) } '` ) ;
60
- shell . assertContainsOutput ( `setName: '${ replSetId } '` ) ;
44
+ await shell . executeLine ( `rs.initiate(${ JSON . stringify ( replSetConfig ) } )` ) ;
45
+ shell . assertContainsOutput ( 'ok: 1' ) ;
46
+ await eventually ( async ( ) => {
47
+ await shell . executeLine ( 'db.isMaster()' ) ;
48
+ shell . assertContainsOutput ( 'ismaster: true' ) ;
49
+ shell . assertContainsOutput ( `me: '${ await rs0 . hostport ( ) } '` ) ;
50
+ shell . assertContainsOutput ( `setName: '${ replSetId } '` ) ;
51
+ } ) ;
61
52
} ) ;
62
53
63
- it ( 'works when specifying just host and port ', async ( ) => {
64
- const shell = TestShell . start ( { args : [ await rs1 . hostport ( ) ] } ) ;
65
- await shell . waitForPrompt ( ) ;
66
- await shell . executeLine ( 'db.isMaster()' ) ;
67
- shell . assertContainsOutput ( 'ismaster: false ') ;
68
- shell . assertContainsOutput ( `me: ' ${ await rs1 . hostport ( ) } '` ) ;
69
- shell . assertContainsOutput ( `setName : '${ replSetId } '` ) ;
70
- } ) ;
71
- } ) ;
54
+ context ( 'connecting to secondary members directly ', ( ) => {
55
+ it ( 'works when specifying a connection string' , async ( ) => {
56
+ const shell = TestShell . start ( { args : [ await rs1 . connectionString ( ) ] } ) ;
57
+ await shell . waitForPrompt ( ) ;
58
+ await shell . executeLine ( 'db.isMaster() ') ;
59
+ shell . assertContainsOutput ( 'ismaster: false' ) ;
60
+ shell . assertContainsOutput ( `me : '${ await rs1 . hostport ( ) } '` ) ;
61
+ shell . assertContainsOutput ( `setName: ' ${ replSetId } '` ) ;
62
+ } ) ;
72
63
73
- context ( 'connecting to primary ', ( ) => {
74
- it ( 'when specifying replicaSet' , async ( ) => {
75
- const shell = TestShell . start ( { args : [ ` ${ await rs1 . connectionString ( ) } ?replicaSet= ${ replSetId } ` ] } ) ;
76
- await shell . waitForPrompt ( ) ;
77
- await shell . executeLine ( 'db.isMaster() ') ;
78
- shell . assertContainsOutput ( 'ismaster: true' ) ;
79
- shell . assertContainsOutput ( `me : '${ await rs0 . hostport ( ) } '` ) ;
80
- shell . assertContainsOutput ( `setName: ' ${ replSetId } '` ) ;
64
+ it ( 'works when specifying just host and port ', async ( ) => {
65
+ const shell = TestShell . start ( { args : [ await rs1 . hostport ( ) ] } ) ;
66
+ await shell . waitForPrompt ( ) ;
67
+ await shell . executeLine ( 'db.isMaster()' ) ;
68
+ shell . assertContainsOutput ( 'ismaster: false ') ;
69
+ shell . assertContainsOutput ( `me: ' ${ await rs1 . hostport ( ) } '` ) ;
70
+ shell . assertContainsOutput ( `setName : '${ replSetId } '` ) ;
71
+ } ) ;
81
72
} ) ;
82
- it ( 'when setting directConnection to false' , async ( ) => {
83
- const shell = TestShell . start ( { args : [ `${ await rs1 . connectionString ( ) } ?directConnection=false` ] } ) ;
84
- await shell . waitForPrompt ( ) ;
85
- await shell . executeLine ( 'db.isMaster()' ) ;
86
- shell . assertContainsOutput ( 'ismaster: true' ) ;
87
- shell . assertContainsOutput ( `me: '${ await rs0 . hostport ( ) } '` ) ;
88
- shell . assertContainsOutput ( `setName: '${ replSetId } '` ) ;
89
- } ) ;
90
- it ( 'when specifying multiple seeds' , async ( ) => {
91
- const connectionString = 'mongodb://' + await rs2 . hostport ( ) + ',' + await rs1 . hostport ( ) + ',' + await rs0 . hostport ( ) ;
92
- const shell = TestShell . start ( { args : [ connectionString ] } ) ;
93
- await shell . waitForPrompt ( ) ;
94
- await shell . executeLine ( 'db.isMaster()' ) ;
95
- shell . assertContainsOutput ( 'ismaster: true' ) ;
96
- shell . assertContainsOutput ( `me: '${ await rs0 . hostport ( ) } '` ) ;
97
- shell . assertContainsOutput ( `setName: '${ replSetId } '` ) ;
73
+
74
+ context ( 'connecting to primary' , ( ) => {
75
+ it ( 'when specifying replicaSet' , async ( ) => {
76
+ const shell = TestShell . start ( { args : [ `${ await rs1 . connectionString ( ) } ?replicaSet=${ replSetId } ` ] } ) ;
77
+ await shell . waitForPrompt ( ) ;
78
+ await shell . executeLine ( 'db.isMaster()' ) ;
79
+ shell . assertContainsOutput ( 'ismaster: true' ) ;
80
+ shell . assertContainsOutput ( `me: '${ await rs0 . hostport ( ) } '` ) ;
81
+ shell . assertContainsOutput ( `setName: '${ replSetId } '` ) ;
82
+ } ) ;
83
+ it ( 'when setting directConnection to false' , async ( ) => {
84
+ const shell = TestShell . start ( { args : [ `${ await rs1 . connectionString ( ) } ?directConnection=false` ] } ) ;
85
+ await shell . waitForPrompt ( ) ;
86
+ await shell . executeLine ( 'db.isMaster()' ) ;
87
+ shell . assertContainsOutput ( 'ismaster: true' ) ;
88
+ shell . assertContainsOutput ( `me: '${ await rs0 . hostport ( ) } '` ) ;
89
+ shell . assertContainsOutput ( `setName: '${ replSetId } '` ) ;
90
+ } ) ;
91
+ it ( 'when specifying multiple seeds' , async ( ) => {
92
+ const connectionString = 'mongodb://' + await rs2 . hostport ( ) + ',' + await rs1 . hostport ( ) + ',' + await rs0 . hostport ( ) ;
93
+ const shell = TestShell . start ( { args : [ connectionString ] } ) ;
94
+ await shell . waitForPrompt ( ) ;
95
+ await shell . executeLine ( 'db.isMaster()' ) ;
96
+ shell . assertContainsOutput ( 'ismaster: true' ) ;
97
+ shell . assertContainsOutput ( `me: '${ await rs0 . hostport ( ) } '` ) ;
98
+ shell . assertContainsOutput ( `setName: '${ replSetId } '` ) ;
99
+ } ) ;
98
100
} ) ;
99
101
} ) ;
100
102
} ) ;
0 commit comments