Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-4188): default localThresholdMS to 15ms #3207

Merged
merged 5 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sdam/topology_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class TopologyDescription {
this.stale = false;
this.compatible = true;
this.heartbeatFrequencyMS = options.heartbeatFrequencyMS ?? 0;
this.localThresholdMS = options.localThresholdMS ?? 0;
this.localThresholdMS = options.localThresholdMS ?? 15;

if (setName) {
this.setName = setName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect } from 'chai';

import { MongoClient, MongoClientOptions } from '../../../src/mongo_client';
import { getTopology } from '../../../src/utils';

describe('TopologyDescription (integration tests)', function () {
let client: MongoClient;

afterEach(async function () {
await client.close();
});

context('options', function () {
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);
});
});
});
});
5 changes: 0 additions & 5 deletions test/unit/assorted/server_selection.spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ describe('Server Selection Logic (spec)', function () {
this.currentTest.skipReason = 'Nodejs driver does not support PossiblePrimary';
this.skip();
}

if (this.currentTest.title.match(/nearest_multiple/i)) {
this.currentTest.skipReason = 'TODO(NODE-4188): localThresholdMS should default to 15ms';
this.skip();
}
});

const selectionSpecDir = join(__dirname, '../../spec/server-selection/server_selection');
Expand Down
73 changes: 73 additions & 0 deletions test/unit/sdam/server_selection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,5 +435,78 @@ describe('server selection', function () {
});
});
});

context('localThresholdMS is respected as an option', function () {
let serverDescription1, serverDescription2, serverDescription3, serverDescriptions;
beforeEach(() => {
serverDescription1 = new ServerDescription(
'127.0.0.1:27017',
{
setName: 'test',
isWritablePrimary: true,
ok: 1
},
{ roundTripTime: 15 }
);
serverDescription2 = new ServerDescription(
'127.0.0.1:27018',
{
setName: 'test',
secondary: true,
ok: 1
},
{ roundTripTime: 25 }
);
serverDescription3 = new ServerDescription(
'127.0.0.1:27019',
{
setName: 'test',
secondary: true,
ok: 1
},
{ roundTripTime: 35 }
);
serverDescriptions = new Map();
serverDescriptions.set(serverDescription1.address, serverDescription1);
serverDescriptions.set(serverDescription2.address, serverDescription2);
serverDescriptions.set(serverDescription3.address, serverDescription3);
});
it('includes servers inside the latency window with default localThresholdMS', function () {
const topologyDescription = new TopologyDescription(
TopologyType.Single,
serverDescriptions,
'test',
MIN_SECONDARY_WRITE_WIRE_VERSION,
new ObjectId(),
MIN_SECONDARY_WRITE_WIRE_VERSION
);
const selector = secondaryWritableServerSelector();
const servers = selector(topologyDescription, Array.from(serverDescriptions.values()));
expect(servers).to.have.lengthOf(2);
const selectedAddresses = new Set(servers.map(({ address }) => address));
expect(selectedAddresses.has(serverDescription1.address)).to.be.true;
expect(selectedAddresses.has(serverDescription2.address)).to.be.true;
expect(selectedAddresses.has(serverDescription3.address)).to.be.false;
});

it('includes servers inside the latency window with custom localThresholdMS', function () {
const topologyDescription = new TopologyDescription(
TopologyType.Single,
serverDescriptions,
'test',
MIN_SECONDARY_WRITE_WIRE_VERSION,
new ObjectId(),
MIN_SECONDARY_WRITE_WIRE_VERSION,
{ localThresholdMS: 5 }
);
const selector = secondaryWritableServerSelector();
const servers = selector(topologyDescription, Array.from(serverDescriptions.values()));
expect(servers).to.have.lengthOf(1);
const selectedAddresses = new Set(servers.map(({ address }) => address));
expect(selectedAddresses.has(serverDescription1.address)).to.be.true;
expect(selectedAddresses.has(serverDescription2.address)).to.be.false;
expect(selectedAddresses.has(serverDescription3.address)).to.be.false;
});
});
});
});