Skip to content

bpo-30635: Fix refleak in test_c_locale_coercion#2126

Merged
ncoghlan merged 4 commits intopython:masterfrom
vstinner:test_c_locale_coercion
Jun 13, 2017
Merged

bpo-30635: Fix refleak in test_c_locale_coercion#2126
ncoghlan merged 4 commits intopython:masterfrom
vstinner:test_c_locale_coercion

Conversation

@vstinner
Copy link
Member

Fix a reference leak in test_c_locale_coercion and refactor the code to make it faster.

vstinner added 4 commits June 12, 2017 12:12
When checking for reference leaks, test_c_locale_coercion is run
multiple times and so _LocaleCoercionTargetsTestCase.setUpClass() is
called multiple times. setUpClass() appends new value at each call.

Use _LocaleCoercionTargetsTestCase.available_targets as a marker to
check if the class is already initialized or not.
Convert setUpClass() to setUpModule() to only compute
AVAILABLE_TARGETS once to spawn less processes.

Speed up test_c_locale_coercion: 3.2 sec => 2.9 sec.
Copy link
Member

@matrixise matrixise left a comment

Choose a reason for hiding this comment

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

this PR fixes the issue with the leak.

Copy link
Contributor

@ncoghlan ncoghlan 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 this, but it's currently a bit too aggressive in skipping test cases.

Moving the skip logic back into the class setup, but leaving the calculation of AVAILABLE_TARGETS at module level should do the trick on that front.

if _set_locale_in_subprocess(target_locale):
AVAILABLE_TARGETS.append(target_locale)
if not AVAILABLE_TARGETS:
raise unittest.SkipTest("No C-with-UTF-8 locale available")
Copy link
Contributor

Choose a reason for hiding this comment

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

There are other tests in the module that should be run regardless of whether or not these locales are available.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah you merged my PR even if I didn't address your comment: "There are other tests in the module that should be run regardless of whether or not these locales are available." ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I realised that since I was updating this test case anyway, I could just incorporate that into #2130


class _LocaleCoercionTargetsTestCase(_ChildProcessEncodingTestCase):
# Base class for test cases that rely on coercion targets being defined
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

The cls.targets_required and not AVAILABLE_TARGETS check should still be handled in setupClass so that the other tests still run as expected, even when locale coercion isn't possible.

expected_warning.append(self.EXPECTED_COERCION_WARNING)
# Expect coercion to use the first available locale
warning_msg = CLI_COERCION_WARNING_FMT.format(AVAILABLE_TARGETS[0])
expected_warning.append(warning_msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch, I'd missed that that particular simplification was possible now.

@ncoghlan
Copy link
Contributor

I need to make other updates to this test case anyway, so I can handle moving the skip back into setupClass as part of that.

@ncoghlan ncoghlan merged commit 023564b into python:master Jun 13, 2017
@vstinner vstinner deleted the test_c_locale_coercion branch June 13, 2017 11:33
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.

4 participants