Merge lp:~gz/bzr/trivial_discard_log_memento_607413 into lp:bzr

Proposed by Martin Packman
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 6222
Proposed branch: lp:~gz/bzr/trivial_discard_log_memento_607413
Merge into: lp:bzr
Diff against target: 33 lines (+4/-8)
1 file modified
bzrlib/tests/__init__.py (+4/-8)
To merge this branch: bzr merge lp:~gz/bzr/trivial_discard_log_memento_607413
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) Approve
Review via email: mp+79572@code.launchpad.net

Commit message

Delete _log_memento after TestCase is done with it so as not to upset the funky weakref cleanup mechanism.

Description of the change

Delete _log_memento after TestCase is done with it so as not to upset the funky weakref cleanup mechanism. The original visible fallout got fixed upstream in the logging module, and with bug 613247 landed the general case of accidentally persisting resources is handled. This branch just makes sure that even with TestCase objects we keep alive on purpose (errors, for instance), the token is thrown away so logging doesn't keep tracking it.

While I was there I updated the docstrings for the TestCase log setup and teardown functions as they no longer deal in tempfiles.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

Are we sure this is safe across supported versions? You mention fixed
upstream, but that always concerns me about compatibility.

John
=:->
On Oct 17, 2011 5:38 PM, "Martin Packman" <email address hidden>
wrote:

> Martin Packman has proposed merging
> lp:~gz/bzr/trivial_discard_log_memento_607413 into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
> Related bugs:
> Bug #607413 in Bazaar: " Exception atexit with selftest and Python 2.7"
> https://bugs.launchpad.net/bzr/+bug/607413
>
> For more details, see:
>
> https://code.launchpad.net/~gz/bzr/trivial_discard_log_memento_607413/+merge/79572
>
> Delete _log_memento after TestCase is done with it so as not to upset the
> funky weakref cleanup mechanism. The original visible fallout got fixed
> upstream in the logging module, and with bug 613247 landed the general case
> of accidentally persisting resources is handled. This branch just makes sure
> that even with TestCase objects we keep alive on purpose (errors, for
> instance), the token is thrown away so logging doesn't keep tracking it.
>
> While I was there I updated the docstrings for the TestCase log setup and
> teardown functions as they no longer deal in tempfiles.
> --
>
> https://code.launchpad.net/~gz/bzr/trivial_discard_log_memento_607413/+merge/79572
> Your team bzr-core is requested to review the proposed merge of
> lp:~gz/bzr/trivial_discard_log_memento_607413 into lp:bzr.
>
> === modified file 'bzrlib/tests/__init__.py'
> --- bzrlib/tests/__init__.py 2011-10-14 01:48:16 +0000
> +++ bzrlib/tests/__init__.py 2011-10-17 15:36:26 +0000
> @@ -1718,10 +1718,7 @@
> return result
>
> def _startLogFile(self):
> - """Send bzr and test log messages to a temporary file.
> -
> - The file is removed as the test is torn down.
> - """
> + """Setup a in-memory target for bzr and testcase log messages"""
> pseudo_log_file = StringIO()
> def _get_log_contents_for_weird_testtools_api():
> return [pseudo_log_file.getvalue().decode(
> @@ -1734,14 +1731,13 @@
> self.addCleanup(self._finishLogFile)
>
> def _finishLogFile(self):
> - """Finished with the log file.
> -
> - Close the file and delete it.
> - """
> + """Flush and dereference the in-memory log for this testcase"""
> if trace._trace_file:
> # flush the log file, to get all content
> trace._trace_file.flush()
> trace.pop_log_file(self._log_memento)
> + # The logging module now tracks references for cleanup so discard
> ours
> + del self._log_memento
>
> def thisFailsStrictLockCheck(self):
> """It is known that this test would fail with -Dstrict_locks.
>
>
>

Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
Martin Packman (gz) wrote :

> Are we sure this is safe across supported versions? You mention fixed
> upstream, but that always concerns me about compatibility.

Yes, this is just avoiding problems from a change in 2.7 which caused logging to try flushing things late on in module teardown. Prior to that, trace.pop_log_file did everything needed for cleanup and there was no need to care about references at all.

The original Python change:
<http://bugs.python.org/issue6615>
<http://hg.python.org/cpython/diff/022cd0f3c558/Lib/logging/__init__.py>

We're defended against weird behaviour from this pretty well already, using StringIO rather than real files and cleaning up testcases as we go should be enough, this is just a cherry on top.

Revision history for this message
Martin Pool (mbp) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/tests/__init__.py'
2--- bzrlib/tests/__init__.py 2011-10-14 01:48:16 +0000
3+++ bzrlib/tests/__init__.py 2011-10-17 15:36:26 +0000
4@@ -1718,10 +1718,7 @@
5 return result
6
7 def _startLogFile(self):
8- """Send bzr and test log messages to a temporary file.
9-
10- The file is removed as the test is torn down.
11- """
12+ """Setup a in-memory target for bzr and testcase log messages"""
13 pseudo_log_file = StringIO()
14 def _get_log_contents_for_weird_testtools_api():
15 return [pseudo_log_file.getvalue().decode(
16@@ -1734,14 +1731,13 @@
17 self.addCleanup(self._finishLogFile)
18
19 def _finishLogFile(self):
20- """Finished with the log file.
21-
22- Close the file and delete it.
23- """
24+ """Flush and dereference the in-memory log for this testcase"""
25 if trace._trace_file:
26 # flush the log file, to get all content
27 trace._trace_file.flush()
28 trace.pop_log_file(self._log_memento)
29+ # The logging module now tracks references for cleanup so discard ours
30+ del self._log_memento
31
32 def thisFailsStrictLockCheck(self):
33 """It is known that this test would fail with -Dstrict_locks.