~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lockdir.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for LockDir"""
18
18
 
19
19
from cStringIO import StringIO
 
20
import os
20
21
from threading import Thread, Lock
21
22
import time
22
23
 
23
24
import bzrlib
24
25
from bzrlib import (
 
26
    config,
 
27
    errors,
25
28
    osutils,
 
29
    tests,
26
30
    )
27
31
from bzrlib.errors import (
28
32
        LockBreakMismatch,
29
33
        LockContention, LockError, UnlockableTransport,
30
34
        LockNotHeld, LockBroken
31
35
        )
32
 
from bzrlib.lockdir import LockDir, _DEFAULT_TIMEOUT_SECONDS
 
36
from bzrlib.lockdir import LockDir
33
37
from bzrlib.tests import TestCaseWithTransport
34
38
from bzrlib.trace import note
35
39
 
216
220
        One thread holds on a lock and then releases it; another 
217
221
        tries to lock it.
218
222
        """
 
223
        # This test sometimes fails like this:
 
224
        # Traceback (most recent call last):
 
225
 
 
226
        #   File "/home/pqm/bzr-pqm-workdir/home/+trunk/bzrlib/tests/
 
227
        # test_lockdir.py", line 247, in test_32_lock_wait_succeed
 
228
        #     self.assertEqual(1, len(self._logged_reports))
 
229
        # AssertionError: not equal:
 
230
        # a = 1
 
231
        # b = 0
 
232
        raise tests.TestSkipped("Test fails intermittently")
219
233
        t = self.get_transport()
220
234
        lf1 = LockDir(t, 'test_lock')
221
235
        lf1.create()
282
296
 
283
297
    def test_34_lock_write_waits(self):
284
298
        """LockDir.lock_write() will wait for the lock.""" 
 
299
        # the test suite sets the default to 0 to make deadlocks fail fast.
 
300
        # change it for this test, as we want to try a manual deadlock.
 
301
        bzrlib.lockdir._DEFAULT_TIMEOUT_SECONDS = 300
285
302
        t = self.get_transport()
286
303
        lf1 = LockDir(t, 'test_lock')
287
304
        lf1.create()
590
607
        self.assertContainsRe(info_list[1],
591
608
                              r'^held by .* on host .* \[process #\d*\]$')
592
609
        self.assertContainsRe(info_list[2], r'locked \d+ seconds? ago$')
 
610
 
 
611
    def test_lock_without_email(self):
 
612
        global_config = config.GlobalConfig()
 
613
        # Intentionally has no email address
 
614
        global_config.set_user_option('email', 'User Identity')
 
615
        ld1 = self.get_lock()
 
616
        ld1.create()
 
617
        ld1.lock_write()
 
618
        ld1.unlock()
 
619
 
 
620
    def test_lock_permission(self):
 
621
        if not osutils.supports_posix_readonly():
 
622
            raise tests.TestSkipped('Cannot induce a permission failure')
 
623
        ld1 = self.get_lock()
 
624
        lock_path = ld1.transport.local_abspath('test_lock')
 
625
        os.mkdir(lock_path)
 
626
        osutils.make_readonly(lock_path)
 
627
        self.assertRaises(errors.PermissionDenied, ld1.attempt_lock)