Skip to content
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

chore: add test for atomic upsertWithWhere (#1864) #1871

Merged
merged 1 commit into from Nov 24, 2020

Conversation

jannyHou
Copy link
Contributor

Introduce the new property atomicUpsertWithWhere for
connector that implement specific method.
See loopbackio/loopback-connector-mongodb#563
for mongodb implementation.

Backport #1864

Signed-off-by: Matteo Padovano mrbatista@users.noreply.github.com

Checklist

  • Sign off your commits with DCO (Developer Certificate of Origin)
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Commit messages are following our guidelines

id: '4', name: 'Brian',
}, function(err) {
err.message.should.equal('There are multiple instances found.' +
bdd.itIf(connectorCapabilities.atomicUpsertWithWhere !== true,
Copy link
Member

Choose a reason for hiding this comment

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

When adding a new connector capability flag, we should pick a reasonable default so that we don't have to update all connectors with the new flag. Considering that DAO does not require connectors to implement atomic upsertWithWhere and provides a non-atomic implementation in such case, I think we should assume connectors don't support atomic version by default.

We need to ensure one of the bdd.itIf cases is executed when connectorCapabilities.atomicUpsertWithWhere is not set to any value (it's undefined). I think it will be this particular case, right?

I think the condition here could be simplified as follows:

Suggested change
bdd.itIf(connectorCapabilities.atomicUpsertWithWhere !== true,
bdd.itIf(!connectorCapabilities.atomicUpsertWithWhere,

'upsertWithWhere update the first matching instance when multiple instances are ' +
'retrieved based on the filter criteria', async () => {
// The first matching instance is determinate from specific connector implementation
// For example for mongodb connector the sort parameter is used (default to _id asc)
Copy link
Member

Choose a reason for hiding this comment

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

I find it problematic that connectors implement different behavior than our default non-atomic implementation. Are we sure that SQL connectors like MySQL and PostgreSQL will update the first record only, the same way as MongoDB connector works? It would be great if we could align juggler-provided non-atomic version with the behavior of real connectors (both SQL and noSQL). If different connectors behave differently, then IMO we need to clearly document these differences and probably need to add a new connectorCapability flag to allow the test suite to execute the right set of expectations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we sure that SQL connectors like MySQL and PostgreSQL will update the first record only, the same way as MongoDB connector works?

@bajtos Currently only mongodb supports that, no other connectors have atomic implementation.

Hmm isn't atomicUpsertWithWhere already a connector flag? I will document the behaviour after PRs merge :)

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

Fair enough 👍

Introduce the new property atomicUpsertWithWhere for
connector that implement specific method.
See loopbackio/loopback-connector-mongodb#563
for mongodb implementation.

Signed-off-by: Matteo Padovano <mrbatista@users.noreply.github.com>
@jannyHou jannyHou merged commit 7058c52 into 3.x Nov 24, 2020
@delete-merged-branch delete-merged-branch bot deleted the backport-atomic-upsert branch November 24, 2020 14:53
jannyHou added a commit that referenced this pull request Nov 27, 2020
 * chore: add test for atomic upsertWithWhere (#1864) (#1871) (Janny)
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.

None yet

3 participants