Revision 1d49428b

b/test/hs/Test/Ganeti/Locking/Allocation.hs
37 37
import Test.Ganeti.TestCommon
38 38
import Test.Ganeti.TestHelper
39 39

  
40
import Ganeti.BasicTypes
40 41
import Ganeti.Locking.Allocation
41 42

  
42 43
{-
......
112 113
  let (state', _) = updateLocks b request state
113 114
  in (listLocks a state ==? listLocks a state')
114 115

  
116
-- | Verify that a given request is statisfied in list of owned locks
117
requestSucceeded :: Ord a => M.Map a  OwnerState -> LockRequest a -> Bool
118
requestSucceeded owned (LockRequest lock status) = M.lookup lock owned == status
119

  
120
-- | Verify that lock updates are atomic, i.e., either we get all the required
121
-- locks, or the state is completely unchanged.
122
prop_LockupdateAtomic :: Property
123
prop_LockupdateAtomic =
124
  forAll (arbitrary :: Gen (LockAllocation TestLock TestOwner)) $ \state ->
125
  forAll (arbitrary :: Gen TestOwner) $ \a ->
126
  forAll (arbitrary :: Gen [LockRequest TestLock]) $ \request ->
127
  let (state', result) = updateLocks a request state
128
  in if result == Ok (S.empty)
129
       then printTestCase
130
            ("Update suceeded, but in final state " ++ show state'
131
              ++ "not all locks are as requested")
132
            $ let owned = listLocks a state'
133
              in all (requestSucceeded owned) request
134
       else printTestCase
135
            ("Update failed, but state changed to " ++ show state')
136
            (state == state')
137

  
115 138
testSuite "Locking/Allocation"
116 139
 [ 'prop_LocksDisjoint
117 140
 , 'prop_LocksStable
141
 , 'prop_LockupdateAtomic
118 142
 ]

Also available in: Unified diff