Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

fix(core): Support WiredTiger engine errmsg format in MongoDB 3.2 #1246

Merged
merged 1 commit into from
Mar 14, 2016

Conversation

QiyuLi
Copy link
Contributor

@QiyuLi QiyuLi commented Mar 3, 2016

The new WiredTiger engine is introduced in MongoDB 3.2.
It changes the output errmsg format for violation of unique index.
This commit adds support for the new format.

Fixes #1245

@lirantal lirantal added this to the 0.5.0 milestone Mar 3, 2016
@trendzetter
Copy link
Contributor

Seems a better solution than previously proposed hacks. Haven't tried it yet.

@trendzetter
Copy link
Contributor

Just tried it. No issues for me. I am running mongod 3.2.3 but the mongodb libraries that npm installs are 2.1.7 (I think that is strange but it works).

@QiyuLi
Copy link
Contributor Author

QiyuLi commented Mar 3, 2016

@trendzetter
Copy link
Contributor

Possibly my data is not in WiredTiger since I upgraded an existing database.

@QiyuLi
Copy link
Contributor Author

QiyuLi commented Mar 3, 2016

Yup, existing db file will cause mongodb to use old MMapV1 engine (default engine in mongodb 3.0).

// >= 3.2 11000 duplicate key error collection: mean-test.users index: username already exists
// < 3.2 Username already exists
userInfoRes.body.message.toLowerCase().should.containEql('username already exists');
userInfoRes.body.message.should.equal('Username already exists');
Copy link
Member

Choose a reason for hiding this comment

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

This change isn't needed. using toLowerCase() and containEql() is better here.

@mleanos
Copy link
Member

mleanos commented Mar 4, 2016

@QiyuLi This looks pretty good. I left a few comments.

Thanks for the fix :)

@QiyuLi
Copy link
Contributor Author

QiyuLi commented Mar 4, 2016

@mleanos
The reason why I'm changing it back to userInfoRes.body.message.should.equal('Email already exists'); is:

I will change it to !== -1

@mleanos
Copy link
Member

mleanos commented Mar 4, 2016

@QiyuLi I don't think we need the assertion there to be precise. Also, the assert should have zero impact on what is displayed to the user. IMO, it's just an unnecessary change.

With that said, I'm fine with you leaving it the way you have it, since it was originally that way before the recent changes; unless someone else has objections.

Thanks for explaining your reasoning.

The new WiredTiger engine is introduced in MongoDB 3.2.
It changes the output errmsg format for violation of unique index.
This commit adds support for the new format.

Fixes meanjs#1245
@QiyuLi QiyuLi force-pushed the fix/supoort_mongo_3.2 branch from 8268ae7 to 6265aaa Compare March 4, 2016 15:55
@QiyuLi
Copy link
Contributor Author

QiyuLi commented Mar 4, 2016

@mleanos I re-submit the commit including the fix !== -1

@mleanos
Copy link
Member

mleanos commented Mar 5, 2016

@QiyuLi Thank you. LGTM now.

@lirantal @ilanbiala @codydaig LGTY?

Also, are you we ignoring the bitHound builds? They never seem to complete :)

@ilanbiala
Copy link
Member

@QiyuLi Why add in more complex support and revert the changes instead of using the looser validation that covers both?

@trendzetter
Copy link
Contributor

@ilanbiala https://cloud.githubusercontent.com/assets/5421502/13476128/5fab7546-e094-11e5-9e37-e4394f7653f8.png I think it is solving a usability issue in the ui too. The test is giving a valid alert and should not be loosened.

@QiyuLi
Copy link
Contributor Author

QiyuLi commented Mar 7, 2016

@ilanbiala trendzetter did a good summary.
Loosened assert will cause improper alert display on user screen.

@trendzetter
Copy link
Contributor

I have come to understand that this issue and pr should account as a serious warning about code quality and applying best practices. I didn't know at the time I loosened the tests what I was actually doing because I wasn't very familiar with the tests and the issue didn't show up with me. Someone forwarded me this "fix" to include. Good tests should not be fixed rather the code should be fixed to behave according to the use cases. I should not have been allowed to modify the tests. If someone suggests to fix the tests you should always question if there is really something wrong with the tests or is it mangling the tests to suit the issue.

mleanos added a commit to mleanos/mean that referenced this pull request Mar 8, 2016
Adds the mongoose-beautiful-unique-validation package, and implements it
on the Sign Up server controller, as a proof of concept.

Would like to get others to test this using various MongoDB versions;
preferably versions > 3.0.7

