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

TST: extend check for leaked files #39047

Closed
wants to merge 2 commits into from
Closed

TST: extend check for leaked files #39047

wants to merge 2 commits into from

Conversation

twoertwein
Copy link
Member

@twoertwein twoertwein commented Jan 9, 2021

Use ResourceWarnings as indicators of leaked files. I left the psutil-based check for leaked files.

I enabled the check for leaked files for all io tests.

boto3 (#17058) is probably causing all of the unclosed ssl connections. This PR ignores ResourceWarnings that contain the string 'ssl'. The fixture applied to all io tests further ignores all connections found by psutils for the same reason. Connections are checked for code that was previously covered by check_file_leaks.

@pep8speaks
Copy link

pep8speaks commented Jan 9, 2021

Hello @twoertwein! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-03-31 11:44:04 UTC

@twoertwein twoertwein marked this pull request as draft January 9, 2021 03:53
@jreback jreback added the Testing pandas testing functions or related to the test suite label Jan 9, 2021
@@ -64,6 +64,7 @@ xfail_strict = True
filterwarnings =
error:Sparse:FutureWarning
error:The SparseArray:FutureWarning
always::ResourceWarning
Copy link
Member Author

@twoertwein twoertwein Jan 18, 2021

Choose a reason for hiding this comment

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

default::ResourceWarning might create less spam and probably catch the same mistakes. If I interpret default correctly, it will only create one warning instead of repeating it over and over (one test should fail, but not all test that use the failed function will fail). I might be wrong on that.

Copy link
Contributor

Choose a reason for hiding this comment

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

can you leave this out?

Copy link
Member Author

Choose a reason for hiding this comment

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

python doesn't show ResourceWarnings by default (irronically -W default is not the default). Instead of having always::ResourceWarning here (or default:...), it would also be possible to have warnings.simplefilter("always", category=ResourceWarning) within the context manager or in conftest.py.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, but then how do we know this is working?

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 locally tested whether it errors on open(...) without a call to close. I will look into making a test that is expected to fail to make sure that the line is not accidentally removed in the future.

@twoertwein twoertwein marked this pull request as ready for review January 18, 2021 17:00
ci/deps/actions-37-cov.yaml Outdated Show resolved Hide resolved
ci/deps/actions-37-cov.yaml Outdated Show resolved Hide resolved
@@ -64,6 +64,7 @@ xfail_strict = True
filterwarnings =
error:Sparse:FutureWarning
error:The SparseArray:FutureWarning
always::ResourceWarning
Copy link
Contributor

Choose a reason for hiding this comment

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

can you leave this out?

@twoertwein
Copy link
Member Author

twoertwein commented Jan 26, 2021

I added a test to make sure that ResourceWarning are being generated+caught: it works for me locally and on some of the CI test runs.

The test to check this leaks a file ending with "_resoruce_test" [1]. For the test runs that fail it seems that this exact file's ResourceWarning is associated with different tests!?! I don't understand how the warnings are associated with different tests!

[1] https://github.com/pandas-dev/pandas/pull/39047/files#diff-6e61080cbd905ab74df62dfef5763fe30dc51efd2db7a56a5a9d38281dd96e7bR450

edit: this phenomenon might probably also explain some ssl ResourceWarnings in test that definitely have no ssl/networking component.


conns2 = proc.connections()
assert conns2 == conns, (conns2, conns)
def __init__(self, ignore_connections: bool = False):
Copy link
Member

Choose a reason for hiding this comment

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

why would we ignore connections?

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 disabled them when extending the test to pandas/tests/io since we probably catch some ssl connections from boto3. I will double check whether that is needed. Tests that were previously covered by check_file_leaks have their connections checked.

Do you have an idea what might be causing #39047 (comment) ?

Copy link
Member

Choose a reason for hiding this comment

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

Do you have an idea what might be causing #39047 (comment) ?

I've never had any luck in tracking down the unclosed ssl socket warnings. the connections part of check_file_leaks was supposed to identify them, but apparently doesnt

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 have a feeling that associating ResoruceWarnings with different tests might be an issue with pytest-xdist. I found a few issues about warnings on their github but nothing that would directly explain what I see in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

could try some CI runs with xdist disabled?

Copy link
Member Author

Choose a reason for hiding this comment

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

what is the bes way to disable it? I tried to add -n 0 to addopts in setup.cfg but that has no effect as pytest seems to be called with -n auto

@jreback
Copy link
Contributor

jreback commented Feb 27, 2021

@twoertwein how's this coming?

@twoertwein
Copy link
Member Author

@twoertwein how's this coming?

I assume pytest-xdist might cause warnings to be associated with the other tests but I haven't yet tested disabling pytest-xdist on the CI.

@jbrockmendel
Copy link
Member

@twoertwein do you have a plan in mind for how to get this finished?

@twoertwein
Copy link
Member Author

@twoertwein do you have a plan in mind for how to get this finished?

It still fails when running pytest with -n 0 --dist=no. I'm not sure of to further debug this: there must be some difference between me running the tests locally and the CI. I do not get the failing tests on my machine.

@jbrockmendel
Copy link
Member

I'm not sure of to further debug this: there must be some difference between me running the tests locally and the CI. I do not get the failing tests on my machine.

Sorry to hear that, and that i dont have any helpful suggestions.

If you're not planning on working on this in the near future, let's close this to clear the queue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants