-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(NODE-5749): RTTPinger always sends legacy hello #3921
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0a74415
fix(NODE-5749): RTTPinger always sends legacy hello
nbbeeken 54c8af6
test: fix assertion for standalone
nbbeeken ef86f7b
test: above 4.4
nbbeeken efed7eb
test: skip LB mode
nbbeeken 3cf3ed2
test: address flakiness by waiting for necessary condition
nbbeeken 937ea95
test: cleanup rtt finder and beforeEach
nbbeeken 698ad1c
test: add serverApi disabled test
nbbeeken 2f540f1
test: update naming for error case
nbbeeken 0e810ec
test: skip when serverApi is enabled
nbbeeken d91df42
test: add api disable and helloOk test, fix err msg
nbbeeken afc5157
Merge branch 'main' into NODE-5749-rtt-serverApi
nbbeeken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
test/integration/connection-monitoring-and-pooling/rtt_pinger.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { expect } from 'chai'; | ||
import * as semver from 'semver'; | ||
import * as sinon from 'sinon'; | ||
|
||
import { type Connection, type MongoClient, type RTTPinger } from '../../mongodb'; | ||
import { sleep } from '../../tools/utils'; | ||
|
||
/** | ||
* RTTPinger creation depends on getting a response to the monitor's initial hello | ||
* and that hello containing a topologyVersion. | ||
* Subsequently the rttPinger creates its connection asynchronously | ||
* | ||
* I just went with a sleepy loop, until we have what we need, One could also use SDAM events in a clever way perhaps? | ||
*/ | ||
async function getRTTPingers(client: MongoClient) { | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const rttPingers = Array.from(client.topology?.s.servers.values() ?? [], s => { | ||
if (s.monitor?.rttPinger?.connection != null) return s.monitor?.rttPinger; | ||
dariakp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else null; | ||
}).filter(rtt => rtt != null); | ||
|
||
if (rttPingers.length !== 0) { | ||
return rttPingers as (Omit<RTTPinger, 'connection'> & { connection: Connection })[]; | ||
} | ||
|
||
await sleep(5); | ||
} | ||
} | ||
|
||
describe('class RTTPinger', () => { | ||
afterEach(() => sinon.restore()); | ||
|
||
beforeEach(async function () { | ||
if (this.configuration.isLoadBalanced) { | ||
if (this.currentTest) | ||
dariakp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.currentTest.skipReason = 'No monitoring in LB mode, test not relevant'; | ||
return this.skip(); | ||
} | ||
if (semver.gte('4.4.0', this.configuration.version)) { | ||
if (this.currentTest) | ||
this.currentTest.skipReason = | ||
'Test requires streaming monitoring, needs to be on MongoDB 4.4+'; | ||
return this.skip(); | ||
} | ||
}); | ||
|
||
context('when serverApi is enabled', () => { | ||
dariakp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let serverApiClient: MongoClient; | ||
beforeEach(async function () { | ||
if (semver.gte('5.0.0', this.configuration.version)) { | ||
if (this.currentTest) | ||
this.currentTest.skipReason = 'Test requires serverApi, needs to be on MongoDB 5.0+'; | ||
return this.skip(); | ||
} | ||
|
||
serverApiClient = this.configuration.newClient( | ||
{}, | ||
{ serverApi: { version: '1', strict: true }, heartbeatFrequencyMS: 10 } | ||
); | ||
}); | ||
|
||
afterEach(async () => { | ||
await serverApiClient?.close(); | ||
}); | ||
|
||
it('measures rtt with a hello command', async function () { | ||
await serverApiClient.connect(); | ||
const rttPingers = await getRTTPingers(serverApiClient); | ||
|
||
const spies = rttPingers.map(rtt => sinon.spy(rtt.connection, 'command')); | ||
|
||
await sleep(11); // allow for another ping after spies have been made | ||
|
||
expect(spies).to.have.lengthOf.at.least(1); | ||
for (const spy of spies) { | ||
expect(spy).to.have.been.calledWith(sinon.match.any, { hello: 1 }, sinon.match.any); | ||
} | ||
}); | ||
}); | ||
|
||
context('when rtt hello receives an error', () => { | ||
dariakp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let client: MongoClient; | ||
beforeEach(async function () { | ||
client = this.configuration.newClient({}, { heartbeatFrequencyMS: 10 }); | ||
}); | ||
|
||
afterEach(async () => { | ||
await client?.close(); | ||
}); | ||
|
||
it('destroys the connection', async function () { | ||
await client.connect(); | ||
const rttPingers = await getRTTPingers(client); | ||
|
||
for (const rtt of rttPingers) { | ||
sinon.stub(rtt.connection, 'command').yieldsRight(new Error('any')); | ||
} | ||
const spies = rttPingers.map(rtt => sinon.spy(rtt.connection, 'destroy')); | ||
|
||
await sleep(11); // allow for another ping after spies have been made | ||
|
||
expect(spies).to.have.lengthOf.at.least(1); | ||
for (const spy of spies) { | ||
expect(spy).to.have.been.called; | ||
} | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.