-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
server_discovery_and_monitoring.spec.test.js
84 lines (68 loc) · 2.59 KB
/
server_discovery_and_monitoring.spec.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
const { TestRunnerContext, generateTopologyTests } = require('../../tools/spec-runner');
const { loadSpecTests } = require('../../spec');
class SDAMRunnerContext extends TestRunnerContext {
constructor() {
super();
this.currentPrimary = null;
}
configureFailPoint(args) {
return this.enableFailPoint(args.failPoint);
}
recordPrimary(client) {
const servers = client.topology.description.servers;
const primary = Array.from(servers.values()).filter(sd => sd.type === 'RSPrimary')[0];
this.currentPrimary = primary.address;
}
waitForPrimaryChange(client) {
const currentPrimary = this.currentPrimary;
return new Promise(resolve => {
function eventHandler(event) {
if (
event.newDescription.type === 'RSPrimary' &&
event.newDescription.address !== currentPrimary
) {
resolve();
client.removeListener('serverDescriptionChanged', eventHandler);
}
}
client.on('serverDescriptionChanged', eventHandler);
});
}
}
// 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
// Some tests are failing when setting a failCommand when auth is enabled.
const isAuthEnabled = process.env.AUTH === 'auth';
const failpointTests = [
'Reset server and pool after AuthenticationFailure error',
'Reset server and pool after misc command error',
'Reset server and pool after network error during authentication',
'Reset server and pool after network timeout error during authentication',
'Reset server and pool after shutdown error during authentication'
];
// TODO: NODE-3135 - make CMAP SDAM-aware and ensure PoolClearError is retryable
const cmapSkippedTests = ['PoolClearedError does not mark server unknown'];
const skippedTests = isAuthEnabled ? failpointTests.concat(cmapSkippedTests) : cmapSkippedTests;
function sdamDisabledTestFilter(test) {
const { description } = test;
return !skippedTests.includes(description);
}
describe('SDAM', function () {
describe('integration spec tests', function () {
const testContext = new SDAMRunnerContext();
const testSuites = loadSpecTests('server-discovery-and-monitoring/integration');
beforeEach(async function () {
if (this.configuration.isLoadBalanced) {
this.currentTest.skipReason = 'Cannot run in a loadBalanced environment';
this.skip();
}
});
beforeEach(async function () {
await testContext.setup(this.configuration);
});
afterEach(async () => {
await testContext.teardown();
});
generateTopologyTests(testSuites, testContext, sdamDisabledTestFilter);
});
});