Skip to content

Commit

Permalink
test(NODE-3521): fix cursor server selection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Mar 2, 2022
1 parent dc62173 commit 5839dae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion test/unit/cursor/aggregation_cursor.test.js
Expand Up @@ -95,11 +95,16 @@ describe('Aggregation Cursor', function () {

context('when a data bearing server becomes available', function () {
beforeEach(function () {
// Set the count of times hello has been called.
let helloCalls = 0;
test.server.setMessageHandler(request => {
const doc = request.document;
if (isHello(doc)) {
request.reply(helloCalls > 0 ? { errmsg: 'network error' } : mock.HELLO);
// After the first hello call errors indicating no data bearing server is
// available, any subsequent hello call should succeed after server selection.
// This gives us a data bearing server available for the next call.
request.reply(helloCalls > 0 ? mock.HELLO : { errmsg: 'network error' });
helloCalls++;
} else if (doc.aggregate) {
request.reply({
cursor: {
Expand Down
7 changes: 6 additions & 1 deletion test/unit/cursor/find_cursor.test.js
Expand Up @@ -86,11 +86,16 @@ describe('Find Cursor', function () {

context('when a data bearing server becomes available', function () {
beforeEach(function () {
// Set the count of times hello has been called.
let helloCalls = 0;
test.server.setMessageHandler(request => {
const doc = request.document;
if (isHello(doc)) {
request.reply(helloCalls > 0 ? { errmsg: 'network error' } : mock.HELLO);
// After the first hello call errors indicating no data bearing server is
// available, any subsequent hello call should succeed after server selection.
// This gives us a data bearing server available for the next call.
request.reply(helloCalls > 0 ? mock.HELLO : { errmsg: 'network error' });
helloCalls++;
} else if (doc.find) {
request.reply({
cursor: {
Expand Down

0 comments on commit 5839dae

Please sign in to comment.