~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lockdir.py

  • Committer: Robert Collins
  • Date: 2006-05-05 04:43:35 UTC
  • mfrom: (1687.1.17 break-lock)
  • mto: This revision was merged to the branch mainline in revision 1701.
  • Revision ID: robertc@robertcollins.net-20060505044335-0e785bae0df1047e
Merge break-lock command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for LockDir"""
18
18
 
 
19
from cStringIO import StringIO
19
20
from threading import Thread
20
21
import time
21
22
 
 
23
import bzrlib
22
24
from bzrlib.errors import (
23
25
        LockBreakMismatch,
24
26
        LockContention, LockError, UnlockableTransport,
56
58
        lf = LockDir(self.get_transport(), 'test_lock')
57
59
        self.assertEqual(lf.peek(), None)
58
60
 
 
61
    def get_lock(self):
 
62
        return LockDir(self.get_transport(), 'test_lock')
 
63
 
 
64
    def test_unlock_after_break_raises(self):
 
65
        ld = self.get_lock()
 
66
        ld2 = self.get_lock()
 
67
        ld.create()
 
68
        ld.attempt_lock()
 
69
        ld2.force_break(ld2.peek())
 
70
        self.assertRaises(LockBroken, ld.unlock)
 
71
 
59
72
    def test_03_readonly_peek(self):
60
73
        lf = LockDir(self.get_readonly_transport(), 'test_lock')
61
74
        self.assertEqual(lf.peek(), None)
318
331
        self.assertTrue(t.has('test_lock/held/info'))
319
332
        lf1.unlock()
320
333
        self.assertFalse(t.has('test_lock/held/info'))
 
334
 
 
335
    def test_break_lock(self):
 
336
        # the ui based break_lock routine should Just Work (tm)
 
337
        ld1 = self.get_lock()
 
338
        ld2 = self.get_lock()
 
339
        ld1.create()
 
340
        ld1.lock_write()
 
341
        # do this without IO redirection to ensure it doesn't prompt.
 
342
        self.assertRaises(AssertionError, ld1.break_lock)
 
343
        orig_factory = bzrlib.ui.ui_factory
 
344
        # silent ui - no need for stdout
 
345
        bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
 
346
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
 
347
        try:
 
348
            ld2.break_lock()
 
349
            self.assertRaises(LockBroken, ld1.unlock)
 
350
        finally:
 
351
            bzrlib.ui.ui_factory = orig_factory