forked from mongodb/node-mongodb-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(NODE-5530): make topology descriptions JSON stringifiable (mongod…
…b#4070) Co-authored-by: Aditi Khare <106987683+aditi-khare-mongoDB@users.noreply.github.com>
- Loading branch information
1 parent
55c290a
commit acb2c67
Showing
3 changed files
with
91 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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,46 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { MongoClient, MongoServerSelectionError, ReadPreference } from '../../mongodb'; | ||
|
||
describe('Error (Integration)', function () { | ||
it('NODE-5296: handles aggregate errors from dns lookup', async function () { | ||
const error = await MongoClient.connect('mongodb://localhost:27222', { | ||
serverSelectionTimeoutMS: 1000 | ||
}).catch(e => e); | ||
expect(error).to.be.instanceOf(MongoServerSelectionError); | ||
expect(error.message).not.to.be.empty; | ||
}); | ||
|
||
context('when a server selection error is stringified', function () { | ||
it( | ||
'the error"s topology description correctly displays the `servers`', | ||
{ requires: { topology: 'replicaset' } }, | ||
async function () { | ||
const client: MongoClient = this.configuration.newClient({ | ||
serverSelectionTimeoutMS: 1000 | ||
}); | ||
try { | ||
await client.connect(); | ||
|
||
const error = await client | ||
.db('foo') | ||
.collection('bar') | ||
.find( | ||
{}, | ||
{ | ||
// Use meaningless read preference tags to ensure that the server selection fails | ||
readPreference: new ReadPreference('secondary', [{ ny: 'ny' }]) | ||
} | ||
) | ||
.toArray() | ||
.catch(e => JSON.parse(JSON.stringify(e))); | ||
|
||
const servers = error.reason.servers; | ||
expect(Object.keys(servers).length > 0).to.be.true; | ||
} finally { | ||
await client.close(); | ||
} | ||
} | ||
); | ||
}); | ||
}); |
This file contains 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