Skip to content
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

Adding pymongo functional tests #340

Merged
merged 14 commits into from
Feb 7, 2020

Conversation

hectorhdzg
Copy link
Member

@hectorhdzg hectorhdzg commented Dec 18, 2019

Using similar approach as OpenTelemetry JS to run docker with MongodDB container and run tests against it, currently it will require contributors of this repo to have docker installed and running when executing the tests

Fixes #284

@hectorhdzg hectorhdzg requested a review from a team December 18, 2019 23:18
@codecov-io
Copy link

codecov-io commented Dec 19, 2019

Codecov Report

Merging #340 into master will increase coverage by 0.19%.
The diff coverage is 87.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #340      +/-   ##
==========================================
+ Coverage   85.13%   85.32%   +0.19%     
==========================================
  Files          38       38              
  Lines        1911     1929      +18     
  Branches      225      227       +2     
==========================================
+ Hits         1627     1646      +19     
+ Misses        219      218       -1     
  Partials       65       65
Impacted Files Coverage Δ
...sdk/src/opentelemetry/sdk/trace/export/__init__.py 86.79% <0%> (ø) ⬆️
...-ext-flask/src/opentelemetry/ext/flask/__init__.py 88.88% <100%> (ø) ⬆️
opentelemetry-api/src/opentelemetry/util/types.py 100% <100%> (ø) ⬆️
...emetry-sdk/src/opentelemetry/sdk/trace/__init__.py 90.7% <100%> (-0.24%) ⬇️
...ry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py 68.18% <33.33%> (ø) ⬆️
...xt-zipkin/src/opentelemetry/ext/zipkin/__init__.py 84.41% <84.41%> (ø) ⬆️
...ntelemetry-api/src/opentelemetry/trace/__init__.py 84.56% <89.36%> (ø) ⬆️
...elemetry-api/src/opentelemetry/metrics/__init__.py 87.93% <90.9%> (ø) ⬆️
... and 6 more

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 d021fd8...176cb73. Read the comment docs.

check=False,
)
if process.returncode != 0:
logging.warning("Failed to start MongoDB container")
Copy link
Member

Choose a reason for hiding this comment

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

Why not just use check=True?

Copy link
Member Author

Choose a reason for hiding this comment

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

Container could be already running because it was started by the user, the test didn't execute clean up while debugging, etc. I didn't want to fail the test case here, it would fail when creating MongoClient if something goes wrong anyways

@hectorhdzg hectorhdzg added the needs reviewers PRs with this label are ready for review and needs people to review to move forward. label Jan 2, 2020
Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

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

Overall the tests and the general idea sound great. My one thought is around the startup and shutdown of containers.

Always starting the containers during unit tests

I think that, rather than having a specific CI class, we should just have docker in our CI system, and start up the containers ourselves. Is that possible? My thought here is there's not a lot of value in differentiating the service startup and shutdown process between CI and local testing.

Utility code to start / stop containers.

It looks like there's some libraries that already handle the startup and shutdown of containers.

Now that we're using pytest, we could potentially pick up fixtures and use one of:

Just thinking there's not a lot of value in handling startup and shutdown ourselves, and there's messy cases such as shutting down an already running container (docker run IIRC fails if a container of the same name is already up).

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

I don't think it's a good idea to run docker containers from tests, and I think this approach is likely to cause some serious maintenance headaches in the future.

Some problems I see with this, but not an exhaustive list:

  • If the user doesn't have the mongo docker image cached, downloading the image can take longer than two seconds. As it's written now, if the image isn't cached, each test just hangs for a couple seconds and then fails with a cryptic ServerSelectionTimeoutError error.
  • If the user was running a mongo container before starting the test, this test will stop it. This is pretty surprising behavior.
  • if the user is running mongo outside of docker, we shouldn't need to run the container.

My thought here is there's not a lot of value in differentiating the service startup and shutdown process between CI and local testing.

Running mongo as a TravisCI service means that the container starts in parallel with the tests, instead of starting (and potentially downloading the image) when the fixture is loaded.

I'd prefer for these tests to fail fast if mongo isn't available, and for a dedicated tox target (or script, or etc.) to start and stop mongo as needed.

We should also find a better way to quarantine integration tests with dependencies like this so they don't run as part of the normal test suite.

@hectorhdzg
Copy link
Member Author

@toumorokoshi , @c24t I updated the code to not do any docker related operations in the test classes, created new tox environment just for these to be able to disable easily in case there are any issue and added a dependency on docker-compose to easily add new containers if needed, let me know if you have any feedback

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Thanks for splitting off Docker integration tests into their own target. Change looks good, would love to see a README in opentelemetry-ext-docker or an update to CONTRIBUTING for anyone looking to add new integration tests.

self.assertIsInstance(span.start_time, int)
self.assertIsInstance(span.end_time, int)
self.assertIsNotNone(pymongo_span.parent)
self.assertEqual(pymongo_span.parent.name, root_span.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

By this point you require pymongo_span and root_span to be defined. They may not be if spans only includes 2 spans whose name attribute is "rootSpan" or if it includes 2 spans whose name is not. If any of those happen, you'll get a NameError in a test case when you want to get only AssertionErrors. Instead for looping through spans looking for spans whose name attribute matches, it should be asserted that spans actually contains one span whose name attribute is "rootSpan" and another one whose name attribute is not.

Copy link
Member Author

Choose a reason for hiding this comment

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

The actual test I wanted to include is that rootSpan is parent of other spans created, that is why I'm saving the reference for it so I can assert later, the check of an extra span being created in pymongo is already taken care in self.assertEqual(len(spans), 2) because all tests start with a rootSpan only, are you suggesting to add more check regarding these spans?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, what I am pointing out is that your test case requires self._span_exporter.get_finished_spans() to deliver you 2 spans, one named "rootSpan" and other not, and since it requires that, it is probably something that you want to specifically test.

@c24t
Copy link
Member

c24t commented Feb 7, 2020

Sorry to hold you up @hectorhdzg. This PR LGTM after splitting off the docker tests, and it looks like you addressed @ocelotl's comment in 176cb73.

@c24t c24t requested a review from ocelotl February 7, 2020 07:42
@c24t
Copy link
Member

c24t commented Feb 7, 2020

@ocelotl if this LGTY we can merge it.

@ocelotl
Copy link
Contributor

ocelotl commented Feb 7, 2020

Sure, I think this could be addressed but it is not critical. 👍

@c24t c24t merged commit f42bc5b into open-telemetry:master Feb 7, 2020
toumorokoshi pushed a commit to toumorokoshi/opentelemetry-python that referenced this pull request Feb 17, 2020
@hectorhdzg hectorhdzg deleted the hectorhdzg/pymongoFunc branch March 24, 2020 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reviewers PRs with this label are ready for review and needs people to review to move forward.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add pymongo integration tests
7 participants