Skip to content

PYTHON-1878 Add mongodb+srv URIs to Atlas Connectivity tests #538

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 6 commits into from
Jan 6, 2021

Conversation

ShaneHarvey
Copy link
Member

No description provided.

. ./prepare_atlas_connectivity.sh
rm -f ./prepare_atlas_connectivity.sh

PYTHON_BINARY=${PYTHON_BINARY} bash ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh
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 is a more user friendly way to manage secrets. We load the env variables in secret (with silent:true) and then we're free to use xtrace and view test output as usual. Now we can actually see why a task failed :)

Copy link
Contributor

Choose a reason for hiding this comment

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

<3 it!

set -o errexit
set -o xtrace
Copy link
Member Author

Choose a reason for hiding this comment

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

We can do this safely. We just need to remember not to print or use the secret variables in the shell script.

echo "Running tests without dnspython"
python test/atlas/test_connection.py

# dnspython is incompatible with Jython so don't test that combination.
Copy link
Member Author

Choose a reason for hiding this comment

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

# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
PYTHON_BINARY=${PYTHON_BINARY} ATLAS_REPL='${atlas_repl}' ATLAS_SHRD='${atlas_shrd}' ATLAS_FREE='${atlas_free}' ATLAS_TLS11='${atlas_tls11}' ATLAS_TLS12='${atlas_tls12}' sh ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh
cat <<EOT > prepare_atlas_connectivity.sh
export ATLAS_FREE='${atlas_free}'
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 we can further optimize some of these invocations by switching to using subprocess.exec instead of shell.exec and then setting either theinclude_expansions_in_env option or the add_expansions_to_env option to automatically set the appropriate environment variables. I suppose we don't need to do it right now, but being able to eventually eliminate the use of $PREPARE_SHELL would be a huge improvement IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify, I am just suggesting this as a future optimization/refactor. Not saying that we need to do it in this PR. Would love to hear your thoughts on it @ShaneHarvey

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool idea! Can you open a ticket with this comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

. ./prepare_atlas_connectivity.sh
rm -f ./prepare_atlas_connectivity.sh

PYTHON_BINARY=${PYTHON_BINARY} bash ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

<3 it!

def test_srv_tls_12(self):
_connect(ATLAS_SRV_TLS12)

@unittest.skipUnless(PYMONGO_MUST_HAVE_DNS, 'dnspython is optional')
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Can you add a comment/docstring detailing what this test achieves? Specifically, we don't end up silently skipping all tests if dnspython is not installed (instead we get a failure due to this test).

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 this up a bit. PTAL at the new approach:

@unittest.skipUnless(HAS_DNS or MUST_TEST_SRV, 'SRV requires dnspython')

Copy link
Member Author

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

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

I updated the tests in response to your detailed review and added an extra test to ensure:

  • that we don't accidentally duplicate the test URIs in our evergreen project configs (because I'm paranoid).
  • that the SRV uris actually contain mongodb+srv://.

Please take another look.

def test_srv_tls_12(self):
_connect(ATLAS_SRV_TLS12)

@unittest.skipUnless(PYMONGO_MUST_HAVE_DNS, 'dnspython is optional')
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 this up a bit. PTAL at the new approach:

@unittest.skipUnless(HAS_DNS or MUST_TEST_SRV, 'SRV requires dnspython')

@ShaneHarvey ShaneHarvey merged commit a9d668c into mongodb:master Jan 6, 2021
ShaneHarvey added a commit that referenced this pull request Jan 6, 2021
Enable xtrace with silent:false to make test failures easier to diagnose.

(cherry picked from commit a9d668c)
@ShaneHarvey ShaneHarvey deleted the PYTHON-1878 branch January 6, 2021 23:21
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