Skip to content

Conversation

tadjik1
Copy link
Contributor

@tadjik1 tadjik1 commented Oct 2, 2025

Description

Summary of Changes

This PR migrates the integration tests for crud/crud_api. The changes include:

  • Refactor callbacks to async/await
  • Direct import from the src folder
  • Removing old test requirements (for example, for mongodb >= 3, or topology "ssl")
  • Changing some independent tests within the single it into separate describe with multiple tests in it
Notes for Reviewers

The file is huge, and there are many changes in it, but I tried to keep the same structure, I hope it's still manageable to review it. Let me know if you want me to break down PR into pieces somehow.

What is the motivation for this change?

This work is part of a larger, ongoing initiative to convert all tests to use async/await, with the ultimate goal of removing the legacy driver wrapper.

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket


it('should correctly execute aggregation method using crud api', function (done) {
const db = client.db();
describe('should correctly execute aggregation method using crud api', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a difficult part to review, so I want to share the context and my reasoning behind converting one test in it into separate block describe:
in the previous version we were testing multiple independent cursor methods (forEach, next, etc.) within the same function, and use callbacks chain to run them in series. So the structure looked like:

it(..., (done) => {
  function test1() {
    testMethod1(() => {
      test2();
    });
  }

  function test2() {
    testMethod2(() => {
      done();
    });
  }

  test1();
});

I decided to split this into multiple independent tests (multiple it) within the same block (one describe). And also converted callbacks into async/await.
Let me know if it works.


it('should correctly execute insert methods using crud api', function (done) {
client.connect(function (err, client) {
describe('should correctly execute insert methods using crud api', function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comment from the above with the reasoning behind changing single it into describe.

// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
describe(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, please see my comment from the above with the reasoning behind changing single it into describe.

// Execute the command with all steps defined
// will fail
const err = await cursor.toArray().catch(err => err);
expect(err).to.be.instanceof(MongoServerError);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we now catch error with const e = await p.catch(e => e); we get e initialized in both cases (resolve and reject), so I changed this assertion to instanceof instead of previous (test.ok(err != null);) which worked well with callbacks.

.collection('t20_1')
.bulkWrite(ops, { ordered: true, writeConcern: { w: 1 } })
.catch(err => err);
expect(err).to.be.instanceOf(MongoBulkWriteError);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original assertion test.ok(err !== null); won't work well with promises, so I changed it to instanceof.

@tadjik1 tadjik1 marked this pull request as ready for review October 6, 2025 08:17
@tadjik1 tadjik1 requested a review from a team as a code owner October 6, 2025 08:17
@baileympearson baileympearson self-assigned this Oct 6, 2025
@baileympearson baileympearson added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Oct 6, 2025
Comment on lines +318 to +344
it('allMethods', async function () {
const cursor = db.collection('t1').aggregate([{ $match: {} }], {
allowDiskUse: true,
batchSize: 2,
maxTimeMS: 50
});

//
// Exercise each
// -------------------------------------------------
const testEach = function () {
let count = 0;
const cursor = db.collection('t1').aggregate();
cursor.match({ a: 1 });
cursor.forEach(
() => {
count = count + 1;
},
err => {
expect(err).to.not.exist;
test.equal(3, count);
testStream();
}
);
};
// Exercise all the options
cursor
.geoNear({ geo: 1 })
.group({ group: 1 })
.limit(10)
.match({ match: 1 })
.maxTimeMS(10)
.out('collection')
.project({ project: 1 })
.redact({ redact: 1 })
.skip(1)
.sort({ sort: 1 })
.batchSize(10)
.unwind('name');

//
// Exercise stream
// -------------------------------------------------
const testStream = function () {
const cursor = db.collection('t1').aggregate();
let count = 0;
cursor.match({ a: 1 });
const stream = cursor.stream();
stream.on('data', function () {
count = count + 1;
});
// Execute the command with all steps defined
// will fail
const err = await cursor.toArray().catch(err => err);
expect(err).to.be.instanceof(MongoServerError);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the value of this test? Maybe we can schedule it for removal.

requires: { topology: ['single', 'replicaset', 'sharded'] }
},
function () {
it('legacy update', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this test, there is no Collection.update method anymore.

Comment on lines +480 to 482
{
requires: { topology: ['single', 'replicaset', 'sharded'] }
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest removing these entirely; these general CRUD tests should pass on any configuration and topology.

Comment on lines 774 to 777
it('should correctly execute removeMany with no selector', {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
requires: { topology: ['single', 'replicaset', 'sharded'] }
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above about metadata

Comment on lines 787 to 789
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
requires: { topology: ['single', 'replicaset', 'sharded'] }
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above about metadata

Comment on lines 817 to 819
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
requires: { topology: ['single', 'replicaset', 'sharded'] }
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above about metadata

}
});

it('should correctly execute crud operations using w:0', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is already covered by should correctly execute crud operations with w:0, right? I think we can schedule this one for deletion.

});
});

it('should correctly throw error on illegal callback when ordered bulkWrite encounters error', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we take this opportunity to update the test title so it accurately reflects that the test is testing?

Comment on lines 876 to 878
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
requires: { topology: ['single', 'replicaset', 'sharded'] }
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment about metadata

Comment on lines 832 to 835
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
requires: { topology: ['single', 'replicaset', 'sharded'] }
},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment about metadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants