Skip to content

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

Merged
merged 4 commits into from
Mar 25, 2021
Merged

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Mar 18, 2021

While changing test setup to rely on drivers-evergreen-tools, I missed that the AUTH variable needs to be "auth" for drivers-evergreen-tools while "yes" was used for our own scripts. This PR updates the build config and fixes a test that can be flaky due to potential elections in the replica set.

@alcaeus alcaeus self-assigned this Mar 18, 2021
alcaeus added 2 commits March 18, 2021 11:28
This was done for auth due to a bug fixed in 3.7.7, but the change was not reverted (see mongodb-labs/drivers-evergreen-tools#38).
@alcaeus alcaeus requested a review from jmikola March 22, 2021 13:41
$tags = $server->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";
}
Copy link
Member

Choose a reason for hiding this comment

The 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 getServers() is non-deterministic? If so, perhaps this needs to be rewritten to instead have a function that asserts any server has certain tags. For example:

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 array_intersect_assoc() is that its return value uses the same key ordering as the first argument, which makes it possible to do the === check above.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I've kept the loop but removed the use of array_intersect_assoc, as the last check will match for any server:

php > var_dump(array_intersect_assoc([], ['dc' => 'pa', 'ordinal' => 'two']));
array(0) {
}

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 getServers().

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

Suggestion to change to strict equality in the test, but LGTM either way.

echo "ordinal: ", array_key_exists('ordinal', $tags) ? $tags['ordinal'] : 'not set', "\n";
function assertSomeServerHasTags(array $servers, array $expectedTags) {
foreach ($servers as $server) {
if ($expectedTags == $server->getTags()) {
Copy link
Member

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).

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 changed to a strict comparison, which then caused tests to fail again. With some debug output, I was able to capture the following diff:

003+ No server has tags: {"ordinal":"two","dc":"pa"}
004+ Server tags: {"localhost:27017":{"ordinal":"one","dc":"ny"},"localhost:27018":{"dc":"pa","ordinal":"two"},"localhost:27019":[]}
003- Found server with tags: {"ordinal":"two","dc":"pa"}

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.

@alcaeus alcaeus force-pushed the fix-evergreen-auth-testing branch 2 times, most recently from 0bba665 to 63b6a41 Compare March 25, 2021 08:56
@alcaeus alcaeus force-pushed the fix-evergreen-auth-testing branch from 63b6a41 to 4abf4a7 Compare March 25, 2021 09:01
@alcaeus alcaeus merged commit ddfe1c3 into mongodb:master Mar 25, 2021
@alcaeus alcaeus deleted the fix-evergreen-auth-testing branch March 25, 2021 09:25
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