/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lockable_files.py

Add Repository.{dont_,}leave_lock_in_place.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        def resetTimeout():
44
44
            lockdir._DEFAULT_TIMEOUT_SECONDS = orig_timeout
45
45
        self.addCleanup(resetTimeout)
46
 
        lockdir._DEFAULT_TIMEOUT_SECONDS = 3
 
46
        lockdir._DEFAULT_TIMEOUT_SECONDS = 0
47
47
 
48
48
    def test_read_write(self):
49
49
        self.assertRaises(NoSuchFile, self.lockable.get, 'foo')
240
240
        new_lockable.lock_write()
241
241
        new_lockable.unlock()
242
242
 
243
 
 
244
 
 
 
243
    def test_leave_in_place(self):
 
244
        token = self.lockable.lock_write()
 
245
        try:
 
246
            if token is None:
 
247
                # This test does not apply, because this lockable refuses
 
248
                # tokens.
 
249
                return
 
250
            self.lockable.leave_in_place()
 
251
        finally:
 
252
            self.lockable.unlock()
 
253
        # At this point, the lock is still in place on disk
 
254
        self.assertRaises(errors.LockContention, self.lockable.lock_write)
 
255
        # But should be relockable with a token.
 
256
        self.lockable.lock_write(token=token)
 
257
        self.lockable.unlock()
 
258
 
 
259
    def test_dont_leave_in_place(self):
 
260
        token = self.lockable.lock_write()
 
261
        try:
 
262
            if token is None:
 
263
                # This test does not apply, because this lockable refuses
 
264
                # tokens.
 
265
                return
 
266
            self.lockable.leave_in_place()
 
267
        finally:
 
268
            self.lockable.unlock()
 
269
        # At this point, the lock is still in place on disk.
 
270
        # Acquire the existing lock with the token, and ask that it is removed
 
271
        # when this object unlocks, and unlock to trigger that removal.
 
272
        new_lockable = self.get_lockable()
 
273
        new_lockable.lock_write(token=token)
 
274
        new_lockable.dont_leave_in_place()
 
275
        new_lockable.unlock()
 
276
        # At this point, the lock is no longer on disk, so we can lock it.
 
277
        third_lockable = self.get_lockable()
 
278
        third_lockable.lock_write()
 
279
        third_lockable.unlock()
245
280
 
246
281
 
247
282
# This method of adapting tests to parameters is different to 
305
340
    """LockableFile tests run with RemoteLockDir on a branch."""
306
341
 
307
342
    def setUp(self):
308
 
        super(TestLockableFiles_RemoteLockDir, self).setUp()
 
343
        TestCaseWithSmartMedium.setUp(self)
 
344
        _TestLockableFiles_mixin.setUp(self)
309
345
        # can only get a RemoteLockDir with some RemoteObject...
310
346
        # use a branch as thats what we want. These mixin tests test the end
311
347
        # to end behaviour, so stubbing out the backend and simulating would
319
355
        # getting a new lockable involves opening a new instance of the branch
320
356
        branch = bzrlib.branch.Branch.open(self.get_url('foo'))
321
357
        return branch.control_files
 
358
 
 
359
    def test_lock_write_returns_None_refuses_token(self):
 
360
        # this test is not relevant for RemoteBranchLockableFiles as remote
 
361
        # locks are done directly from the remote branch object.
 
362
        return None
 
363
 
 
364
    def test_lock_write_raises_on_token_mismatch(self):
 
365
        # See test_lock_write_returns_None_refuses_token.
 
366
        return None
 
367
 
 
368
    def test_lock_write_with_matching_token(self):
 
369
        # See test_lock_write_returns_None_refuses_token.
 
370
        return None
 
371
 
 
372
    def test_unlock_after_lock_write_with_token(self):
 
373
        # See test_lock_write_returns_None_refuses_token.
 
374
        return None
 
375
 
 
376
    def test_lock_write_with_token_fails_when_unlocked(self):
 
377
        # See test_lock_write_returns_None_refuses_token.
 
378
        return None
 
379
 
 
380
    def test_lock_write_reenter_with_token(self):
 
381
        # See test_lock_write_returns_None_refuses_token.
 
382
        return None
 
383
 
 
384
    def test_leave_in_place(self):
 
385
        # See test_lock_write_returns_None_refuses_token.
 
386
        return None
 
387
 
 
388
    def test_dont_leave_in_place(self):
 
389
        # See test_lock_write_returns_None_refuses_token.
 
390
        return None