Skip to content

Commit 4e62a8a

Browse files
committed
QLS: turn swallowed error assertions into pure test failures.
We replace the assertions by pure responses that are checked against the model.
1 parent 037d203 commit 4e62a8a

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

test/Test/Database/LSMTree/StateMachine.hs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,10 @@ instance Eq (Obs h a) where
10381038
-- See also 'Model.runModelMWithInjectedErrors' and
10391039
-- 'runRealWithInjectedErrors'.
10401040
(OEither (Left (OId lhs)), OEither (Left (OId rhs)))
1041-
| Just (_ :: Model.Err) <- cast lhs
1041+
| Just (e :: Model.Err) <- cast lhs
1042+
, case e of
1043+
Model.ErrOther _ -> False
1044+
_ -> True
10421045
, Just Model.DefaultErrDiskFault <- cast rhs
10431046
-> True
10441047

@@ -1707,20 +1710,37 @@ runRealWithInjectedErrors s env merrs k rollback =
17071710
atomically $ writeTVar logVar emptyLog
17081711
eith <- catchErr handlers $ FSSim.withErrors errsVar errs k
17091712
errsLog <- readTVarIO logVar
1710-
-- TODO: turn assertions on @errsLog@ into 'Property's
17111713
case eith of
1712-
Left (Model.ErrDiskFault _) -> do
1714+
Left e@(Model.ErrDiskFault _) -> do
17131715
modifyMutVar faultsVar (InjectFaultInducedError s :)
1714-
assert (countNoisyErrors errsLog >= 1) $ pure ()
1715-
pure eith
1716-
Left _ -> do
1717-
assert (countNoisyErrors errsLog == 0) $ pure ()
1718-
pure eith
1716+
if countNoisyErrors errsLog == 0 then
1717+
pure $ Left $ Model.ErrOther $
1718+
-- If we injected 0 disk faults, but we still found an
1719+
-- ErrDiskFault, then there is a bug in our code. ErrDiskFaults
1720+
-- should not occur on the happy path.
1721+
"Found an ErrDiskFault error, but no disk faults were injected: " <> show e
1722+
else
1723+
pure eith
1724+
Left e -> do
1725+
if countNoisyErrors errsLog > 0 then
1726+
pure $ Left $ Model.ErrOther $
1727+
-- If we injected 1 or more disk faults, but we did not find an
1728+
-- ErrDiskFault, then there is a bug in our code. An injected disk
1729+
-- fault should always lead to an ErrDiskFault.
1730+
"Found a non-ErrDiskFault error, but disk faults were injected: " <> show e
1731+
else
1732+
pure eith
17191733
Right x -> do
17201734
modifyMutVar faultsVar (InjectFaultAccidentalSuccess s :)
17211735
rollback x
1722-
assert (countNoisyErrors errsLog == 0) $ pure ()
1723-
pure $ Left $ Model.ErrDiskFault ("dummy: " <> s)
1736+
if (countNoisyErrors errsLog > 0) then
1737+
pure $ Left $ Model.ErrOther $
1738+
-- If we injected 1 or more disk faults, but the action
1739+
-- accidentally succeeded, then 1 or more errors were swallowed
1740+
-- that should have been found as ErrDiskFault.
1741+
"Action succeeded, but disk faults were injected. Errors were swallowed!"
1742+
else
1743+
pure $ Left $ Model.ErrDiskFault ("dummy: " <> s)
17241744
where
17251745
errsVar = envErrors env
17261746
logVar = envErrorsLog env

0 commit comments

Comments
 (0)