~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lockable_files.py

Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
smart protocol as appropriate, so that locking operations on RemoteRepositories
work correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
class _TestLockableFiles_mixin(object):
38
38
 
39
39
    def setUp(self):
40
 
        # Reduce the default timeout, so that if tests fail, they will do so
41
 
        # reasonably quickly.
42
 
        orig_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
43
 
        def resetTimeout():
44
 
            lockdir._DEFAULT_TIMEOUT_SECONDS = orig_timeout
45
 
        self.addCleanup(resetTimeout)
46
 
        lockdir._DEFAULT_TIMEOUT_SECONDS = 0
 
40
        self.reduceLockdirTimeout()
47
41
 
48
42
    def test_read_write(self):
49
43
        self.assertRaises(NoSuchFile, self.lockable.get, 'foo')
145
139
        finally:
146
140
            self.lockable.unlock()
147
141
 
 
142
    def test_lock_write_returns_token_when_given_token(self):
 
143
        token = self.lockable.lock_write()
 
144
        try:
 
145
            if token is None:
 
146
                # This test does not apply, because this lockable refuses
 
147
                # tokens.
 
148
                return
 
149
            new_lockable = self.get_lockable()
 
150
            token_from_new_lockable = new_lockable.lock_write(token=token)
 
151
            try:
 
152
                self.assertEqual(token, token_from_new_lockable)
 
153
            finally:
 
154
                new_lockable.unlock()
 
155
        finally:
 
156
            self.lockable.unlock()
 
157
 
148
158
    def test_lock_write_raises_on_token_mismatch(self):
149
159
        token = self.lockable.lock_write()
150
160
        try:
388
398
    def test_dont_leave_in_place(self):
389
399
        # See test_lock_write_returns_None_refuses_token.
390
400
        return None
 
401
 
 
402
    def test_lock_write_returns_token_when_given_token(self):
 
403
        # See test_lock_write_returns_None_refuses_token.
 
404
        return None