ouroboros-consensus-test-0.1.0.0: Tests of the consensus layer
Safe HaskellNone
LanguageHaskell2010

Test.Util.FS.Sim.Error

Description

HasFS instance wrapping SimFS that generates errors, suitable for testing error handling.

Synopsis

Simulate Errors monad

mkSimErrorHasFS ∷ ∀ m. (MonadSTM m, MonadThrow m) ⇒ StrictTVar m MockFSStrictTVar m ErrorsHasFS m HandleMock Source #

Introduce possibility of errors

TODO: Lenses would be nice for the setters

runSimErrorFS ∷ (MonadSTM m, MonadThrow m) ⇒ MockFSErrors → (StrictTVar m ErrorsHasFS m HandleMock → m a) → m (a, MockFS) Source #

Runs a computation provided an Errors and an initial MockFS, producing a result and the final state of the filesystem.

withErrorsMonadSTM m ⇒ StrictTVar m ErrorsErrors → m a → m a Source #

Execute the next action using the given Errors. After the action is finished, the previous Errors are restored.

Streams

type ErrorStream = Stream FsErrorType Source #

An ErrorStream is a possibly infinite Stream of (Maybe) FsErrorTypes.

Nothing indicates that there is no error.

Each time the ErrorStream is used (see runErrorStream), the first element (Nothing in case the list is empty) is taken from the list and an ErrorStream with the remainder of the list is returned. The first element represents whether an error should be returned or not.

An FsError consists of a number of fields: fsErrorType, a fsErrorPath, etc. Only the first fields is interesting. Therefore, we only generate the FsErrorType. The FsErrorType will be used to construct the actual FsError.

type ErrorStreamPutSome = Stream (Either (FsErrorType, Maybe PutCorruption) Partial) Source #

ErrorStream for hPutSome: an error and possibly some corruption, or a partial write.

newtype Stream a Source #

A Stream is a possibly infinite stream of Maybe as.

Constructors

Stream 

Fields

Instances

Instances details
Functor Stream Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Methods

fmap ∷ (a → b) → Stream a → Stream b Source #

(<$) ∷ a → Stream b → Stream a Source #

Show a ⇒ Show (Stream a) Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Methods

showsPrecIntStream a → ShowS Source #

showStream a → String Source #

showList ∷ [Stream a] → ShowS Source #

Semigroup (Stream a) Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Methods

(<>)Stream a → Stream a → Stream a Source #

sconcatNonEmpty (Stream a) → Stream a Source #

stimesIntegral b ⇒ b → Stream a → Stream a Source #

Monoid (Stream a) Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Methods

memptyStream a Source #

mappendStream a → Stream a → Stream a Source #

mconcat ∷ [Stream a] → Stream a Source #

always ∷ a → Stream a Source #

Make a Stream that always generates the given a.

mkStream ∷ [Maybe a] → Stream a Source #

Create a Stream based on the given possibly infinite list of Maybe as.

mkStreamGenInt → Gen a → Gen (Stream a) Source #

Make a Stream generator based on a a generator.

The generator generates a finite stream of 10 elements, where each element has a chance of being either Nothing or an element generated with the given a generator (wrapped in a Just).

The first argument is the likelihood (as used by frequency) of a Just where Nothing has likelihood 2.

nullStream a → Bool Source #

Return True if the stream is empty.

A stream consisting of only Nothings (even if it is only one) is not considered to be empty.

runStreamStream a → (Maybe a, Stream a) Source #

Advance the Stream. Return the Maybe a and the remaining Stream.

Generating partial reads/writes

newtype Partial Source #

Given a Partial p where p > 0, we do the following to make a call to hGetSome or hPutSome partial:

  • hGetSome: we subtract p from the number of requested bytes. If that would result in 0 requested bytes or less, we request 1 byte. If the number of requested bytes was already 0, leave it untouched, as we can't simulate a partial read in this case.
  • hPutSome: we drop the last p bytes from the bytestring. If that would result in an empty bytestring, just take the first byte of the bytestring. If the bytestring was already empty, leave it untouched, as we can't simulate a partial write in this case.

Constructors

Partial Word64 

Instances

Instances details
Show Partial Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Arbitrary Partial Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Methods

arbitrary ∷ Gen Partial

shrinkPartial → [Partial]

Generating corruption for hPutSome

data PutCorruption Source #

Model possible corruptions that could happen to a hPutSome call.

Constructors

SubstituteWithJunk Blob

The blob to write is substituted with corrupt junk

PartialWrite Partial

Only perform the write partially

Instances

Instances details
Show PutCorruption Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Arbitrary PutCorruption Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Error streams for HasFS

data Errors Source #

Error streams for the methods of the HasFS type class.

An ErrorStream is provided for each method of the HasFS type class. This ErrorStream will be used to generate potential errors that will be thrown by the corresponding method.

For hPutSome, an ErrorStreamWithCorruption is provided to simulate corruption.

An Errors is used in conjunction with SimErrorFS, which is a layer on top of SimFS that simulates methods throwing FsErrors.

Instances

Instances details
Show Errors Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Semigroup Errors Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Monoid Errors Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Arbitrary Errors Source # 
Instance details

Defined in Test.Util.FS.Sim.Error

Methods

arbitrary ∷ Gen Errors

shrinkErrors → [Errors]

allNullErrorsBool Source #

Return True if all streams are empty (null).

genErrors Source #

Arguments

Bool

True -> generate partial writes

Bool

True -> generate SubstituteWithJunk corruptions

→ Gen Errors 

Generator for Errors that allows some things to be disabled.

This is needed by the VolatileDB state machine tests, which try to predict what should happen based on the Errors, which is too complex sometimes.

simpleErrorsErrorStreamErrors Source #

Use the given ErrorStream for each field/method. No corruption of hPutSome.