Skip to content

Commit df8ac73

Browse files
authored
refactor(NODE-3790): Remove oppressive language from test files (#3071)
1 parent f1979db commit df8ac73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+314
-216
lines changed

src/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,9 @@ export const MONGO_CLIENT_EVENTS = Object.freeze([
114114
...TOPOLOGY_EVENTS,
115115
...HEARTBEAT_EVENTS
116116
] as const);
117+
118+
/**
119+
* @internal
120+
* The legacy hello command that was deprecated in MongoDB 5.0.
121+
*/
122+
export const LEGACY_HELLO_COMMAND = 'ismaster';

src/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Document, ObjectId, resolveBSONOptions } from './bson';
77
import type { Connection } from './cmap/connection';
88
import { MAX_SUPPORTED_WIRE_VERSION } from './cmap/wire_protocol/constants';
99
import type { Collection } from './collection';
10+
import { LEGACY_HELLO_COMMAND } from './constants';
1011
import type { Db } from './db';
1112
import {
1213
AnyError,
@@ -1097,6 +1098,14 @@ export function isSuperset(set: Set<any> | any[], subset: Set<any> | any[]): boo
10971098
return true;
10981099
}
10991100

1101+
/**
1102+
* Checks if the document is a Hello request
1103+
* @internal
1104+
*/
1105+
export function isHello(doc: Document): boolean {
1106+
return doc[LEGACY_HELLO_COMMAND] || doc.hello ? true : false;
1107+
}
1108+
11001109
/** Returns the items that are uniquely in setA */
11011110
export function setDifference<T>(setA: Iterable<T>, setB: Iterable<T>): Set<T> {
11021111
const difference = new Set<T>(setA);

test/benchmarks/driverBench/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const MongoBench = require('../mongoBench');
55
const Runner = MongoBench.Runner;
66
const commonHelpers = require('./common');
77

8+
const { LEGACY_HELLO_COMMAND } = require('../../../src/constants');
9+
810
let BSON = require('bson');
911

1012
try {
@@ -110,7 +112,9 @@ function runCommand(done) {
110112
if (_id > 10000) {
111113
return done();
112114
}
113-
return this.db.command({ ismaster: true }, err => (err ? done(err) : loop(_id + 1)));
115+
return this.db.command({ [LEGACY_HELLO_COMMAND]: true }, err =>
116+
err ? done(err) : loop(_id + 1)
117+
);
114118
};
115119

116120
return loop(1);

test/functional/causal_consistency.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
'use strict';
2+
3+
const { LEGACY_HELLO_COMMAND } = require('../../src/constants');
4+
25
const setupDatabase = require('./shared').setupDatabase,
36
expect = require('chai').expect;
47

5-
const ignoredCommands = ['ismaster', 'endSessions'];
8+
const ignoredCommands = [LEGACY_HELLO_COMMAND, 'endSessions'];
69
const test = { commands: { started: [], succeeded: [] } };
710
describe('Causal Consistency', function () {
811
before(function () {

test/functional/change_stream.test.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ const fs = require('fs');
1414
const os = require('os');
1515
const path = require('path');
1616
const crypto = require('crypto');
17-
17+
const { LEGACY_HELLO_COMMAND } = require('../../src/constants');
1818
chai.use(require('chai-subset'));
19+
const { isHello } = require('../../src/utils');
1920

2021
function withChangeStream(dbName, collectionName, callback) {
2122
if (arguments.length === 1) {
@@ -1115,11 +1116,11 @@ describe('Change Streams', function () {
11151116
const doc = request.document;
11161117

11171118
// Create a server that responds to the initial aggregation to connect to the server, but not to subsequent getMore requests
1118-
if (doc.ismaster || doc.hello) {
1119+
if (isHello(doc)) {
11191120
request.reply(
11201121
Object.assign(
11211122
{
1122-
ismaster: true,
1123+
[LEGACY_HELLO_COMMAND]: true,
11231124
secondary: false,
11241125
me: primaryServer.uri(),
11251126
primary: primaryServer.uri(),
@@ -1314,9 +1315,9 @@ describe('Change Streams', function () {
13141315

13151316
const OPERATION_TIME = new Timestamp(4, 1501511802);
13161317

1317-
const makeIsMaster = server => ({
1318+
const makeHello = server => ({
13181319
__nodejs_mock_server__: true,
1319-
ismaster: true,
1320+
[LEGACY_HELLO_COMMAND]: true,
13201321
secondary: false,
13211322
me: server.uri(),
13221323
primary: server.uri(),
@@ -1399,8 +1400,8 @@ describe('Change Streams', function () {
13991400
function primaryServerHandler(request) {
14001401
try {
14011402
const doc = request.document;
1402-
if (doc.ismaster || doc.hello) {
1403-
return request.reply(makeIsMaster(server));
1403+
if (isHello(doc)) {
1404+
return request.reply(makeHello(server));
14041405
} else if (doc.aggregate) {
14051406
return request.reply(AGGREGATE_RESPONSE);
14061407
} else if (doc.getMore) {
@@ -1671,14 +1672,25 @@ describe('Change Streams', function () {
16711672
class MockServerManager {
16721673
constructor(config, commandIterators) {
16731674
this.config = config;
1674-
this.cmdList = new Set(['ismaster', 'hello', 'endSessions', 'aggregate', 'getMore']);
1675+
this.cmdList = new Set([
1676+
LEGACY_HELLO_COMMAND,
1677+
'hello',
1678+
'endSessions',
1679+
'aggregate',
1680+
'getMore'
1681+
]);
16751682
this.database = 'test_db';
16761683
this.collection = 'test_coll';
16771684
this.ns = `${this.database}.${this.collection}`;
16781685
this._timestampCounter = 0;
16791686
this.cursorId = new Long('9064341847921713401');
16801687
this.commandIterators = commandIterators;
16811688
this.promise = this.init();
1689+
1690+
// Handler for the legacy hello command
1691+
this[LEGACY_HELLO_COMMAND] = function () {
1692+
return this.hello();
1693+
};
16821694
}
16831695

16841696
init() {
@@ -1755,10 +1767,10 @@ describe('Change Streams', function () {
17551767

17561768
// Handlers for specific commands
17571769

1758-
ismaster() {
1770+
hello() {
17591771
const uri = this.server.uri();
17601772
return Object.assign({}, mock.HELLO, {
1761-
ismaster: true,
1773+
[LEGACY_HELLO_COMMAND]: true,
17621774
secondary: false,
17631775
me: uri,
17641776
primary: uri,
@@ -1769,10 +1781,6 @@ describe('Change Streams', function () {
17691781
});
17701782
}
17711783

1772-
hello() {
1773-
return this.ismaster();
1774-
}
1775-
17761784
endSessions() {
17771785
return { ok: 1 };
17781786
}
@@ -2502,7 +2510,7 @@ context('NODE-2626 - handle null changes without error', function () {
25022510
it('changeStream should close if cursor id for initial aggregate is Long.ZERO', function (done) {
25032511
mockServer.setMessageHandler(req => {
25042512
const doc = req.document;
2505-
if (doc.ismaster || doc.hello) {
2513+
if (isHello(doc)) {
25062514
return req.reply(mock.HELLO);
25072515
}
25082516
if (doc.aggregate) {

test/functional/change_stream_spec.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { setupDatabase } = require('./shared');
99
const { delay } = require('./shared');
1010

1111
const expect = chai.expect;
12+
const { LEGACY_HELLO_COMMAND } = require('../../src/constants');
1213

1314
describe('Change Streams Spec - Unified', function () {
1415
runUnifiedSuite(loadSpecTests(path.join('change-streams', 'unified')));
@@ -66,7 +67,7 @@ describe('Change Stream Spec - v1', function () {
6667
ctx.database = ctx.client.db(sDB);
6768
ctx.collection = ctx.database.collection(sColl);
6869
ctx.client.on('commandStarted', e => {
69-
if (e.commandName !== 'ismaster') _events.push(e);
70+
if (e.commandName !== LEGACY_HELLO_COMMAND) _events.push(e);
7071
});
7172
});
7273
});

test/functional/cmap/connection.test.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { connect } = require('../../../src/cmap/connect');
55
const { expect } = require('chai');
66
const { setupDatabase } = require('../../functional/shared');
77
const { ns, HostAddress } = require('../../../src/utils');
8+
const { LEGACY_HELLO_COMMAND } = require('../../../src/constants');
89

910
describe('Connection - functional/cmap', function () {
1011
before(function () {
@@ -23,10 +24,10 @@ describe('Connection - functional/cmap', function () {
2324
expect(err).to.not.exist;
2425
this.defer(_done => conn.destroy(_done));
2526

26-
conn.command(ns('admin.$cmd'), { ismaster: 1 }, undefined, (err, ismaster) => {
27+
conn.command(ns('admin.$cmd'), { [LEGACY_HELLO_COMMAND]: 1 }, undefined, (err, hello) => {
2728
expect(err).to.not.exist;
28-
expect(ismaster).to.exist;
29-
expect(ismaster.ok).to.equal(1);
29+
expect(hello).to.exist;
30+
expect(hello.ok).to.equal(1);
3031
done();
3132
});
3233
});
@@ -50,10 +51,10 @@ describe('Connection - functional/cmap', function () {
5051
conn.on('commandSucceeded', event => events.push(event));
5152
conn.on('commandFailed', event => events.push(event));
5253

53-
conn.command(ns('admin.$cmd'), { ismaster: 1 }, undefined, (err, ismaster) => {
54+
conn.command(ns('admin.$cmd'), { [LEGACY_HELLO_COMMAND]: 1 }, undefined, (err, hello) => {
5455
expect(err).to.not.exist;
55-
expect(ismaster).to.exist;
56-
expect(ismaster.ok).to.equal(1);
56+
expect(hello).to.exist;
57+
expect(hello.ok).to.equal(1);
5758
expect(events).to.have.length(2);
5859
done();
5960
});

test/functional/collations.test.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const setupDatabase = require('./shared').setupDatabase;
33
const mock = require('../tools/mongodb-mock/index');
44
const expect = require('chai').expect;
55
const { Long, Code } = require('../../src');
6+
const { isHello } = require('../../src/utils');
67

78
const testContext = {};
89
describe('Collation', function () {
@@ -26,7 +27,7 @@ describe('Collation', function () {
2627
let commandResult;
2728
testContext.server.setMessageHandler(request => {
2829
const doc = request.document;
29-
if (doc.ismaster || doc.hello) {
30+
if (isHello(doc)) {
3031
request.reply(primary[0]);
3132
} else if (doc.count) {
3233
commandResult = doc;
@@ -62,7 +63,7 @@ describe('Collation', function () {
6263
let commandResult;
6364
testContext.server.setMessageHandler(request => {
6465
const doc = request.document;
65-
if (doc.ismaster || doc.hello) {
66+
if (isHello(doc)) {
6667
request.reply(primary[0]);
6768
} else if (doc.aggregate) {
6869
commandResult = doc;
@@ -100,7 +101,7 @@ describe('Collation', function () {
100101
let commandResult;
101102
testContext.server.setMessageHandler(request => {
102103
var doc = request.document;
103-
if (doc.ismaster || doc.hello) {
104+
if (isHello(doc)) {
104105
request.reply(primary[0]);
105106
} else if (doc.distinct) {
106107
commandResult = doc;
@@ -136,7 +137,7 @@ describe('Collation', function () {
136137
let commandResult;
137138
testContext.server.setMessageHandler(request => {
138139
var doc = request.document;
139-
if (doc.ismaster || doc.hello) {
140+
if (isHello(doc)) {
140141
request.reply(primary[0]);
141142
} else if (doc.mapReduce) {
142143
commandResult = doc;
@@ -177,7 +178,7 @@ describe('Collation', function () {
177178
let commandResult;
178179
testContext.server.setMessageHandler(request => {
179180
var doc = request.document;
180-
if (doc.ismaster || doc.hello) {
181+
if (isHello(doc)) {
181182
request.reply(primary[0]);
182183
} else if (doc.delete) {
183184
commandResult = doc;
@@ -213,7 +214,7 @@ describe('Collation', function () {
213214
let commandResult;
214215
testContext.server.setMessageHandler(request => {
215216
const doc = request.document;
216-
if (doc.ismaster || doc.hello) {
217+
if (isHello(doc)) {
217218
request.reply(primary[0]);
218219
} else if (doc.update) {
219220
commandResult = doc;
@@ -251,7 +252,7 @@ describe('Collation', function () {
251252
let commandResult;
252253
testContext.server.setMessageHandler(request => {
253254
const doc = request.document;
254-
if (doc.ismaster || doc.hello) {
255+
if (isHello(doc)) {
255256
request.reply(primary[0]);
256257
} else if (doc.find) {
257258
commandResult = doc;
@@ -287,7 +288,7 @@ describe('Collation', function () {
287288
let commandResult;
288289
testContext.server.setMessageHandler(request => {
289290
const doc = request.document;
290-
if (doc.ismaster || doc.hello) {
291+
if (isHello(doc)) {
291292
request.reply(primary[0]);
292293
} else if (doc.find) {
293294
commandResult = doc;
@@ -325,7 +326,7 @@ describe('Collation', function () {
325326
let commandResult;
326327
testContext.server.setMessageHandler(request => {
327328
const doc = request.document;
328-
if (doc.ismaster || doc.hello) {
329+
if (isHello(doc)) {
329330
request.reply(primary[0]);
330331
} else if (doc.find) {
331332
commandResult = doc;
@@ -361,7 +362,7 @@ describe('Collation', function () {
361362
let commandResult;
362363
testContext.server.setMessageHandler(request => {
363364
const doc = request.document;
364-
if (doc.ismaster || doc.hello) {
365+
if (isHello(doc)) {
365366
request.reply(primary[0]);
366367
} else if (doc.listCollections) {
367368
request.reply({
@@ -403,7 +404,7 @@ describe('Collation', function () {
403404
let commandResult;
404405
testContext.server.setMessageHandler(request => {
405406
const doc = request.document;
406-
if (doc.ismaster || doc.hello) {
407+
if (isHello(doc)) {
407408
request.reply(primary[0]);
408409
} else if (doc.update) {
409410
commandResult = doc;
@@ -457,7 +458,7 @@ describe('Collation', function () {
457458
let commandResult;
458459
testContext.server.setMessageHandler(request => {
459460
const doc = request.document;
460-
if (doc.ismaster || doc.hello) {
461+
if (isHello(doc)) {
461462
request.reply(primary[0]);
462463
} else if (doc.createIndexes) {
463464
commandResult = doc;

test/functional/collection.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const sinonChai = require('sinon-chai');
77
const mock = require('../tools/mongodb-mock/index');
88

99
chai.use(sinonChai);
10+
const { isHello } = require('../../src/utils');
1011

1112
describe('Collection', function () {
1213
let configuration;
@@ -638,7 +639,7 @@ describe('Collection', function () {
638639
}
639640
}
640641

641-
if (doc.ismaster || doc.hello) {
642+
if (isHello(doc)) {
642643
request.reply(Object.assign({}, mock.HELLO));
643644
} else if (doc.endSessions) {
644645
request.reply({ ok: 1 });

test/functional/command_monitoring.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { loadSpecTests } = require('../spec');
1010
const { expect } = require('chai');
1111
const { ReadPreference } = require('../../src/read_preference');
1212
const { runUnifiedTest } = require('../tools/unified-spec-runner/runner');
13+
const { LEGACY_HELLO_COMMAND } = require('../../src/constants');
1314

1415
describe('APM', function () {
1516
before(function () {
@@ -838,15 +839,15 @@ describe('APM', function () {
838839
// Set up the listeners
839840
client.on(
840841
'commandStarted',
841-
filterOutCommands(['ismaster', 'endSessions'], monitoringResults.starts)
842+
filterOutCommands([LEGACY_HELLO_COMMAND, 'endSessions'], monitoringResults.starts)
842843
);
843844
client.on(
844845
'commandFailed',
845-
filterOutCommands(['ismaster', 'endSessions'], monitoringResults.failures)
846+
filterOutCommands([LEGACY_HELLO_COMMAND, 'endSessions'], monitoringResults.failures)
846847
);
847848
client.on(
848849
'commandSucceeded',
849-
filterOutCommands(['ismaster', 'endSessions'], monitoringResults.successes)
850+
filterOutCommands([LEGACY_HELLO_COMMAND, 'endSessions'], monitoringResults.successes)
850851
);
851852

852853
// Unpack the operation

0 commit comments

Comments
 (0)