The implementation seems pretty simple, and we can choose when to use it
since it requires exposes `trySave` as a save method that will implement
the Beautiful Unique Validator.

Related meanjs#1246
@mleanos
Copy link
Member

mleanos commented Mar 8, 2016

We definitely need to reconcile the differences in the validation errors that newer versions of MongoDB are generating. That's the main point of the fix here.

As for whether or not the tests need to change, it's up for debate. The decision was made previously to use containEql & toLowerCase; which I think was a good decision.

To be clear, the asserts (in the tests) have no bearing on what messages are sent to the UI. I think there might be some confusion there with the terminology.

I think the fix here is fine, and don't have a super strong opinion whether or not to change the assertions.

@simison mentioned a possible solution with the mongoose-beautiful-unique-validation package. I looked at it & think it's very promising. I can't tell if there are any MongoDB version compatibility issues. If we want to explore this package, I think it could be helpful to have others test this. Preferably using versions of MongoDB > 3.0.7 (as that's what I have tested it with). I pushed up a branch to my fork for anyone that want's to test.

mleanos@84d8c02

@trendzetter
Copy link
Contributor

@mleanos I disagree that it is a good decision to add containEql and tolowercase.
Sending "Email already exists" or """t"'y!ç( b§"ç!"bàv ç!,ute eMAIL aLREaDy eXists" would both satisfy the test but only one is acceptable to send to the UI. These test were testing an exact string with a good reason.

To be clear, the asserts (in the tests) have no bearing on what messages are sent to the UI.

I am not sure if I understand you correctly here. The tests do test what is send to the UI, right? Isn't testing what is in the UI exactly the point of e2e tests?

@mleanos
Copy link
Member

mleanos commented Mar 8, 2016

What i meant was that we're merely assertng against what is sent to the Ui. So if we use containEql or eql doesn't affect the message sent to the Ui.

@trendzetter
Copy link
Contributor

The e2E test should give an error if what is send is not acceptable output. The exact check does that but the loosened check doesn't.

@mleanos
Copy link
Member

mleanos commented Mar 8, 2016

@trendzetter You're definitely making a good point. However, I'm not sure we have to be so strict in this case. With that said, I'm fine with the change in this PR.

@trendzetter
Copy link
Contributor

@mleanos If you are not strict you allow for all kinds of weirdness to get through, exactly the opposite of why you added tests. The goal of the e2e or system tests is to get an early warning during development that you have broken end user functionality. This test did in fact just that. I (and others) didn't respond correctly by changing the test instead of looking for the issue. One should only change the old test to the new if the test is checking things that aren't required. I would say that in the case of our software, clear readable errors with normal casing and punctuation is a requirement (although I haven't seen any formal requirements or use cases for this software).
It took me a while to wake up to this but now I remember clearly what we learned during the lessons TDD , computer science (yes, I am a qualified software developer, just new to advanced javascript)

Am I making sense or do I give the impression of a weird fanatic? I can't stress enough how important it is to have the correct understanding about this if you want to benefit from testing.

@mleanos
Copy link
Member

mleanos commented Mar 10, 2016

@trendzetter I totally understand, and you're just trying to get your point across. I thank you for that.

Let's wait to see if others have an opinion, and if @ilanbiala has more insight. As I said before, I'm indifferent about the use of containEql vs eql at this point.

@ilanbiala
Copy link
Member

@trendzetter might be right, but honestly I question our use of the error message directly in the UI. I think that's also an issue. Let's just stick with eql since it is actually what we want and not just some part of the string being that.

@mleanos
Copy link
Member

mleanos commented Mar 12, 2016

@QiyuLi I think this is ready. I'll merge over the weekend, if no other concerns are brought up.

@trendzetter
Copy link
Contributor

Sorry for the negative tone. I will be glad if those line are restored. It was really a shameful mistake I managed to sneak in. its encouraging and refreshing seeing others catching such mistakes.

@simison
Copy link
Member

simison commented Mar 14, 2016

@trendzetter remember that contributing to open source is all about team work, being polite and compromising sometimes. And thanks for your and anyone else's efforts on meanjs! Have a fun and good day. :-)
</ offtopic >

@trendzetter
Copy link
Contributor

👍

mleanos added a commit that referenced this pull request Mar 14, 2016
fix(core): Support WiredTiger engine errmsg format in MongoDB 3.2
@mleanos mleanos merged commit 4e9ad81 into meanjs:master Mar 14, 2016
@mleanos
Copy link
Member

mleanos commented Mar 14, 2016

Thank you @QiyuLi & @trendzetter for helping out here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants