-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(NODE-7223): run checkout on connect regardless of credentials #4715
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
94a37d0
92c379a
e38d620
1c70d3a
ede31fd
011ecce
67e8b57
56c77a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import { | |
Db, | ||
getTopology, | ||
MongoClient, | ||
MongoNetworkError, | ||
MongoNotConnectedError, | ||
MongoServerSelectionError, | ||
ReadPreference, | ||
|
@@ -333,6 +334,28 @@ describe('class MongoClient', function () { | |
} | ||
}); | ||
}); | ||
|
||
it('throws ENOTFOUND error when connecting to non-existent host with no auth and loadBalanced=true', async function () { | ||
const configuration = this.configuration; | ||
const client = configuration.newClient( | ||
'mongodb://iLoveJavaScript:27017/test?loadBalanced=true', | ||
{ serverSelectionTimeoutMS: 100 } | ||
); | ||
|
||
const error = await client.connect().catch(error => error); | ||
expect(error).to.be.instanceOf(MongoNetworkError); // not server selection like other topologies | ||
expect(error.message).to.match(/ENOTFOUND/); | ||
}); | ||
|
||
it('throws an error when srv is not a real record', async function () { | ||
const client = this.configuration.newClient('mongodb+srv://iLoveJavaScript/test', { | ||
serverSelectionTimeoutMS: 100 | ||
}); | ||
|
||
const error = await client.connect().catch(error => error); | ||
expect(error).to.be.instanceOf(Error); | ||
expect(error.message).to.match(/ENOTFOUND/); | ||
}); | ||
}); | ||
|
||
it('Should correctly pass through appname', { | ||
|
@@ -600,15 +623,17 @@ describe('class MongoClient', function () { | |
); | ||
|
||
it( | ||
'does not checkout connection when authentication is disabled', | ||
'checks out connection to confirm connectivity even when authentication is disabled', | ||
|
||
{ requires: { auth: 'disabled' } }, | ||
async function () { | ||
const checkoutStartedEvents = []; | ||
client.on('connectionCheckOutStarted', event => { | ||
checkoutStartedEvents.push(event); | ||
}); | ||
const checkoutStarted = once(client, 'connectionCheckOutStarted'); | ||
await client.connect(); | ||
expect(checkoutStartedEvents).to.be.empty; | ||
const checkout = await checkoutStarted; | ||
expect(checkout).to.exist; | ||
expect(client).to.have.property('topology').that.is.instanceOf(Topology); | ||
} | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest just copying the doc comment from MongoClient.connect(). Or reworking this a bit.
But the phrasing "to verify a typical set of preconditions" feels odd (and also - typical set of preconditions for who and what, exactly?).
Alternatively, since I expect users primarily use the instance connect and not the static connect, we could just move the docs from the static method here and just link the static method's documentation to this.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did try to link and api-extractor throws because the syntax is abiguous, you have to use tsdoc syntax which means you need to add a new flag to typedoc to get it to link properly. Probably something worth looking into adding if linking around to other docs would be valuable.
I can move the docs to the instance or the static or copy them on to both?
updated the preconditions bit