Skip to content

test(crud): resync crud tests and update test runner #2005

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 2 commits into from
May 29, 2019
Merged

Conversation

daprahamian
Copy link
Contributor

Files to look at:

  • lib/bulk/common.js: minor change to expose BulkWriteError for an instanceof check in test/functional/crud_spec_tests.js
  • test/functional/crud_spec_tests.js: Updated it to run with some of the new features that were added into v1 before v2 was created. Specifically:
    • scenario.data can be an empty array, which will result in an empty insert attempt / error
    • testing the final state uses outcome.collection.data instead of outcome.results
    • Write commands can be expected to error, and can contain an assertion on the content of the error. Added support for that to the few tests that actually error (bulkWrite and insertMany), and added a transform function to massage our BulkWriteError into the shape it should be.
      Files to ignore: Any yml/json/rst files

@daprahamian daprahamian requested review from mbroadst and kvwalker May 28, 2019 20:13
Copy link
Contributor

@kvwalker kvwalker left a comment

Choose a reason for hiding this comment

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

looks good to me! the description was very helpful :)

just 1 question about a ticket

expect(result).to.not.be.an('error');
}

// TODO: when we fix our bulk write errors, get rid of this
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a ticket for this?

Copy link
Member

Choose a reason for hiding this comment

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

I just made the same comment above at the point of function definition 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought there was, b/c it's been a known issue for a while, but I can't seem to find one, so I made https://jira.mongodb.org/browse/NODE-1989

expect(result).to.not.be.an('error');
}

// TODO: when we fix our bulk write errors, get rid of this
Copy link
Member

Choose a reason for hiding this comment

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

I just made the same comment above at the point of function definition 😄

@@ -162,7 +206,7 @@ describe('CRUD spec', function() {
.find({})
.toArray()
.then(collectionResults => {
expect(collectionResults).to.containSubset(outcome.result);
expect(collectionResults).to.containSubset(outcome.collection.data);
Copy link
Member

Choose a reason for hiding this comment

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

I think we still need to check this in v1, see this for example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are already asserting outcome.results here. This line is not asserting the result of the function call, but rather the state of the collection after the operation has been performed. If we were to use the example you provided above, we would be asserting that the entire collection would equal 3.

Copy link
Member

Choose a reason for hiding this comment

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

oh wow, yeah that's a bug. Do we need a more rigorous validator than containsSubset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

containsSubset seems to default to equals for non-objects, so I think we're fine.

);
const asserter = assertWriteExpectations(collection, scenarioTest.outcome);

return collection[scenarioTest.operation.name](documents, options).then(asserter, asserter);
Copy link
Member

Choose a reason for hiding this comment

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

This used to return a Promise with only a then attached to it, allowing errors to propagate back up if something went wrong before the expectations were checked. Now you pass in the "asserter" to both resolve and reject, but don't pass in a method that checks for an error.

To me it seems like it would be easier to read this flow if we did something more like:

const promise = collection[scenarioTest.operation.name](documents, options);
if (scenario.hasError) {
  promise.catch(doErrorChecks);
}

return promise.then(asserter);

@daprahamian daprahamian merged commit 53055f4 into next May 29, 2019
@daprahamian daprahamian deleted the sync-crud branch May 29, 2019 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants