Skip to content

Commit 6822b5f

Browse files
committed
QLS: OptionFaultInjection
1 parent 07275cd commit 6822b5f

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

test/Test/Database/LSMTree/StateMachine.hs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ instance Arbitrary Model.TableConfig where
176176
deriving via AllowThunk (ModelIO.Session IO)
177177
instance NoThunks (ModelIO.Session IO)
178178

179-
type ModelIOImpl = ModelIO.Table
179+
type ModelIOImpl = '(ModelIO.Table, DisableFaultInjection)
180180

181181
propLockstep_ModelIOImpl ::
182182
Actions (Lockstep (ModelState ModelIOImpl))
@@ -278,7 +278,7 @@ instance Arbitrary R.WriteBufferAlloc where
278278
| QC.Positive x' <- QC.shrink (QC.Positive x)
279279
]
280280

281-
type RealImplRealFS = R.Table
281+
type RealImplRealFS = '(R.Table, DisableFaultInjection)
282282

283283
propLockstep_RealImpl_RealFS_IO ::
284284
Tracer IO R.LSMTreeTrace
@@ -320,7 +320,7 @@ propLockstep_RealImpl_RealFS_IO tr =
320320
R.closeSession session
321321
removeDirectoryRecursive tmpDir
322322

323-
type RealImplMockFS = R.Table
323+
type RealImplMockFS = '(R.Table, EnableFaultInjection)
324324

325325
propLockstep_RealImpl_MockFS_IO ::
326326
Tracer IO R.LSMTreeTrace
@@ -500,12 +500,21 @@ instance R.ResolveValue Value where
500500
Model state
501501
-------------------------------------------------------------------------------}
502502

503-
type ModelStateTypeParams = TableKind
503+
type ModelStateTypeParams = (TableKind, OptionFaultInjection)
504504
type TableKind = (Type -> Type) -> Type -> Type -> Type -> Type
505505

506+
data OptionFaultInjection =
507+
EnableFaultInjection
508+
| DisableFaultInjection
509+
506510
type Table :: ModelStateTypeParams -> TableKind
507511
type family Table ps where
508-
Table h = h
512+
Table '(h, iof) = h
513+
514+
type InjectFault :: ModelStateTypeParams -> Bool
515+
type family InjectFault ps where
516+
InjectFault '(h, EnableFaultInjection) = True
517+
InjectFault '(h, DisableFaultInjection) = False
509518

