Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Mongo read preference #393

Merged
merged 2 commits into from
Aug 14, 2017
Merged

Conversation

SamBartrum
Copy link
Contributor

A potential fix relating to this issue: #392

Expose the ability to set the mongo read preference within the connection config.

(This is my first time writing any go, so go easy on me!)

Required for all PRs:

  • CHANGELOG.md updated (feel free to wait until changes have been reviewed by a maintainer)
  • README.md updated (if needed)

@jipperinbham
Copy link
Contributor

this looks great and inline with the general code style

I took a cursory look at the failing tests and will try to reproduce locally.

@SamBartrum
Copy link
Contributor Author

Excellent. I'll try and figure out what is going wrong with the tests too - although not had much luck so far.

@jipperinbham
Copy link
Contributor

@SamBartrum ok, I tracked down the issue, the tests use a different session to check doc counts and such. You need to add readPreference: DefaultReadPreference, right after here. After making that change locally against your branch, the tests passed.

@compose compose deleted a comment from codecov bot Aug 14, 2017
@codecov
Copy link

codecov bot commented Aug 14, 2017

Codecov Report

Merging #393 into master will increase coverage by 0.14%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #393      +/-   ##
==========================================
+ Coverage   84.42%   84.57%   +0.14%     
==========================================
  Files          59       59              
  Lines        4046     4071      +25     
==========================================
+ Hits         3416     3443      +27     
+ Misses        468      467       -1     
+ Partials      162      161       -1
Impacted Files Coverage Δ
adaptor/mongodb/client.go 100% <100%> (ø) ⬆️
adaptor/mongodb/mongodb.go 100% <100%> (ø) ⬆️
events/emitter.go 83.09% <0%> (+2.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a25a8e1...6d04710. Read the comment docs.

Copy link
Contributor

@jipperinbham jipperinbham left a comment

Choose a reason for hiding this comment

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

overall, changes look great, just have a few nitpicks

c.readPreference = DefaultReadPreference
return nil
}
switch read_preference {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking it'd be nice to do a strings.ToLower(read_preference) here so the preference is insensitive.

readPreference: 2,
},
nil,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

please add test cases to cover all possible preferences

client/error.go Outdated
@@ -49,3 +49,12 @@ func (e VersionError) Error() string {
}
return fmt.Sprintf("%s running %s, %s", e.URI, e.V, e.Err)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

this should be in adaptor/mongodb/client.go (below here) since it's specific to mongodb

@jipperinbham
Copy link
Contributor

LGTM, if you could rebase from master and preferably squash the commits, I'll get this merged in

@SamBartrum SamBartrum force-pushed the mongo_read_preference branch from ac11ebe to 60b614b Compare August 14, 2017 18:15
… squashed commits)

Squashed commits:
[60b614b] Move mongo specific error to mongodb/client. Add more tests to cover all read preferences. Allow for case insensitive read preference to be set. (+5 squashed commits)
Squashed commits:
[381efce] Fix failing tests
[82c48da] Unit tests for mongo read preference setting. Fixed other unit tests in light of the new default read preference.
[11e7ed9] Update readme to show read preference in the mongo config.
[ae4c94e] Remove mgo specific read preferences.
[b636058] Can now set mongo read preference in config, defaults to Primary and raises an error if the read preference is not known.
[677afaf] Initial commit. Starting to expose option to set mongo read preference.
@SamBartrum SamBartrum force-pushed the mongo_read_preference branch from 60b614b to 3306ac0 Compare August 14, 2017 19:11
@SamBartrum
Copy link
Contributor Author

Just added a last minute test for the InvalidReadPreferenceError and fixed a typo in a test. It should now be rebased from master and squashed into a single commit. Good to go?

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

Successfully merging this pull request may close these issues.

2 participants