Skip to content

PHPC-424: Validate that RP tag set is an array of documents #399

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

Merged
merged 2 commits into from
Sep 15, 2016

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Sep 12, 2016

https://jira.mongodb.org/browse/PHPC-424

This adds common validation for read preference tag sets when specified through either the Manager constructor's URI options array or ReadPreference constructor.

An additional test case for a malformed tag set has been added to the Manager::__construct() error test for read preference options. Additionally, the ReadPreference::__construct() error test has been split up to test for mode and tagSet errors separately.

Note: we cannot test for the exceptions for bson_init_static() and mongoc_read_prefs_is_valid(), since those points will never be hit in normal operation.


switch(ZEND_NUM_ARGS()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This single-case switch should make sense once you see #400. Since I was refactoring the tagSet validation already, I opted to restructure this early. It should also make the diff for PHPC-752's commit easier to understand.

Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

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

LGTM, except for:

  • the single error message change

@@ -28,4 +32,6 @@ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Unsupported readPreference value: 'nothing'
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Primary read preference mode conflicts with tags
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Read preference tags must be an array of zero or more documents
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should say "Primary read preference mode conflicts with tags". It doesn't matter whether they're valid or not yet.

Copy link
Member Author

@jmikola jmikola Sep 15, 2016

Choose a reason for hiding this comment

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

This is more consistent with the ReadPreference constructor. We're validating individual values before we check the combined state of the read preference. Of course, they'll end up seeing both exceptions in due time (the second will appear after they resolve the first issue).

On that note, I think there's an oversight in php_phongo_apply_rp_options_to_uri() where we're never checking if "maxstalenessms" is a positive value. As-is, I think a negative value would only trigger a generic "Read preference is not valid" error.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added another case to the ReadPreference ctor test to demonstrate that it also reports invalid tag set structure first (before the primary conflict).

This adds common validation for read preference tag sets when specified through either the Manager constructor's URI options array or ReadPreference constructor.

An additional test case for a malformed tag set has been added to the Manager::__construct() error test for read preference options. Additionally, the ReadPreference::__construct() error test has been split up to test for mode and tagSet errors separately.

Note: we cannot test for the exceptions for bson_init_static() and mongoc_read_prefs_is_valid(), since those points will never be hit in normal operation.
@jmikola jmikola merged commit 56d8b77 into mongodb:master Sep 15, 2016
jmikola added a commit that referenced this pull request Sep 15, 2016
@jmikola jmikola deleted the phpc-424 branch September 15, 2016 16:41
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.

2 participants