~abentley/bzr/cp-4470

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lockdir.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2009-03-16 11:57:58 UTC
  • mfrom: (3995.3.115 1.13-for-rf)
  • Revision ID: launchpad@pqm.canonical.com-20090316115758-hkrp6igwb4vyt94l
[rs=mwhudson] bzr 1.13

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
        lf1.attempt_lock()
127
127
        lf2 = LockDir(t, 'test_lock')
128
128
        try:
129
 
            # locking is between LockDir instances; aliases within 
 
129
            # locking is between LockDir instances; aliases within
130
130
            # a single process are not detected
131
131
            lf2.attempt_lock()
132
132
            self.fail('Failed to detect lock collision')
167
167
 
168
168
    def test_30_lock_wait_fail(self):
169
169
        """Wait on a lock, then fail
170
 
        
 
170
 
171
171
        We ask to wait up to 400ms; this should fail within at most one
172
172
        second.  (Longer times are more realistic but we don't want the test
173
173
        suite to take too long, and this should do for now.)
185
185
            after = time.time()
186
186
            # it should only take about 0.4 seconds, but we allow more time in
187
187
            # case the machine is heavily loaded
188
 
            self.assertTrue(after - before <= 8.0, 
 
188
            self.assertTrue(after - before <= 8.0,
189
189
                    "took %f seconds to detect lock contention" % (after - before))
190
190
        finally:
191
191
            lf1.unlock()
226
226
    def test_32_lock_wait_succeed(self):
227
227
        """Succeed when trying to acquire a lock that gets released
228
228
 
229
 
        One thread holds on a lock and then releases it; another 
 
229
        One thread holds on a lock and then releases it; another
230
230
        tries to lock it.
231
231
        """
232
232
        # This test sometimes fails like this:
277
277
        self.assertContainsRe(args[4], r'\d\d:\d\d:\d\d')
278
278
 
279
279
    def test_34_lock_write_waits(self):
280
 
        """LockDir.lock_write() will wait for the lock.""" 
 
280
        """LockDir.lock_write() will wait for the lock."""
281
281
        # the test suite sets the default to 0 to make deadlocks fail fast.
282
282
        # change it for this test, as we want to try a manual deadlock.
283
283
        raise tests.TestSkipped('Timing-sensitive test')
320
320
 
321
321
    def test_35_wait_lock_changing(self):
322
322
        """LockDir.wait_lock() will report if the lock changes underneath.
323
 
        
 
323
 
324
324
        This is the stages we want to happen:
325
325
 
326
326
        0) Synchronization locks are created and locked.
327
327
        1) Lock1 obtains the lockdir, and releases the 'check' lock.
328
328
        2) Lock2 grabs the 'check' lock, and checks the lockdir.
329
 
           It sees the lockdir is already acquired, reports the fact, 
 
329
           It sees the lockdir is already acquired, reports the fact,
330
330
           and unsets the 'checked' lock.
331
331
        3) Thread1 blocks on acquiring the 'checked' lock, and then tells
332
332
           Lock1 to release and acquire the lockdir. This resets the 'check'
333
333
           lock.
334
334
        4) Lock2 acquires the 'check' lock, and checks again. It notices
335
 
           that the holder of the lock has changed, and so reports a new 
 
335
           that the holder of the lock has changed, and so reports a new
336
336
           lock holder.
337
337
        5) Thread1 blocks on the 'checked' lock, this time, it completely
338
338
           unlocks the lockdir, allowing Lock2 to acquire the lock.
532
532
        """Check the on-disk representation of LockDirs is as expected.
533
533
 
534
534
        There should always be a top-level directory named by the lock.
535
 
        When the lock is held, there should be a lockname/held directory 
 
535
        When the lock is held, there should be a lockname/held directory
536
536
        containing an info file.
537
537
        """
538
538
        t = self.get_transport()