hydra-node
Safe HaskellSafe-Inferred
LanguageGHC2021

Hydra.API.ServerSpec

Synopsis

Documentation

spec :: Spec Source #

State change translation fixtures

surfacedOutputs :: [(String, Maybe Text)] Source #

Which client output each StateChanged is surfaced as, by constructor name; Nothing for the ones deliberately kept internal. Adding a state change without classifying it here fails "classifies exactly the state changes that exist".

sampleStateChanges :: IO [(String, StateChanged SimpleTx)] Source #

One sample value per StateChanged constructor, paired with its name.

stateChangesOtherThan :: [String] -> IO [(String, StateChanged SimpleTx)] Source #

Samples for every constructor except the named ones.

outputTagOf :: TimedServerOutput SimpleTx -> Text Source #

aSeenSnapshot :: Snapshot SimpleTx Source #

anOpenedHead :: StateChanged SimpleTx Source #

aClosedHead :: StateChanged SimpleTx Source #

peerA :: Host Source #

peerB :: Host Source #

connected :: NetworkInfo Source #

disconnected :: NetworkInfo Source #

connectedTo :: NetworkInfo Source #

sendsAnErrorWhenInputCannotBeDecoded :: Socket -> PortNumber -> Expectation Source #

waitForClients :: (MonadSTM m, Ord a, Num a) => TVar m a -> m () Source #

testClient :: TQueue IO Value -> TVar IO Int -> Connection -> IO () Source #

allowEverythingServerOutputFilter :: ServerOutputFilter tx Source #

rejectEverything :: ServerOutputFilter tx Source #

Rejects every output, so anything a client still receives reached it without passing the filter.

onlyAddress :: Text -> ServerOutputFilter tx Source #

Accepts outputs only for one address, so which address the server asked about is observable from which client receives the output.

timedOutputOf :: StateEvent SimpleTx -> TimedServerOutput SimpleTx Source #

The TimedServerOutput a client is expected to receive for an event.

nextFrame :: HasCallStack => Connection -> IO Value Source #

The next frame on a connection, without skipping over any.

receivesNothing :: HasCallStack => Connection -> Expectation Source #

Assert that nothing more arrives on a connection. Used where the expectation is an absence, so it has to wait out a full second rather than return on a match.

noop :: Applicative m => a -> m () Source #

withFreeServerSocket :: (Socket -> PortNumber -> IO a) -> IO a Source #

Allocate a listening socket on a free port and hand both it and its port to the action. The server is then given the very socket it serves on, so the port cannot be taken in the gap between choosing it and binding it. That gap used to surface as a flaky RunServerException carrying "Address already in use".

withTestAPIServer :: Socket -> PortNumber -> Party -> EventSource (StateEvent SimpleTx) IO -> Tracer IO APIServerLog -> ((EventSink (StateEvent SimpleTx) IO, Server SimpleTx IO) -> IO ()) -> IO () Source #

withTestAPIServerBindingPort :: PortNumber -> Party -> EventSource (StateEvent SimpleTx) IO -> Tracer IO APIServerLog -> ((EventSink (StateEvent SimpleTx) IO, Server SimpleTx IO) -> IO ()) -> IO () Source #

Like withTestAPIServer but lets the server bind port itself. Only for the test that asserts a second server on the same port is refused: handing both servers one socket would let them both succeed.

withTestAPIServerStalledWhen :: Socket -> IO (Maybe StallReason) -> PortNumber -> Party -> EventSource (StateEvent SimpleTx) IO -> Tracer IO APIServerLog -> ((EventSink (StateEvent SimpleTx) IO, Server SimpleTx IO) -> IO ()) -> IO () Source #

Like withTestAPIServer, but with the live broadcast status the server greets clients with under the test's control.

withTestAPIServerWithCallback :: Maybe Socket -> PortNumber -> Party -> EventSource (StateEvent SimpleTx) IO -> Tracer IO APIServerLog -> (ClientInput SimpleTx -> IO ()) -> ((EventSink (StateEvent SimpleTx) IO, Server SimpleTx IO) -> IO ()) -> IO () Source #

Like withTestAPIServer, but with an explicit callback invoked for every ClientInput received by the server.

withTestAPIServerWithFilter :: Socket -> PortNumber -> Party -> EventSource (StateEvent SimpleTx) IO -> ServerOutputFilter SimpleTx -> Tracer IO APIServerLog -> ((EventSink (StateEvent SimpleTx) IO, Server SimpleTx IO) -> IO ()) -> IO () Source #

Like withTestAPIServer, but with an explicit ServerOutputFilter.

withTestAPIServer' :: Maybe Socket -> PortNumber -> Party -> EventSource (StateEvent SimpleTx) IO -> ServerOutputFilter SimpleTx -> Tracer IO APIServerLog -> (ClientInput SimpleTx -> IO ()) -> ((EventSink (StateEvent SimpleTx) IO, Server SimpleTx IO) -> IO ()) -> IO () Source #

withClient :: PortNumber -> String -> (Connection -> IO ()) -> IO () Source #

Connect to a websocket server running at given path. Fails if not connected within 2 seconds.

mockSource :: Monad m => [a] -> EventSource a m Source #

waitForValue :: HasCallStack => PortNumber -> (Value -> Maybe ()) -> IO () Source #

waitMatch :: HasCallStack => Natural -> Connection -> (Value -> Maybe a) -> IO a Source #

Wait up to some time for an API server output to match the given predicate.

shouldSatisfyAll :: forall a. HasCallStack => Show a => [a] -> [a -> Bool] -> Expectation Source #

genStateEventForApi :: Gen (StateEvent SimpleTx) Source #