-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(repository-tests): run repository-tests on cloudant #3968
Conversation
12502eb
to
28a847e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice start!
acceptance/repository-cloudant/src/__tests__/cloudant-default-repository.acceptance.ts
Outdated
Show resolved
Hide resolved
0b7f930
to
04b9553
Compare
a113c72
to
7f9e923
Compare
@@ -34,6 +34,11 @@ export function createSuiteForReplaceById( | |||
}) | |||
id: MixedIdType; | |||
|
|||
// cloudant needs this property to do replacement method | |||
// see cloundant README file for more details |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it suboptimal to force all connector tests (SQL, MongoDB, etc.) to use _rev
property. Let's find a way how to allow individual connectors to provide any extra properties via CrudFeatures
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that you added revisionTokenRequired
flag to fix test failures.
Personally, I'd prefer to find a way how to define _rev
property only when running on Cloudant, so that we are not using _rev
property when testing e.g. MongoDB.
Having said that, I don't have any solution I could offer from the top of my head, so it's probably better to accept the current proposal for now and get this pull request landed sooner rather than later 👍
aec5e27
to
037dce5
Compare
821b0b3
to
3689039
Compare
636b9ae
to
850873a
Compare
20e2a51
to
110e32a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, @agnes512 👏 I am happy to see that you managed to find a working solution for running our tests against Cloudant 👍
Let's discuss & improve the implementation details now.
docker.setup.js
Outdated
// // we don't pass any node flags, so we can call _mocha instead the wrapper | ||
// const mochaBin = require.resolve('mocha/bin/_mocha'); | ||
|
||
process.env.CLOUDANT_DATABASE = 'testdb'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this docker setup is specific to Cloudant, can you please move the setup script to acceptance/repository-cloudant
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file will be removed once the release is done. The script is from #3968. I use it here to check if it sets up travis correctly and takes reasonable time to finish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bajtos Thank you for the technical feedback of the setup script, it's actually added in https://github.com/strongloop/loopback-connector-cloudant/blob/master/docker.setup.js, @agnes512 put it in her PR before that script merged into the master.
To be honest, to save the time, the code in that script is mostly copied from an existing script that has been running for test from 2 years ago 🙈 , so for some of your questions I don't quite know the answer, but I'll try :p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the technical feedback of the setup script, it's actually added in https://github.com/strongloop/loopback-connector-cloudant/blob/master/docker.setup.js, @agnes512 put it in her PR before that script merged into the master.
I see, makes sense.
To be honest, to save the time, the code in that script is mostly copied from an existing script that has been running for test from 2 years ago
Sure, no need to refactor the script if it's working well as it is now. I am going to mark all my comments for docker.setup.js
as resolved then.
docker.setup.js
Outdated
async.waterfall( | ||
[ | ||
dockerStart('ibmcom/couchdb3:latest'), | ||
sleep(ms('2s')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am little bit concerned about the hard-coded delay. In many cases, the docker will start faster and we wait unnecessarily long. In some edge cases, the docker may not start fast enough, in which case the subsequent steps will fail (assuming they detect & handle this error correctly).
Is there any reasonable easy way how to replace this sleep with poll-based approach? E.g. every 100ms check if the docker container has started. If yes then the wait is over, if not then sleep 100ms and try again.
Feel free to leave this out of this pull request though.
package.json
Outdated
@@ -62,7 +66,8 @@ | |||
"docs:prepare": "./docs/bin/build-preview-site.sh", | |||
"docs:start": "cd docs/_preview && bundle exec jekyll serve --no-w --i", | |||
"mocha": "node packages/build/bin/run-mocha \"packages/*/dist/__tests__/**/*.js\" \"extensions/*/dist/__tests__/**/*.js\" \"examples/*/dist/__tests__/**/*.js\" \"packages/cli/test/**/*.js\" \"packages/build/test/*/*.js\"", | |||
"posttest": "npm run lint" | |||
"posttest": "npm run lint", | |||
"docker:setup": "node ./docker.setup.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the Docker setup is specific to Cloudant, can we move this npm script to acceptance/repository-cloudant/package.json
please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will be loaded from dependency loopback-connector-cloudant
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jannyHou I moved the whole script to the acceptance/repo-cloudant. But I am okay with either way~
@@ -34,6 +34,11 @@ export function createSuiteForReplaceById( | |||
}) | |||
id: MixedIdType; | |||
|
|||
// cloudant needs this property to do replacement method | |||
// see cloundant README file for more details |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it suboptimal to force all connector tests (SQL, MongoDB, etc.) to use _rev
property. Let's find a way how to allow individual connectors to provide any extra properties via CrudFeatures
.
expect(toJSON(found)).to.deepEqual( | ||
// use containDeep instead of deepEqual because cloudant changes _rev value after | ||
// replacement | ||
expect(toJSON(found)).to.containDeep( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am concerned that by changing from deepEqual
to containDeep
we are allowing many more changes than just a different _rev
value. For example, if the connector and/or the database adds new properties, this assertion will happily accept that, even though such behavior is most likely not wanted.
Let's find a way how to deal with _rev
changes via a new CrudFeatures
flag in such way that only changes in the _rev
property is allowed and only when testing against Cloudant/CouchDB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in the fifth commit.
expect(toJSON(found)).to.deepEqual( | ||
// use containDeep instead of deepEqual because cloudant changes _rev value after | ||
// replacement | ||
expect(toJSON(found)).to.containDeep( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
- Use the `couchDB3:latest` image, and rename the container as | ||
`cloudant-testdb`. | ||
|
||
- Start the container, and create an admin and password for this image at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we automate this and the previous step please? In other repository acceptance packages, the docker-based setup requires the developer to run a single script only. Can we perhaps tell people to use npm docker:setup
? (See also my other comments suggesting to move that script to this package.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, and README is updated. ( the script is run in this folder now)
ef41ae7
to
c2eb73c
Compare
const docker = new require('dockerode')(); | ||
const http = require('http'); | ||
const ms = require('ms'); | ||
const fs = require('fs-extra'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fs-extra
isn't listed in package.json
.. but it also doesn't appear to really be fully utilized here since the only method used is in fs
from core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true fs
is enough
82a5e08
to
2750e01
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
|
||
```bash | ||
source setup.sh <HOST> <PORT> <USER> <PASSWORD> <DATABASE> | ||
CLOUDANT_USER=<USER> CLOUDANT_PASSWORD=<PASSWORD> CLOUDANT_DATABASE=<DATABASE> node docker.setup.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node docker.setup.sh
looks suspicious - node typically expects .js
files, not .sh
. I think it's just a typo?
CLOUDANT_USER=<USER> CLOUDANT_PASSWORD=<PASSWORD> CLOUDANT_DATABASE=<DATABASE> node docker.setup.sh | |
CLOUDANT_USER=<USER> CLOUDANT_PASSWORD=<PASSWORD> CLOUDANT_DATABASE=<DATABASE> node docker.setup.js |
BTW why node docker.setup.js
and not npm run docker:setup
? Should we modify Travis CI config to call node docker.setup.js
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
And right, I think
CLOUDANT_USERNAME=<USER> CLOUDANT_PASSWORD=<PASSWORD> CLOUDANT_DATABASE=<DATABASE> npm run docker:setup
also allows users to have their own configurations 👍 changed.
@@ -34,6 +34,11 @@ export function createSuiteForReplaceById( | |||
}) | |||
id: MixedIdType; | |||
|
|||
// cloudant needs this property to do replacement method | |||
// see cloundant README file for more details |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that you added revisionTokenRequired
flag to fix test failures.
Personally, I'd prefer to find a way how to define _rev
property only when running on Cloudant, so that we are not using _rev
property when testing e.g. MongoDB.
Having said that, I don't have any solution I could offer from the top of my head, so it's probably better to accept the current proposal for now and get this pull request landed sooner rather than later 👍
* | ||
* Default: `false` | ||
*/ | ||
revisionTokenRequired: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick - feel free to ignore.
The _rev
value is not always required, is it? For example, when creating a new model instance, the _rev
must not be provided, at least AFAIK.
Maybe hasRevisionToken
would be a better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense
477e642
to
f55ef5b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
crudRepositoryTestSuite( | ||
CLOUDANT_CONFIG, | ||
// Workaround for https://github.com/microsoft/TypeScript/issues/31840 | ||
DefaultTransactionalRepository as CrudRepositoryCtor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it doesn't support transactions, I think you should change this to DefaultCrudRepository
like in the MongoDB one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Cloudant uses _rev
to handle the update conflict, it doesn't handle transaction like sql dbs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, I just copied it from MySQL :p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Almost there! LGTM after addressing comment from Nora and Ryan.
On a second thought I agree on keeping the setup script in this repository. Easy to maintain. the cloudant connector still uses the old script.
crudRepositoryTestSuite( | ||
CLOUDANT_CONFIG, | ||
// Workaround for https://github.com/microsoft/TypeScript/issues/31840 | ||
DefaultTransactionalRepository as CrudRepositoryCtor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Cloudant uses _rev
to handle the update conflict, it doesn't handle transaction like sql dbs.
7fabac1
to
ee20f11
Compare
ee20f11
to
9bf7a6b
Compare
closes #3437
Create
acceptance-repository-cloudant
folder.replace-by-id
need to be modified to run the replacement operation on Cloudant ( it needs an extra property_rev
to do so).docker.setup.js
) to set up the docker image.docker.setup.js
file is based on @jannyHou 's PR. I modified it a bit, now it can be used to set up the local test as well with customized names. ( see README).Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