forked from mongodb/node-mongodb-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopology_description.test.ts
93 lines (78 loc) · 3.17 KB
/
topology_description.test.ts
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { expect } from 'chai';
import {
getTopology,
type MongoClient,
type MongoClientOptions,
TopologyType
} from '../../mongodb';
describe('TopologyDescription (integration tests)', function () {
let client: MongoClient;
afterEach(async function () {
await client.close();
});
beforeEach(async function () {
client = this.configuration.newClient();
await client.connect();
});
context('options', function () {
let client: MongoClient;
afterEach(async function () {
await client.close();
});
beforeEach(async function () {
client = this.configuration.newClient();
});
context('localThresholdMS', function () {
it('should default to 15ms', async function () {
const options: MongoClientOptions = {};
client = await this.configuration.newClient(options).connect();
const topologyDescription = getTopology(client).description;
expect(topologyDescription).to.have.ownProperty('localThresholdMS').to.equal(15);
});
it('should be set to the localThresholdMS option when it is passed in', async function () {
const options: MongoClientOptions = {
localThresholdMS: 30
};
client = await this.configuration.newClient(options).connect();
const topologyDescription = getTopology(client).description;
expect(topologyDescription).to.have.ownProperty('localThresholdMS').to.equal(30);
});
});
});
context('topology types', function () {
const topologyTypesMap = new Map<TopologyTypeRequirement, TopologyType>([
['single', TopologyType.Single],
['replicaset', TopologyType.ReplicaSetWithPrimary],
['sharded', TopologyType.Sharded],
['load-balanced', TopologyType.LoadBalanced]
// Intentionally omitted ReplicaSetNoPrimary & Unknown
]);
for (const [filterType, driverType] of topologyTypesMap) {
it(
`when running against ${filterType} driver should declare ${driverType} topology type`,
{ requires: { topology: filterType } },
async () => {
await client.db().command({ ping: 1 });
expect(client.topology).to.exist;
expect(client.topology.description).to.exist;
expect(client.topology.description).to.have.property('type', driverType);
}
);
}
});
describe('json stringification', function () {
it('can be stringified without error', function () {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
const description = client.topology?.description!;
expect(description).to.exist;
expect(() => JSON.stringify(description)).not.to.throw;
});
it('properly stringifies the server description map', function () {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
const description = client.topology?.description!;
expect(description).to.exist;
const { servers } = JSON.parse(JSON.stringify(description));
expect(Object.keys(servers).length > 0, '`servers` stringified with no servers.').to.be.true;
});
});
});