510519
type ModelState :: ModelStateTypeParams -> Type
511520
data ModelState ps = ModelState Model.Model Stats
@@ -553,6 +562,9 @@ instance ( Show (Class.TableConfig (Table h))
553562
, Eq (Class.TableConfig (Table h))
554563
, Arbitrary (Class.TableConfig (Table h))
555564
, Typeable (Table h)
565+
, Typeable h
566+
, Typeable (InjectFault h)
567+
, SBoolI (InjectFault h)
556568
) => StateModel (Lockstep (ModelState h)) where
557569
data instance Action (Lockstep (ModelState h)) a where
558570
-- Tables
@@ -602,13 +614,13 @@ instance ( Show (Class.TableConfig (Table h))
602614
-- Snapshots
603615
CreateSnapshot ::
604616
C k v b
605-
=> StaticMaybe 'True (Maybe Errors)
617+
=> StaticMaybe (InjectFault h) (Maybe Errors)
606618
-> R.SnapshotLabel -> R.SnapshotName -> Var h (WrapTable (Table h) IO k v b)
607619
-> Act h ()
608620
OpenSnapshot ::
609621
C k v b
610622
=> {-# UNPACK #-} !(PrettyProxy (k, v, b))
611-
-> StaticMaybe 'True (Maybe Errors)
623+
-> StaticMaybe (InjectFault h) (Maybe Errors)
612624
-> R.SnapshotLabel -> R.SnapshotName
613625
-> Act h (WrapTable (Table h) IO k v b)
614626
DeleteSnapshot :: R.SnapshotName -> Act h ()
@@ -726,6 +738,9 @@ instance ( Eq (Class.TableConfig (Table h))
726738
, Show (Class.TableConfig (Table h))
727739
, Arbitrary (Class.TableConfig (Table h))
728740
, Typeable (Table h)
741+
, Typeable h
742+
, Typeable (InjectFault h)
743+
, SBoolI (InjectFault h)
729744
) => InLockstep (ModelState h) where
730745
type instance ModelOp (ModelState h) = Op
731746

@@ -942,7 +957,10 @@ instance ( Eq (Class.TableConfig (Table h))
942957
, Show (Class.TableConfig (Table h))
943958
, Arbitrary (Class.TableConfig (Table h))
944959
, Typeable (Table h)
960+
, Typeable h
945961
, NoThunks (Class.Session (Table h) IO)
962+
, Typeable (InjectFault h)
963+
, SBoolI (InjectFault h)
946964
) => RunLockstep (ModelState h) (RealMonad h IO) where
947965
observeReal ::
948966
Proxy (RealMonad h IO)
@@ -1003,6 +1021,9 @@ instance ( Eq (Class.TableConfig (Table h))
10031021
, Show (Class.TableConfig (Table h))
10041022
, Arbitrary (Class.TableConfig (Table h))
10051023
, Typeable ((Table h))
1024+
, Typeable h
1025+
, Typeable (InjectFault h)
1026+
, SBoolI (InjectFault h)
10061027
) => RunLockstep (ModelState h) (RealMonad h (IOSim s)) where
10071028
observeReal ::
10081029
Proxy (RealMonad h (IOSim s))
@@ -1067,7 +1088,10 @@ instance ( Eq (Class.TableConfig (Table h))
10671088
, Show (Class.TableConfig (Table h))
10681089
, Arbitrary (Class.TableConfig (Table h))
10691090
, Typeable (Table h)
1091+
, Typeable h
10701092
, NoThunks (Class.Session (Table h) IO)
1093+
, Typeable (InjectFault h)
1094+
, SBoolI (InjectFault h)
10711095
) => RunModel (Lockstep (ModelState h)) (RealMonad h IO) where
10721096
perform _ = runIO
10731097
postcondition = Lockstep.Defaults.postcondition
@@ -1078,6 +1102,9 @@ instance ( Eq (Class.TableConfig (Table h))
10781102
, Show (Class.TableConfig (Table h))
10791103
, Arbitrary (Class.TableConfig (Table h))
10801104
, Typeable (Table h)
1105+
, Typeable h
1106+
, Typeable (InjectFault h)
1107+
, SBoolI (InjectFault h)
10811108
) => RunModel (Lockstep (ModelState h)) (RealMonad h (IOSim s)) where
10821109
perform _ = runIOSim
10831110
postcondition = Lockstep.Defaults.postcondition
@@ -1365,6 +1392,9 @@ arbitraryActionWithVars ::
13651392
, Show (Class.TableConfig (Table h))
13661393
, Arbitrary (Class.TableConfig (Table h))
13671394
, Typeable (Table h)
1395+
, Typeable h
1396+
, Typeable (InjectFault h)
1397+
, SBoolI (InjectFault h)
13681398
)
13691399
=> Proxy (k, v, b)
13701400
-> R.SnapshotLabel
@@ -1572,6 +1602,7 @@ shrinkActionWithVars ::
15721602
Eq (Class.TableConfig (Table h))
15731603
, Arbitrary (Class.TableConfig (Table h))
15741604
, Typeable ((Table h))
1605+
, SBoolI (InjectFault h)
15751606
)
15761607
=> ModelVarContext (ModelState h)
15771608
-> ModelState h
@@ -1694,6 +1725,9 @@ updateStats ::
16941725
, Eq (Class.TableConfig (Table h))
16951726
, Arbitrary (Class.TableConfig (Table h))
16961727
, Typeable (Table h)
1728+
, Typeable h
1729+
, Typeable (InjectFault h)
1730+
, SBoolI (InjectFault h)
16971731
)
16981732
=> LockstepAction (ModelState h) a
16991733
-> ModelLookUp (ModelState h)

0 commit comments

Comments
 (0)