~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lock.py

(broken) Change fcntl locks to be properly exclusive within the same process.
This exposes the location where we are opening the same WorkingTree in both read and write
mode, which breaks several tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
        # Taking out a lock on a locked file should raise LockContention
100
100
        self.assertRaises(errors.LockContention, lock.WriteLock, 'a-file')
101
101
 
102
 
    def _disabled_test_read_then_write_excludes(self):
 
102
    def test_read_then_write_excludes(self):
103
103
        """If a file is read-locked, taking out a write lock should fail."""
104
104
        a_lock = lock.ReadLock('a-file')
105
105
        self.addCleanup(a_lock.unlock)
106
106
        # Taking out a lock on a locked file should raise LockContention
107
107
        self.assertRaises(errors.LockContention, lock.WriteLock, 'a-file')
108
108
 
109
 
    def _disabled_test_write_then_read_excludes(self):
 
109
    def test_read_unlock_write(self):
 
110
        """Make sure that unlocking allows us to lock write"""
 
111
        a_lock = lock.ReadLock('a-file')
 
112
        a_lock.unlock()
 
113
        a_lock = lock.WriteLock('a-file')
 
114
        a_lock.unlock()
 
115
 
 
116
    def test_write_then_read_excludes(self):
110
117
        """If a file is write-locked, taking out a read lock should fail.
111
118
 
112
119
        The file is exclusively owned by the write lock, so we shouldn't be
116
123
        self.addCleanup(a_lock.unlock)
117
124
        # Taking out a lock on a locked file should raise LockContention
118
125
        self.assertRaises(errors.LockContention, lock.ReadLock, 'a-file')
 
126
 
 
127
    def test_write_unlock_read(self):
 
128
        """If we have removed the write lock, we can grab a read lock."""
 
129
        a_lock = lock.WriteLock('a-file')
 
130
        a_lock.unlock()
 
131
        a_lock = lock.ReadLock('a-file')
 
132
        a_lock.unlock()
 
133
 
 
134
    def test_multiple_read_unlock_write(self):
 
135
        """We can only grab a write lock if all read locks are done."""
 
136
        a_lock = b_lock = c_lock = None
 
137
        try:
 
138
            a_lock = lock.ReadLock('a-file')
 
139
            b_lock = lock.ReadLock('a-file')
 
140
            self.assertRaises(errors.LockContention, lock.WriteLock, 'a-file')
 
141
            a_lock.unlock()
 
142
            a_lock = None
 
143
            self.assertRaises(errors.LockContention, lock.WriteLock, 'a-file')
 
144
            b_lock.unlock()
 
145
            b_lock = None
 
146
            c_lock = lock.WriteLock('a-file')
 
147
            c_lock.unlock()
 
148
            c_lock = None
 
149
        finally:
 
150
            # Cleanup as needed
 
151
            if a_lock is not None:
 
152
                a_lock.unlock()
 
153
            if b_lock is not None:
 
154
                b_lock.unlock()
 
155
            if c_lock is not None:
 
156
                c_lock.unlock()