Revision 13caa61d test/hs/Test/Ganeti/Locking/Allocation.hs
b/test/hs/Test/Ganeti/Locking/Allocation.hs | ||
---|---|---|
271 | 271 |
. flip all oldLocks $ \lock -> |
272 | 272 |
M.lookup lock newOwned >= M.lookup lock oldOwned |
273 | 273 |
|
274 |
-- | Verify the result list of the opportunistic union: if a lock is not in |
|
275 |
-- the result that, than its state has not changed, and if it is, it is as |
|
276 |
-- requested. The latter property is tested in that liberal way, so that we |
|
277 |
-- really can take arbitrary requests, including those that require both, shared |
|
278 |
-- and exlusive state for the same lock. |
|
279 |
prop_OpportunisticAnswer :: Property |
|
280 |
prop_OpportunisticAnswer = |
|
281 |
forAll (arbitrary :: Gen (LockAllocation TestLock TestOwner)) $ \state -> |
|
282 |
forAll (arbitrary :: Gen TestOwner) $ \a -> |
|
283 |
forAll ((choose (1,3) >>= vector) :: Gen [(TestLock, OwnerState)]) $ \req -> |
|
284 |
let (state', result) = opportunisticLockUnion a req state |
|
285 |
oldOwned = listLocks a state |
|
286 |
newOwned = listLocks a state' |
|
287 |
involvedLocks = M.keys oldOwned ++ map fst req |
|
288 |
in conjoin [ printTestCase ("Locks not in the answer set " ++ show result |
|
289 |
++ " may not be changed, but found " |
|
290 |
++ show state') |
|
291 |
. flip all involvedLocks $ \lock -> |
|
292 |
(lock `S.member` result) |
|
293 |
|| (M.lookup lock oldOwned == M.lookup lock newOwned) |
|
294 |
, printTestCase ("Locks not in the answer set " ++ show result |
|
295 |
++ " must be as requested, but found " |
|
296 |
++ show state') |
|
297 |
. flip all involvedLocks $ \lock -> |
|
298 |
(lock `S.notMember` result) |
|
299 |
|| maybe False (flip elem req . (,) lock) |
|
300 |
(M.lookup lock newOwned) |
|
301 |
] |
|
302 |
|
|
303 |
|
|
304 |
|
|
274 | 305 |
testSuite "Locking/Allocation" |
275 | 306 |
[ 'prop_LocksDisjoint |
276 | 307 |
, 'prop_LockImplicationX |
... | ... | |
281 | 312 |
, 'prop_BlockSufficient |
282 | 313 |
, 'prop_BlockNecessary |
283 | 314 |
, 'prop_OpportunisticMonotone |
315 |
, 'prop_OpportunisticAnswer |
|
284 | 316 |
] |
Also available in: Unified diff