Skip to content

Refactor testing console exporter #2877

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 7 commits into from
Aug 26, 2022
Merged

Conversation

ocelotl
Copy link
Contributor

@ocelotl ocelotl commented Aug 16, 2022

Fixes #2876

@ocelotl ocelotl self-assigned this Aug 16, 2022
@ocelotl ocelotl requested a review from a team August 16, 2022 17:24
@ocelotl ocelotl added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Aug 16, 2022
@aabmass
Copy link
Member

aabmass commented Aug 16, 2022

Based on the description in the issue, it sounds like the problem is the test cases are not calling shutdown() on the SDK which causes the background thread to leak in the tests and then export() after the test is ended?

@ocelotl
Copy link
Contributor Author

ocelotl commented Aug 17, 2022

Based on the description in the issue, it sounds like the problem is the test cases are not calling shutdown() on the SDK which causes the background thread to leak in the tests and then export() after the test is ended?

We automatically call shutdown() on exit (using atexit in the MeterProvider), so we should not need to call shutdown() manually. The issue here is that (if I am understanding Pytest correctly) when the -s option is not passed to Pytest, it keeps stdout open only during the call phase of the tests (the actual testing) and not during the teardown phase of the tests (when Pytest exits and the shutdown function previously registered via atexit.register is called).

I think we could configure the MeterProvider in our tests not to call shutdown() on exit and add a teardown function for Pytest that calls the shutdown() function manually, but this function end up being called in the teardown phase of the tests too, so I think we should get the same problem because by that moment the Pytest would have closed the stdout file already too if the -s option was not passed. That is just an hypotheses, though.

All this being said, we should still always use devnull to capture the output of the ConsoleExporter when testing it because we want to keep the testing output as clean as possible, even when -s is passed.

Copy link
Member

@aabmass aabmass left a comment

Choose a reason for hiding this comment

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

Ah I think you're right that it's the atexit handler. I'm guessing pytest patches sys.stdout during the test.

We automatically call shutdown() on exit (using atexit in the MeterProvider), so we should not need to call shutdown() manually.

That is true, but pytest runs all of the test in a single process. So anything that happens in a test that doesn't get torn down will leak into all the tests. E.g. each PeriodicExportingMetricReader instance has a background thread which will leak and could really slow down our tests. I guess this is a separate issue from this one though.

@ocelotl
Copy link
Contributor Author

ocelotl commented Aug 17, 2022

Ah I think you're right that it's the atexit handler. I'm guessing pytest patches sys.stdout during the test.

We automatically call shutdown() on exit (using atexit in the MeterProvider), so we should not need to call shutdown() manually.

That is true, but pytest runs all of the test in a single process. So anything that happens in a test that doesn't get torn down will leak into all the tests. E.g. each PeriodicExportingMetricReader instance has a background thread which will leak and could really slow down our tests. I guess this is a separate issue from this one though.

Good point, but I agree this is another issue for another PR.

@ocelotl ocelotl requested a review from aabmass August 17, 2022 16:18
@ocelotl ocelotl changed the title Use devnull instead of stdout when testing console exporter Refactor testing console exporter Aug 23, 2022
@ocelotl ocelotl force-pushed the issue_2876 branch 3 times, most recently from d5243bc to 952253f Compare August 24, 2022 12:54
@ocelotl ocelotl marked this pull request as draft August 24, 2022 13:04
@ocelotl
Copy link
Contributor Author

ocelotl commented Aug 24, 2022

This test is failing in CI (but not in my laptop 🙄). Marking this PR as draft while I investigate this.

@ocelotl ocelotl marked this pull request as ready for review August 24, 2022 14:38
@srikanthccv srikanthccv added the Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary label Aug 26, 2022
@ocelotl ocelotl merged commit 6ccdada into open-telemetry:main Aug 26, 2022
@ocelotl ocelotl deleted the issue_2876 branch August 26, 2022 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testing console exporter produces error message after testing ends
3 participants