/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/tests/test_lockdir.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import os
20
20
import time
21
21
 
22
 
import bzrlib
23
 
from bzrlib import (
 
22
import breezy
 
23
from .. import (
24
24
    config,
25
25
    errors,
26
26
    lock,
29
29
    tests,
30
30
    transport,
31
31
    )
32
 
from bzrlib.errors import (
 
32
from ..errors import (
33
33
    LockBreakMismatch,
34
34
    LockBroken,
35
35
    LockContention,
36
36
    LockFailed,
37
37
    LockNotHeld,
38
38
    )
39
 
from bzrlib.lockdir import (
 
39
from ..lockdir import (
40
40
    LockDir,
41
41
    LockHeldInfo,
42
42
    )
43
 
from bzrlib.tests import (
 
43
from . import (
44
44
    features,
45
45
    TestCase,
46
46
    TestCaseInTempDir,
132
132
            # a single process are not detected
133
133
            lf2.attempt_lock()
134
134
            self.fail('Failed to detect lock collision')
135
 
        except LockContention, e:
 
135
        except LockContention as e:
136
136
            self.assertEqual(e.lock, lf2)
137
137
            self.assertContainsRe(str(e),
138
138
                    r'^Could not acquire.*test_lock.*$')
148
148
        # lock is held, should get some info on it
149
149
        info1 = lf1.peek()
150
150
        self.assertEqual(set(info1.info_dict.keys()),
151
 
            set(['user', 'nonce', 'hostname', 'pid', 'start_time']))
 
151
            {'user', 'nonce', 'hostname', 'pid', 'start_time'})
152
152
        # should get the same info if we look at it through a different
153
153
        # instance
154
154
        info2 = LockDir(t, 'test_lock').peek()
199
199
            r' \(process #\d+\), acquired .* ago\.\n'
200
200
            r'Will continue to try until \d{2}:\d{2}:\d{2}, unless '
201
201
            r'you press Ctrl-C.\n'
202
 
            r'See "bzr help break-lock" for more.')
 
202
            r'See "brz help break-lock" for more.')
203
203
 
204
204
    def test_31_lock_wait_easy(self):
205
205
        """Succeed when waiting on a lock with no contention.
330
330
        ld1.lock_write()
331
331
        # do this without IO redirection to ensure it doesn't prompt.
332
332
        self.assertRaises(AssertionError, ld1.break_lock)
333
 
        orig_factory = bzrlib.ui.ui_factory
334
 
        bzrlib.ui.ui_factory = bzrlib.ui.CannedInputUIFactory([True])
 
333
        orig_factory = breezy.ui.ui_factory
 
334
        breezy.ui.ui_factory = breezy.ui.CannedInputUIFactory([True])
335
335
        try:
336
336
            ld2.break_lock()
337
337
            self.assertRaises(LockBroken, ld1.unlock)
338
338
        finally:
339
 
            bzrlib.ui.ui_factory = orig_factory
 
339
            breezy.ui.ui_factory = orig_factory
340
340
 
341
341
    def test_break_lock_corrupt_info(self):
342
342
        """break_lock works even if the info file is corrupt (and tells the UI
348
348
        ld.lock_write()
349
349
        ld.transport.put_bytes_non_atomic('test_lock/held/info', '\0')
350
350
 
351
 
        class LoggingUIFactory(bzrlib.ui.SilentUIFactory):
 
351
        class LoggingUIFactory(breezy.ui.SilentUIFactory):
352
352
            def __init__(self):
353
353
                self.prompts = []
354
354
 
357
357
                return True
358
358
 
359
359
        ui = LoggingUIFactory()
360
 
        self.overrideAttr(bzrlib.ui, 'ui_factory', ui)
 
360
        self.overrideAttr(breezy.ui, 'ui_factory', ui)
361
361
        ld2.break_lock()
362
362
        self.assertLength(1, ui.prompts)
363
363
        self.assertEqual('boolean', ui.prompts[0][0])
374
374
        ld.lock_write()
375
375
        ld.transport.delete('test_lock/held/info')
376
376
 
377
 
        class LoggingUIFactory(bzrlib.ui.SilentUIFactory):
 
377
        class LoggingUIFactory(breezy.ui.SilentUIFactory):
378
378
            def __init__(self):
379
379
                self.prompts = []
380
380
 
383
383
                return True
384
384
 
385
385
        ui = LoggingUIFactory()
386
 
        orig_factory = bzrlib.ui.ui_factory
387
 
        bzrlib.ui.ui_factory = ui
 
386
        orig_factory = breezy.ui.ui_factory
 
387
        breezy.ui.ui_factory = ui
388
388
        try:
389
389
            ld2.break_lock()
390
390
            self.assertRaises(LockBroken, ld.unlock)
391
391
            self.assertLength(0, ui.prompts)
392
392
        finally:
393
 
            bzrlib.ui.ui_factory = orig_factory
 
393
            breezy.ui.ui_factory = orig_factory
394
394
        # Suppress warnings due to ld not being unlocked
395
395
        # XXX: if lock_broken hook was invoked in this case, this hack would
396
396
        # not be necessary.  - Andrew Bennetts, 2010-09-06.