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

test: fix unit tests #31

Merged
merged 6 commits into from Apr 11, 2021
Merged

test: fix unit tests #31

merged 6 commits into from Apr 11, 2021

Conversation

Zxilly
Copy link
Contributor

@Zxilly Zxilly commented Apr 8, 2021

Fix: #29

I need to explain what I do to solve this problem.

If you choose to use transaction with mongodb, even it have returned a success code, it still needs some time to setup the collections. If you operate it at this time, you will got something like

Unable to read from a snapshot due to pending collection catalog changes; please retry the operation. Snapshot timestamp is Timestamp(1584451745, 1). Collection minimum is Timestamp(1584451753, 1)

I didn't find some better way to solve this, and seems it only happens when you run unnittests. It's almost impossible to reproduce this in production environment. So I add

await new Promise(resolve => setTimeout(resolve, 1000));

ok, now it works fine.
If you confused about this meaningless code line. Plz read this.
Don't remove it.

test: fix order problem

test: try to fix transaction

test: try to fix ci

test: try to fix ci

test: try to fix ci

test: try to fix ci

test: try to fix ci
@hsluoyz
Copy link
Member

hsluoyz commented Apr 8, 2021

@ghaiklor @Sefriol @nodece

Copy link
Contributor

@Sefriol Sefriol 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 in general. Just wondering how the logistics like the docker container should be stored.

@@ -230,6 +230,7 @@ export class MongooseAdapter {
if (this.isSynced) {
const session = await this.getSession();
if (!session.inTransaction()) {
await CasbinRule.createCollection()
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. Is this really necessary? We use this library in production and also test environments where we rebuild database constantly and we have never seen this to be an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mongodb will automatic execute this, but I think explicitly defined is also ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. I would probably then move it to connect-function if adding it is necessary.

I have not seen this as common practice, so it would be good to add a comment to this as well on why createCollection is added. However, I might be wrong.

.github/mongo_setup.sh Outdated Show resolved Hide resolved
.github/mongo_setup.sh Outdated Show resolved Hide resolved
@Zxilly Zxilly requested a review from Sefriol April 9, 2021 08:21
@Zxilly
Copy link
Contributor Author

Zxilly commented Apr 9, 2021

Looks good in general. Just wondering how the logistics like the docker container should be stored.

Now it was built every time.

CONFIG="{ _id: '$REPLICA_SET_NAME', members: [{_id: 0, host: 'localhost:27001', priority: 2 }, { _id: 1, host: 'localhost:27002' }, { _id: 2, host: 'localhost:27003' } ]}"
mongo admin --port 27001 --eval "db.runCommand({ replSetInitiate: $CONFIG })"

waitForMongo 27002
Copy link
Contributor

Choose a reason for hiding this comment

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

While this might be sufficient I think it's operationally different. rs_status previously tried to verify that replicaset is valid.

The difference here might be that db-command could go through even when replicaset configuration is not yet done. (For example voting for primary / secondary / arbiter might not be done yet, but database accepts requests)

While waitForMongo can be sufficient to get the database responsive, I am not sure whether it means that the replicaset is fully operational.

This might be just splitting hairs , but I would try to avoid any unexpected errors.

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 think this won't be a problem. Since after this CI will execute yarn install then.
Mongo has enought time to finish its work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, you are probably right.

@hsluoyz hsluoyz merged commit 8e09611 into node-casbin:master Apr 11, 2021
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.

Fix CI error, add CI badge
3 participants