@@ -3,82 +3,29 @@ import { MongoClient } from 'mongodb';
33
44jasmine . DEFAULT_TIMEOUT_INTERVAL = 600000 ;
55
6- describe ( 'single server replset' , ( ) => {
7- let replSet : MongoMemoryReplSet ;
8- afterEach ( async ( ) => {
9- if ( ! ( replSet && replSet . _state === 'running' ) ) return ;
10- await replSet . stop ( ) ;
11- } ) ;
12-
13- it ( 'should enter running state' , async ( ) => {
14- replSet = new MongoMemoryReplSet ( ) ;
15- await replSet . waitUntilRunning ( ) ;
16- const uri = await replSet . getUri ( ) ;
17- expect ( uri . split ( ',' ) . length ) . toEqual ( 1 ) ;
18- } ) ;
19-
20- it ( 'should be able to get connection string to specific db' , async ( ) => {
21- replSet = new MongoMemoryReplSet ( ) ;
22- await replSet . waitUntilRunning ( ) ;
23- const uri = await replSet . getUri ( 'other' ) ;
24- const str = await replSet . getConnectionString ( 'other' ) ;
25- expect ( uri . split ( ',' ) . length ) . toEqual ( 1 ) ;
26- expect ( uri . endsWith ( '/other' ) ) . toBeTruthy ( ) ;
27- expect ( str ) . toEqual ( uri ) ;
28- } ) ;
29-
30- it ( 'should be able to get dbName' , async ( ) => {
31- const opts : any = { autoStart : false , replSet : { dbName : 'static' } } ;
32- replSet = new MongoMemoryReplSet ( opts ) ;
33- const dbName = await replSet . getDbName ( ) ;
34- expect ( dbName ) . toEqual ( 'static' ) ;
35- } ) ;
36-
37- it ( 'should not autostart if autostart: false' , async ( ) => {
38- replSet = new MongoMemoryReplSet ( { autoStart : false } ) ;
39- await new Promise ( ( resolve , reject ) => {
40- replSet . once ( 'state' , ( state ) => reject ( new Error ( `Invalid state: ${ state } ` ) ) ) ;
41- setTimeout ( resolve , 500 ) ;
42- } ) ;
43- } ) ;
44-
45- it ( 'should be possible to connect replicaset after waitUntilRunning resolveds' , async ( ) => {
46- replSet = new MongoMemoryReplSet ( ) ;
47- await replSet . waitUntilRunning ( ) ;
48- const uri = await replSet . getUri ( ) ;
49-
50- await MongoClient . connect ( `${ uri } ?replicaSet=testset` , {
51- useNewUrlParser : true ,
52- useUnifiedTopology : true ,
53- } ) ;
54- } ) ;
55- } ) ;
56-
576describe ( 'multi-member replica set' , ( ) => {
58- let replSet : MongoMemoryReplSet ;
59- afterEach ( async ( ) => {
60- if ( ! replSet ) return ;
61- await replSet . stop ( ) ;
62- } ) ;
63-
64- it ( 'should enter running state' , async ( ) => {
7+ it . only ( 'should enter running state' , async ( ) => {
658 const opts : any = { replSet : { count : 3 } } ;
66- replSet = new MongoMemoryReplSet ( opts ) ;
9+ const replSet = new MongoMemoryReplSet ( opts ) ;
6710 await replSet . waitUntilRunning ( ) ;
6811 expect ( replSet . servers . length ) . toEqual ( 3 ) ;
6912 const uri = await replSet . getUri ( ) ;
7013 expect ( uri . split ( ',' ) . length ) . toEqual ( 3 ) ;
14+
15+ await replSet . stop ( ) ;
7116 } , 40000 ) ;
7217
7318 it ( 'should be possible to connect replicaset after waitUntilRunning resolveds' , async ( ) => {
7419 const opts : any = { replSet : { count : 3 } } ;
75- replSet = new MongoMemoryReplSet ( opts ) ;
20+ const replSet = new MongoMemoryReplSet ( opts ) ;
7621 await replSet . waitUntilRunning ( ) ;
7722 const uri = await replSet . getUri ( ) ;
7823
7924 await MongoClient . connect ( `${ uri } ?replicaSet=testset` , {
8025 useNewUrlParser : true ,
8126 useUnifiedTopology : true ,
8227 } ) ;
28+
29+ await replSet . stop ( ) ;
8330 } ) ;
8431} ) ;
0 commit comments