Rev 5745: (mbp) remove dead code in lockdir and fetch tests (Martin Pool) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Mar 31 05:16:55 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5745 [merge]
revision-id: pqm at pqm.ubuntu.com-20110331051652-e24z29v6f33oylm9
parent: pqm at pqm.ubuntu.com-20110330131515-22rogl3u22r21tym
parent: mbp at canonical.com-20110329062453-pr5t0gr7sbid01ph
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-03-31 05:16:52 +0000
message:
(mbp) remove dead code in lockdir and fetch tests (Martin Pool)
modified:
bzrlib/tests/per_interrepository/test_fetch.py test_fetch.py-20080425213627-j60cjh782ufm83ry-1
bzrlib/tests/per_interrepository/test_interrepository.py test_interrepository.py-20060220061411-1ec13fa99e5e3eee
bzrlib/tests/test_lockdir.py test_lockdir.py-20060220222025-33d4221569a3d600
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
=== modified file 'bzrlib/tests/per_interrepository/test_fetch.py'
--- a/bzrlib/tests/per_interrepository/test_fetch.py 2010-02-04 16:06:36 +0000
+++ b/bzrlib/tests/per_interrepository/test_fetch.py 2011-03-28 04:24:47 +0000
@@ -451,18 +451,13 @@
def test_fetch_missing_revision_same_location_fails(self):
repo_a = self.make_repository('.')
repo_b = repository.Repository.open('.')
- try:
- self.assertRaises(errors.NoSuchRevision, repo_b.fetch, repo_a, revision_id='XXX')
- except errors.LockError, e:
- check_old_format_lock_error(self.repository_format)
+ self.assertRaises(errors.NoSuchRevision,
+ repo_b.fetch, repo_a, revision_id='XXX')
def test_fetch_same_location_trivial_works(self):
repo_a = self.make_repository('.')
repo_b = repository.Repository.open('.')
- try:
- repo_a.fetch(repo_b)
- except errors.LockError, e:
- check_old_format_lock_error(self.repository_format)
+ repo_a.fetch(repo_b)
def test_fetch_missing_text_other_location_fails(self):
source_tree = self.make_branch_and_tree('source')
=== modified file 'bzrlib/tests/per_interrepository/test_interrepository.py'
--- a/bzrlib/tests/per_interrepository/test_interrepository.py 2011-02-08 15:35:14 +0000
+++ b/bzrlib/tests/per_interrepository/test_interrepository.py 2011-03-28 04:24:47 +0000
@@ -32,31 +32,6 @@
)
-def check_old_format_lock_error(repository_format):
- """Potentially ignore LockError on old formats.
-
- On win32, with the old OS locks, we get a failure of double-lock when
- we open a object in 2 objects and try to lock both.
-
- On new formats, LockError would be invalid, but for old formats
- this was not supported on Win32.
- """
- if sys.platform != 'win32':
- raise
-
- description = repository_format.get_format_description()
- if description in ("Repository format 4",
- "Weave repository format 5",
- "Weave repository format 6"):
- # jam 20060701
- # win32 OS locks are not re-entrant. So one process cannot
- # open the same repository twice and lock them both.
- raise TestSkipped('%s on win32 cannot open the same'
- ' repository twice in different objects'
- % description)
- raise
-
-
def check_repo_format_for_funky_id_on_win32(repo):
if not repo._format.supports_funky_characters and sys.platform == 'win32':
raise TestSkipped("funky chars not allowed on this platform in repository"
=== modified file 'bzrlib/tests/test_lockdir.py'
--- a/bzrlib/tests/test_lockdir.py 2011-01-12 20:31:15 +0000
+++ b/bzrlib/tests/test_lockdir.py 2011-03-29 06:24:53 +0000
@@ -17,7 +17,6 @@
"""Tests for LockDir"""
import os
-from threading import Thread, Lock
import time
import bzrlib
@@ -43,10 +42,6 @@
)
from bzrlib.trace import note
-# These tests sometimes use threads to test the behaviour of lock files with
-# concurrent actors. This is not a typical (or necessarily supported) use;
-# they're really meant for guarding between processes.
-
# These tests are run on the default transport provided by the test framework
# (typically a local disk transport). That can be changed by the --transport
# option to bzr selftest. The required properties of the transport
@@ -224,226 +219,6 @@
lf1.unlock()
self.assertEqual([], self._logged_reports)
- def test_32_lock_wait_succeed(self):
- """Succeed when trying to acquire a lock that gets released
-
- One thread holds on a lock and then releases it; another
- tries to lock it.
- """
- # This test sometimes fails like this:
- # Traceback (most recent call last):
-
- # File "/home/pqm/bzr-pqm-workdir/home/+trunk/bzrlib/tests/
- # test_lockdir.py", line 247, in test_32_lock_wait_succeed
- # self.assertEqual(1, len(self._logged_reports))
- # AssertionError: not equal:
- # a = 1
- # b = 0
- raise tests.TestSkipped("Test fails intermittently")
- t = self.get_transport()
- lf1 = LockDir(t, 'test_lock')
- lf1.create()
- lf1.attempt_lock()
-
- def wait_and_unlock():
- time.sleep(0.1)
- lf1.unlock()
- unlocker = Thread(target=wait_and_unlock)
- unlocker.start()
- try:
- lf2 = LockDir(t, 'test_lock')
- self.setup_log_reporter(lf2)
- before = time.time()
- # wait and then lock
- lf2.wait_lock(timeout=0.4, poll=0.1)
- after = time.time()
- self.assertTrue(after - before <= 1.0)
- finally:
- unlocker.join()
-
- # There should be only 1 report, even though it should have to
- # wait for a while
- lock_base = lf2.transport.abspath(lf2.path)
- self.assertEqual(1, len(self._logged_reports))
- self.assertEqual('%s %s\n'
- '%s\n%s\n'
- 'Will continue to try until %s\n',
- self._logged_reports[0][0])
- args = self._logged_reports[0][1]
- self.assertEqual('Unable to obtain', args[0])
- self.assertEqual('lock %s' % (lock_base,), args[1])
- self.assertStartsWith(args[2], 'held by ')
- self.assertStartsWith(args[3], 'locked ')
- self.assertEndsWith(args[3], ' ago')
- self.assertContainsRe(args[4], r'\d\d:\d\d:\d\d')
-
- def test_34_lock_write_waits(self):
- """LockDir.lock_write() will wait for the lock."""
- # the test suite sets the default to 0 to make deadlocks fail fast.
- # change it for this test, as we want to try a manual deadlock.
- raise tests.TestSkipped('Timing-sensitive test')
- bzrlib.lockdir._DEFAULT_TIMEOUT_SECONDS = 300
- t = self.get_transport()
- lf1 = LockDir(t, 'test_lock')
- lf1.create()
- lf1.attempt_lock()
-
- def wait_and_unlock():
- time.sleep(0.1)
- lf1.unlock()
- unlocker = Thread(target=wait_and_unlock)
- unlocker.start()
- try:
- lf2 = LockDir(t, 'test_lock')
- self.setup_log_reporter(lf2)
- before = time.time()
- # wait and then lock
- lf2.lock_write()
- after = time.time()
- finally:
- unlocker.join()
-
- # There should be only 1 report, even though it should have to
- # wait for a while
- lock_base = lf2.transport.abspath(lf2.path)
- self.assertEqual(1, len(self._logged_reports))
- self.assertEqual('%s %s\n'
- '%s\n%s\n'
- 'Will continue to try until %s\n',
- self._logged_reports[0][0])
- args = self._logged_reports[0][1]
- self.assertEqual('Unable to obtain', args[0])
- self.assertEqual('lock %s' % (lock_base,), args[1])
- self.assertStartsWith(args[2], 'held by ')
- self.assertStartsWith(args[3], 'locked ')
- self.assertEndsWith(args[3], ' ago')
- self.assertContainsRe(args[4], r'\d\d:\d\d:\d\d')
-
- def test_35_wait_lock_changing(self):
- """LockDir.wait_lock() will report if the lock changes underneath.
-
- This is the stages we want to happen:
-
- 0) Synchronization locks are created and locked.
- 1) Lock1 obtains the lockdir, and releases the 'check' lock.
- 2) Lock2 grabs the 'check' lock, and checks the lockdir.
- It sees the lockdir is already acquired, reports the fact,
- and unsets the 'checked' lock.
- 3) Thread1 blocks on acquiring the 'checked' lock, and then tells
- Lock1 to release and acquire the lockdir. This resets the 'check'
- lock.
- 4) Lock2 acquires the 'check' lock, and checks again. It notices
- that the holder of the lock has changed, and so reports a new
- lock holder.
- 5) Thread1 blocks on the 'checked' lock, this time, it completely
- unlocks the lockdir, allowing Lock2 to acquire the lock.
- """
-
- raise tests.KnownFailure(
- "timing dependency in lock tests (#213182)")
-
- wait_to_check_lock = Lock()
- wait_until_checked_lock = Lock()
-
- wait_to_check_lock.acquire()
- wait_until_checked_lock.acquire()
- note('locked check and checked locks')
-
- class LockDir1(LockDir):
- """Use the synchronization points for the first lock."""
-
- def attempt_lock(self):
- # Once we have acquired the lock, it is okay for
- # the other lock to check it
- try:
- return super(LockDir1, self).attempt_lock()
- finally:
- note('lock1: releasing check lock')
- wait_to_check_lock.release()
-
- class LockDir2(LockDir):
- """Use the synchronization points for the second lock."""
-
- def attempt_lock(self):
- note('lock2: waiting for check lock')
- wait_to_check_lock.acquire()
- note('lock2: acquired check lock')
- try:
- return super(LockDir2, self).attempt_lock()
- finally:
- note('lock2: releasing checked lock')
- wait_until_checked_lock.release()
-
- t = self.get_transport()
- lf1 = LockDir1(t, 'test_lock')
- lf1.create()
-
- lf2 = LockDir2(t, 'test_lock')
- self.setup_log_reporter(lf2)
-
- def wait_and_switch():
- lf1.attempt_lock()
- # Block until lock2 has had a chance to check
- note('lock1: waiting 1 for checked lock')
- wait_until_checked_lock.acquire()
- note('lock1: acquired for checked lock')
- note('lock1: released lockdir')
- lf1.unlock()
- note('lock1: acquiring lockdir')
- # Create a new nonce, so the lock looks different.
- lf1.nonce = osutils.rand_chars(20)
- lf1.lock_write()
- note('lock1: acquired lockdir')
-
- # Block until lock2 has peeked again
- note('lock1: waiting 2 for checked lock')
- wait_until_checked_lock.acquire()
- note('lock1: acquired for checked lock')
- # Now unlock, and let lock 2 grab the lock
- lf1.unlock()
- wait_to_check_lock.release()
-
- unlocker = Thread(target=wait_and_switch)
- unlocker.start()
- try:
- # Wait and play against the other thread
- lf2.wait_lock(timeout=20.0, poll=0.01)
- finally:
- unlocker.join()
- lf2.unlock()
-
- # There should be 2 reports, because the lock changed
- lock_base = lf2.transport.abspath(lf2.path)
- self.assertEqual(2, len(self._logged_reports))
- lock_url = lf2.transport.abspath(lf2.path)
- self.assertEqual('%s %s\n'
- '%s\n%s\n'
- 'Will continue to try until %s, unless '
- 'you press Ctrl-C.\n'
- 'See "bzr help break-lock" for more.',
- self._logged_reports[0][0])
- args = self._logged_reports[0][1]
- self.assertEqual('Unable to obtain', args[0])
- self.assertEqual('lock %s' % (lock_base,), args[1])
- self.assertStartsWith(args[2], 'held by ')
- self.assertStartsWith(args[3], 'locked ')
- self.assertEndsWith(args[3], ' ago')
- self.assertContainsRe(args[4], r'\d\d:\d\d:\d\d')
-
- self.assertEqual('%s %s\n'
- '%s\n%s\n'
- 'Will continue to try until %s, unless '
- 'you press Ctrl-C.\n'
- 'See "bzr help break-lock" for more.',
- self._logged_reports[1][0])
- args = self._logged_reports[1][1]
- self.assertEqual('Lock owner changed for', args[0])
- self.assertEqual('lock %s' % (lock_base,), args[1])
- self.assertStartsWith(args[2], 'held by ')
- self.assertStartsWith(args[3], 'locked ')
- self.assertEndsWith(args[3], ' ago')
- self.assertContainsRe(args[4], r'\d\d:\d\d:\d\d')
-
def test_40_confirm_easy(self):
"""Confirm a lock that's already held"""
t = self.get_transport()
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2011-02-24 16:45:27 +0000
+++ b/bzrlib/tests/test_selftest.py 2011-03-29 04:30:03 +0000
@@ -754,41 +754,6 @@
# want to assume that thats *all* that would happen.
self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', lambda: None)
- def test_assigned_benchmark_file_stores_date(self):
- self._patch_get_bzr_source_tree()
- output = StringIO()
- result = bzrlib.tests.TextTestResult(self._log_file,
- descriptions=0,
- verbosity=1,
- bench_history=output
- )
- output_string = output.getvalue()
- # if you are wondering about the regexp please read the comment in
- # test_bench_history (bzrlib.tests.test_selftest.TestRunner)
- # XXX: what comment? -- Andrew Bennetts
- self.assertContainsRe(output_string, "--date [0-9.]+")
-
- def test_benchhistory_records_test_times(self):
- self._patch_get_bzr_source_tree()
- result_stream = StringIO()
- result = bzrlib.tests.TextTestResult(
- self._log_file,
- descriptions=0,
- verbosity=1,
- bench_history=result_stream
- )
-
- # we want profile a call and check that its test duration is recorded
- # make a new test instance that when run will generate a benchmark
- example_test_case = TestTestResult("_time_hello_world_encoding")
- # execute the test, which should succeed and record times
- example_test_case.run(result)
- lines = result_stream.getvalue().splitlines()
- self.assertEqual(2, len(lines))
- self.assertContainsRe(lines[1],
- " *[0-9]+ms bzrlib.tests.test_selftest.TestTestResult"
- "._time_hello_world_encoding")
-
def _time_hello_world_encoding(self):
"""Profile two sleep calls
@@ -1222,20 +1187,6 @@
return None
self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', new_get)
- def test_bench_history(self):
- # tests that the running the benchmark passes bench_history into
- # the test result object. We can tell that happens if
- # _get_bzr_source_tree is called.
- self._patch_get_bzr_source_tree()
- test = TestRunner('dummy_test')
- output = StringIO()
- runner = tests.TextTestRunner(stream=self._log_file,
- bench_history=output)
- result = self.run_test_runner(runner, test)
- output_string = output.getvalue()
- self.assertContainsRe(output_string, "--date [0-9.]+")
- self.assertLength(1, self._get_source_tree_calls)
-
def test_verbose_test_count(self):
"""A verbose test run reports the right test count at the start"""
suite = TestUtil.TestSuite([
More information about the bazaar-commits
mailing list