~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_counted_lock.py

  • Committer: Martin Pool
  • Date: 2008-05-12 06:16:05 UTC
  • mto: (3468.3.1 controlfiles)
  • mto: This revision was merged to the branch mainline in revision 4202.
  • Revision ID: mbp@sourcefrog.net-20080512061605-ceef1h4fspghl2k2
CountedLock should manage lock tokens

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        self._assert_not_locked()
44
44
        self._lock_mode = 'w'
45
45
        self._calls.append('lock_write')
 
46
        return 'token'
46
47
 
47
48
    def unlock(self):
48
49
        self._assert_locked()
89
90
        real_lock.unlock()
90
91
        self.assertFalse(real_lock.is_locked())
91
92
        # lock write and unlock
92
 
        real_lock.lock_write()
 
93
        result = real_lock.lock_write()
 
94
        self.assertEqual('token', result)
93
95
        self.assertTrue(real_lock.is_locked())
94
96
        real_lock.unlock()
95
97
        self.assertFalse(real_lock.is_locked())
110
112
 
111
113
class TestCountedLock(TestCase):
112
114
 
113
 
    def test_lock_unlock(self):
 
115
    def test_read_lock(self):
114
116
        # Lock and unlock a counted lock
115
117
        real_lock = DummyLock()
116
118
        l = CountedLock(real_lock)
138
140
        l = CountedLock(real_lock)
139
141
        l.lock_write()
140
142
        l.lock_read()
141
 
        l.lock_write()
 
143
        self.assertEquals('token', l.lock_write())
142
144
        l.unlock()
143
145
        l.unlock()
144
146
        l.unlock()
159
161
            ['lock_read', 'unlock'],
160
162
            real_lock._calls)
161
163
 
 
164
    def test_write_lock_reentrant(self):
 
165
        real_lock = DummyLock()
 
166
        l = CountedLock(real_lock)
 
167
        self.assertEqual('token', l.lock_write())
 
168
        self.assertEqual('token', l.lock_write())
 
169
        l.unlock()
 
170
        l.unlock()
 
171
 
162
172
    def test_break_lock(self):
163
173
        real_lock = DummyLock()
164
174
        l = CountedLock(real_lock)