Safe Haskell | None |
---|---|
Language | Haskell2010 |
Facilitates testing of asynchronouse code.
Example
Assume you have a server that accepts incoming messages and
produces responses asynchronously. In order to test it, open a
connection to it, and process any incomming message from the server by
adding it to the Inbox. Now that we know the messages are all arriving
in the inbox, the test can send messages to the server and use
takeInbox
to wait for expected responses.
Synopsis
- data Inbox a
- newInbox :: IO (Inbox a)
- putInbox :: forall m a. MonadIO m => Inbox a -> a -> m ()
- takeInbox :: (MonadIO m, Show a) => Inbox a -> Filter a b -> m b
- takeInbox' :: forall m a b. (MonadIO m, Show a) => Float -> Inbox a -> Filter a b -> m b
- data Filter a b = Filter Text (a -> Maybe b)
- equalTo :: (Eq a, Show a) => a -> Filter a ()
- predicate :: Text -> (a -> Bool) -> Filter a a
- expectEmpty :: Show a => Inbox a -> IO (ErrorOr ())
- expectEmpty' :: (Show a, MonadIO m) => Inbox a -> Filter a b -> m ()
Documentation
takeInbox :: (MonadIO m, Show a) => Inbox a -> Filter a b -> m b Source #
takeInbox'
with a timeout of 3s
takeInbox' :: forall m a b. (MonadIO m, Show a) => Float -> Inbox a -> Filter a b -> m b Source #
Take a single message out of the inbox, waiting for it up to the specified timeout in seconds. It respects the order the messages were inserted into the inbox.
It is a selector/matcher/extractor with a name. It specifies
what message to pick from the Inbox
and how to transform it. The
name provides for a better error messages. See predicate
for a
Filter
a
a
that selects an element and does not apply any
transformation.
equalTo :: (Eq a, Show a) => a -> Filter a () Source #
A filter that matches messages equal to the given one.
A filter that matches messages based on a predicate.