-
Notifications
You must be signed in to change notification settings - Fork 208
Fix running auth tests #1206
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
Fix running auth tests #1206
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"id": "repl0", | ||
"members": [ | ||
{ | ||
"procParams": { | ||
"ipv6": true, | ||
"bind_ip": "127.0.0.1,::1", | ||
"journal": true, | ||
"oplogSize": 500, | ||
"port": 27017 | ||
}, | ||
"rsParams": { | ||
"tags": { | ||
"ordinal": "one", | ||
"dc": "ny" | ||
} | ||
} | ||
}, | ||
{ | ||
"procParams": { | ||
"ipv6": true, | ||
"bind_ip": "127.0.0.1,::1", | ||
"journal": true, | ||
"oplogSize": 500, | ||
"port": 27018 | ||
}, | ||
"rsParams": { | ||
"tags": { | ||
"ordinal": "two", | ||
"dc": "pa" | ||
} | ||
} | ||
}, | ||
{ | ||
"procParams": { | ||
"ipv6": true, | ||
"bind_ip": "127.0.0.1,::1", | ||
"journal": true, | ||
"port": 27019 | ||
}, | ||
"rsParams": { | ||
} | ||
} | ||
], | ||
"sslParams": { | ||
"sslOnNormalPorts": true, | ||
"sslPEMKeyFile": "ABSOLUTE_PATH_REPLACEMENT_TOKEN/.evergreen/x509gen/server.pem", | ||
"sslCAFile": "ABSOLUTE_PATH_REPLACEMENT_TOKEN/.evergreen/x509gen/ca.pem", | ||
"sslWeakCertificateValidation" : true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"id": "repl0", | ||
"members": [ | ||
{ | ||
"procParams": { | ||
"ipv6": true, | ||
"bind_ip": "127.0.0.1,::1", | ||
"journal": true, | ||
"oplogSize": 500, | ||
"port": 27017 | ||
}, | ||
"rsParams": { | ||
"tags": { | ||
"ordinal": "one", | ||
"dc": "ny" | ||
} | ||
} | ||
}, | ||
{ | ||
"procParams": { | ||
"ipv6": true, | ||
"bind_ip": "127.0.0.1,::1", | ||
"journal": true, | ||
"oplogSize": 500, | ||
"port": 27018 | ||
}, | ||
"rsParams": { | ||
"tags": { | ||
"ordinal": "two", | ||
"dc": "pa" | ||
} | ||
} | ||
}, | ||
{ | ||
"procParams": { | ||
"ipv6": true, | ||
"bind_ip": "127.0.0.1,::1", | ||
"journal": true, | ||
"port": 27019 | ||
}, | ||
"rsParams": { | ||
} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,21 +9,32 @@ MongoDB\Driver\Server::getTags() with replica set | |
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
$manager = new MongoDB\Driver\Manager(URI); | ||
$command = new MongoDB\Driver\Command(['ping' => 1]); | ||
$manager->executeCommand(DATABASE_NAME, $command); | ||
|
||
$tags = $manager->selectServer(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY))->getTags(); | ||
echo "dc: ", array_key_exists('dc', $tags) ? $tags['dc'] : 'not set', "\n"; | ||
echo "ordinal: ", array_key_exists('ordinal', $tags) ? $tags['ordinal'] : 'not set', "\n"; | ||
function assertSomeServerHasTags(array $servers, array $expectedTags) { | ||
foreach ($servers as $server) { | ||
/* Using a non-strict comparison guards against tags being returned in | ||
* a different order than expected. */ | ||
if ($expectedTags == $server->getTags()) { | ||
printf("Found server with tags: %s\n", json_encode($expectedTags)); | ||
return; | ||
} | ||
} | ||
|
||
$tags = $manager->selectServer(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY))->getTags(); | ||
echo "dc: ", array_key_exists('dc', $tags) ? $tags['dc'] : 'not set', "\n"; | ||
echo "ordinal: ", array_key_exists('ordinal', $tags) ? $tags['ordinal'] : 'not set', "\n"; | ||
printf("No server has tags: %s\n", json_encode($expectedTags)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still a potentially flaky test if the order of servers returned by function assertSomeServerHasTags($servers, $expectedTags) {
foreach ($servers as $server) {
if (array_intersect_assoc($expectedTags, $server->getTags()) === $expectedTags) {
printf("Found server with tags: %s\n", json_encode($expectedTags));
return;
}
}
printf("No server has tags: %s\n", json_encode($expectedTags));
}
$servers = $manager->getServers();
assertSomeServerHasTags($servers, ['dc' => 'ny', 'ordinal' => 'one']);
assertSomeServerHasTags($servers, ['dc' => 'pa', 'ordinal' => 'two']);
assertSomeServerHasTags($servers, []); My understanding of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I've kept the loop but removed the use of
A loose equality check works around this, and since we're expecting the tags in the order that we create them I think that should be safe but still protect us against non-deterministic order of the server returned from |
||
|
||
$servers = $manager->getServers(); | ||
assertSomeServerHasTags($servers, ['dc' => 'ny', 'ordinal' => 'one']); | ||
assertSomeServerHasTags($servers, ['dc' => 'pa', 'ordinal' => 'two']); | ||
assertSomeServerHasTags($servers, []); | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECTF-- | ||
dc: ny | ||
ordinal: one | ||
dc: pa | ||
ordinal: two | ||
--EXPECT-- | ||
Found server with tags: {"dc":"ny","ordinal":"one"} | ||
Found server with tags: {"dc":"pa","ordinal":"two"} | ||
Found server with tags: [] | ||
===DONE=== |
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.
If
getTags()
returns an array, is there any reason we can't do a strict equality check here?Both are going to enforce the same order AFAIK, and the associative array itself just has string keys and values (no concern with mismatched types).
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 changed to a strict comparison, which then caused tests to fail again. With some debug output, I was able to capture the following diff:
As you can see, the tags returned for the second server has a different order from the first, which causes a strict equality check to fail. I've added a comment to clarify why we're using
==
in the test for future reference.