@@ -18,16 +18,19 @@ def testALockWait(self):
1818 state = [False , False , False ]
1919 alt = new ()
2020 def concurrent_lock ():
21- pass
22- with alock .ExclusiveLock (alt , (1 ,1 )):
23- with alock .ExclusiveLock (alt , (0 ,0 )):
24- # start it
25- state [0 ] = True
26- while not state [1 ]:
27- pass
21+ try :
22+ with alock .ExclusiveLock (alt , (1 ,1 )):
23+ with alock .ExclusiveLock (alt , (0 ,0 )):
24+ # start it
25+ state [0 ] = True
26+ while not state [1 ]:
27+ pass
28+ time .sleep (0.01 )
29+ while not state [2 ]:
2830 time .sleep (0.01 )
29- while not state [2 ]:
30- time .sleep (0.01 )
31+ except Exception :
32+ # Avoid dead lock in cases where advisory is not available.
33+ state [0 ] = state [1 ] = state [2 ] = True
3134 t = threading .Thread (target = concurrent_lock )
3235 t .start ()
3336 while not state [0 ]:
@@ -49,7 +52,7 @@ def testALockNoWait(self):
4952 with alock .ExclusiveLock (db , (0 ,0 )):
5053 l = alock .ExclusiveLock (alt , (0 ,0 ))
5154 # should fail to acquire
52- self .failUnlessEqual (l .acquire (False ), False )
55+ self .failUnlessEqual (l .acquire (blocking = False ), False )
5356 # no alocks should exist now
5457 self .failUnlessEqual (ad (), 0 )
5558
@@ -75,17 +78,17 @@ def testALock(self):
7578 self .failUnless (ad () > 0 )
7679 for x in lockids :
7780 xl = alock .ExclusiveLock (alt , x )
78- self .failUnlessEqual (xl .acquire (False ), False )
81+ self .failUnlessEqual (xl .acquire (blocking = False ), False )
7982 # main has exclusives on these, so this should fail.
8083 xl = alock .ShareLock (alt , * lockids )
81- self .failUnlessEqual (xl .acquire (False ), False )
84+ self .failUnlessEqual (xl .acquire (blocking = False ), False )
8285 for x in lockids :
8386 # sal1 still holds
8487 xl = alock .ExclusiveLock (alt , x )
85- self .failUnlessEqual (xl .acquire (False ), False )
88+ self .failUnlessEqual (xl .acquire (blocking = False ), False )
8689 # sal1 still holds, but we want a share lock too.
8790 xl = alock .ShareLock (alt , x )
88- self .failUnlessEqual (xl .acquire (False ), True )
91+ self .failUnlessEqual (xl .acquire (blocking = False ), True )
8992 xl .release ()
9093 # no alocks should exist now
9194 self .failUnlessEqual (ad (), 0 )
@@ -101,7 +104,7 @@ def testPartialALock(self):
101104 with alock .ExclusiveLock (db , held ):
102105 l = alock .ExclusiveLock (alt , * wanted )
103106 # should fail to acquire, db has held
104- self .failUnlessEqual (l .acquire (False ), False )
107+ self .failUnlessEqual (l .acquire (blocking = False ), False )
105108 # No alocks should exist now.
106109 # This *MUST* occur prior to alt being closed.
107110 # Otherwise, we won't be testing for the recovery
0 commit comments