Skip to content

Commit 052624e

Browse files
committed
test: add handler for FileFormatError to StateMachine
1 parent 6f99a27 commit 052624e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

test/Test/Database/LSMTree/StateMachine.hs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import Database.LSMTree.Extras.Generators (KeyForIndexCompact)
101101
import Database.LSMTree.Extras.NoThunks (propNoThunks)
102102
import Database.LSMTree.Internal (LSMTreeError (..))
103103
import qualified Database.LSMTree.Internal as R.Internal
104+
import Database.LSMTree.Internal.CRC32C (FileFormatError (..))
104105
import Database.LSMTree.Internal.Serialise (SerialisedBlob,
105106
SerialisedValue)
106107
import qualified Database.LSMTree.Model.IO as ModelIO
@@ -188,7 +189,7 @@ propLockstep_ModelIOImpl =
188189
env :: RealEnv ModelIO.Table IO
189190
env = RealEnv {
190191
envSession = session
191-
, envHandlers = [handler, diskFaultErrorHandler]
192+
, envHandlers = [handler, diskFaultErrorHandler, fileFormatErrorHandler]
192193
, envErrors = errsVar
193194
, envInjectFaultResults = faultsVar
194195
}
@@ -292,6 +293,7 @@ propLockstep_RealImpl_RealFS_IO tr =
292293
, envHandlers = [
293294
realHandler @IO
294295
, diskFaultErrorHandler
296+
, fileFormatErrorHandler
295297
]
296298
, envErrors = errsVar
297299
, envInjectFaultResults = faultsVar
@@ -334,6 +336,7 @@ propLockstep_RealImpl_MockFS_IO tr =
334336
, envHandlers = [
335337
realHandler @IO
336338
, diskFaultErrorHandler
339+
, fileFormatErrorHandler
337340
]
338341
, envErrors = errsVar
339342
, envInjectFaultResults = faultsVar
@@ -362,6 +365,7 @@ propLockstep_RealImpl_MockFS_IOSim tr actions =
362365
, envHandlers = [
363366
realHandler @(IOSim s)
364367
, diskFaultErrorHandler
368+
, fileFormatErrorHandler
365369
]
366370
, envErrors = errsVar
367371
, envInjectFaultResults = faultsVar
@@ -458,6 +462,19 @@ isDiskFault e
458462
isDiskFault' :: forall e. Exception e => e -> Bool
459463
isDiskFault' = isDiskFault . toException
460464

465+
fileFormatErrorHandler :: Monad m => Handler m (Maybe Model.Err)
466+
fileFormatErrorHandler = Handler $ \e -> pure $
467+
if isFileFormatError e
468+
then Just (Model.ErrFsError (displayException e))
469+
else Nothing
470+
471+
isFileFormatError :: SomeException -> Bool
472+
isFileFormatError e
473+
| Just (FileFormatError _file _msg) <- fromException e
474+
= True
475+
| otherwise
476+
= False
477+
461478
createSystemTempDirectory :: [Char] -> IO (FilePath, HasFS IO HandleIO, HasBlockIO IO HandleIO)
462479
createSystemTempDirectory prefix = do
463480
systemTempDir <- getCanonicalTemporaryDirectory

0 commit comments

Comments
 (0)