-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
replset-test.js
64 lines (55 loc) · 1.99 KB
/
replset-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// @flow
import MongoMemoryReplSet from '../MongoMemoryReplSet';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
describe('single server replset', () => {
let replSet: MongoMemoryReplSet;
afterEach(async () => {
if (!(replSet && replSet._state === 'running')) return;
await replSet.stop();
replSet = (null: any);
});
it('should enter running state', async () => {
replSet = new MongoMemoryReplSet();
await replSet.waitUntilRunning();
const uri = await replSet.getUri();
expect(uri.split(',').length).toEqual(1);
});
it('should be able to get connection string to specific db', async () => {
replSet = new MongoMemoryReplSet();
await replSet.waitUntilRunning();
const uri = await replSet.getUri('other');
const str = await replSet.getConnectionString('other');
expect(uri.split(',').length).toEqual(1);
expect(uri.endsWith('/other')).toBeTruthy();
expect(str).toEqual(uri);
});
it('should be able to get dbName', async () => {
const opts: any = { autoStart: false, replSet: { dbName: 'static' } };
replSet = new MongoMemoryReplSet(opts);
const dbName = await replSet.getDbName();
expect(dbName).toEqual('static');
});
it('should not autostart if autostart: false', async () => {
replSet = new MongoMemoryReplSet({ autoStart: false });
await new Promise((resolve, reject) => {
replSet.once('state', state => reject(new Error(`Invalid state: ${state}`)));
setTimeout(resolve, 500);
});
});
});
describe('multi-member replica set', () => {
let replSet: MongoMemoryReplSet;
afterEach(async () => {
if (!replSet) return;
await replSet.stop();
replSet = (null: any);
});
it('should enter running state', async () => {
const opts: any = { replSet: { count: 3 } };
replSet = new MongoMemoryReplSet(opts);
await replSet.waitUntilRunning();
expect(replSet.servers.length).toEqual(3);
const uri = await replSet.getUri();
expect(uri.split(',').length).toEqual(3);
}, 40000);
});