Rev 5080: (andrew) Try to avoid failing tests due to 'close() called during in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Mar 10 06:38:30 GMT 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5080 [merge]
revision-id: pqm at pqm.ubuntu.com-20100310063827-8flct2zz07y0oywf
parent: pqm at pqm.ubuntu.com-20100310011027-9hbbdjalglssr00a
parent: andrew.bennetts at canonical.com-20100310060251-tog0lw6k9ciqnpjo
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2010-03-10 06:38:27 +0000
message:
(andrew) Try to avoid failing tests due to 'close() called during
concurrent operation' during TestCase.finishLogFile. (#531746)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
=== modified file 'NEWS'
--- a/NEWS 2010-03-07 03:04:12 +0000
+++ b/NEWS 2010-03-10 06:38:27 +0000
@@ -168,6 +168,13 @@
* Stop sending apport crash files to ``.cache`` in the directory from
which ``bzr selftest`` was run. (Martin Pool, #422350)
+* Tests no longer fail if "close() called during concurrent
+ operation on the same file object" occurs when closing the log file
+ (which can happen if a thread tries to write to the log file at the
+ wrong moment). An warning will be written to ``stderr`` when this
+ happens, and another warning will be written if the log file could not
+ be closed after retrying 100 times. (Andrew Bennetts, #531746)
+
bzr 2.1.1
#########
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2010-02-18 02:15:48 +0000
+++ b/bzrlib/tests/__init__.py 2010-03-10 06:02:51 +0000
@@ -1671,7 +1671,33 @@
unicodestr = log_contents.decode('utf8', 'replace')
log_contents = unicodestr.encode('utf8')
if not keep_log_file:
- self._log_file.close()
+ close_attempts = 0
+ max_close_attempts = 100
+ first_close_error = None
+ while close_attempts < max_close_attempts:
+ close_attempts += 1
+ try:
+ self._log_file.close()
+ except IOError, ioe:
+ if ioe.errno is None:
+ # No errno implies 'close() called during
+ # concurrent operation on the same file object', so
+ # retry. Probably a thread is trying to write to
+ # the log file.
+ if first_close_error is None:
+ first_close_error = ioe
+ continue
+ raise
+ else:
+ break
+ if close_attempts > 1:
+ sys.stderr.write(
+ 'Unable to close log file on first attempt, '
+ 'will retry: %s\n' % (first_close_error,))
+ if close_attempts == max_close_attempts:
+ sys.stderr.write(
+ 'Unable to close log file after %d attempts.\n'
+ % (max_close_attempts,))
self._log_file = None
# Permit multiple calls to get_log until we clean it up in
# finishLogFile
More information about the bazaar-commits
mailing list