ouroboros-network-framework:testlib
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Network.ConnectionManager.Test.Experiments

Description

This module contains experiments which can be executed either in IO or in IOSim.

Synopsis

Documentation

data ClientAndServerData req Source #

The protocol will run three instances of ReqResp protocol; one for each state: warm, hot and established.

Constructors

ClientAndServerData 

Fields

  • accumulatorInit :: req

    Initial value. In for each request the server sends back a list received requests (in reverse order) terminating with the accumulatorInit.

  • hotInitiatorRequests :: [[req]]

    list of requests run by the hot initiator in each round; Running multiple rounds allows us to test restarting of responders.

  • warmInitiatorRequests :: [[req]]

    list of requests run by the warm initiator in each round

  • establishedInitiatorRequests :: [[req]]

    list of requests run by the established initiator in each round

unidirectionalExperiment :: forall peerAddr socket acc req resp m. (ConnectionManagerMonad m, MonadAsync m, MonadDelay m, MonadFix m, MonadLabelledSTM m, MonadTraceSTM m, MonadSay m, acc ~ [req], resp ~ [req], Ord peerAddr, Show peerAddr, Typeable peerAddr, Eq peerAddr, Serialise req, Show req, Serialise resp, Show resp, Eq resp, Typeable req, Typeable resp) => StdGen -> Timeouts -> Snocket m socket peerAddr -> MakeBearer m socket -> (socket -> m ()) -> socket -> ClientAndServerData req -> m Property Source #

This test runs an initiator only connection manager (client side) and bidirectional connection manager (which runs a server). The client connect to the server and runs protocols to completion.

There is a good reason why we don't run two bidirectional connection managers; If we would do that, when the either side terminates the connection the client side server would through an exception as it is listening.

bidirectionalExperiment Source #

Arguments

:: forall peerAddr socket acc req resp m. (ConnectionManagerMonad m, MonadAsync m, MonadDelay m, MonadFix m, MonadLabelledSTM m, MonadTraceSTM m, MonadSay m, acc ~ [req], resp ~ [req], Ord peerAddr, Show peerAddr, Typeable peerAddr, Eq peerAddr, Serialise req, Show req, Serialise resp, Show resp, Eq resp, Typeable req, Typeable resp, Show acc) 
=> Bool 
-> StdGen 
-> Timeouts 
-> Snocket m socket peerAddr 
-> MakeBearer m socket 
-> (socket -> m ())

configure socket

-> socket 
-> socket 
-> peerAddr 
-> peerAddr 
-> ClientAndServerData req 
-> ClientAndServerData req 
-> m Property 

Bidirectional send and receive.

withInitiatorOnlyConnectionManager Source #

Arguments

:: forall name peerAddr socket req resp m a. (ConnectionManagerMonad m, resp ~ [req], Ord peerAddr, Show peerAddr, Typeable peerAddr, Serialise req, Typeable req, MonadAsync m, MonadDelay m, MonadFix m, MonadLabelledSTM m, MonadTraceSTM m, MonadSay m, Show req, Show name) 
=> name

identifier (for logging)

-> Timeouts 
-> Tracer m (WithName name (AbstractTransitionTrace ConnStateId)) 
-> Tracer m (WithName name (Trace peerAddr (ConnectionHandlerTrace UnversionedProtocol DataFlowProtocolData))) 
-> StdGen 
-> Snocket m socket peerAddr 
-> MakeBearer m socket

series of request possible to do with the bidirectional connection manager towards some peer.

-> ConnStateIdSupply m 
-> Maybe peerAddr 
-> TemperatureBundle (ConnectionId peerAddr -> STM m [req])

Functions to get the next requests for a given connection

-> ProtocolTimeLimits (Handshake UnversionedProtocol Term)

Handshake time limits

-> AcceptedConnectionsLimit 
-> (ConnectionManagerWithExpandedCtx 'InitiatorMode socket peerAddr DataFlowProtocolData UnversionedProtocol ByteString m [resp] Void -> m a) 
-> m a 

withBidirectionalConnectionManager Source #

Arguments

:: forall name peerAddr socket acc req resp m a. (ConnectionManagerMonad m, acc ~ [req], resp ~ [req], Ord peerAddr, Show peerAddr, Typeable peerAddr, Serialise req, Typeable req, MonadAsync m, MonadDelay m, MonadFix m, MonadLabelledSTM m, MonadTraceSTM m, MonadSay m, Show req, Show name) 
=> name 
-> Timeouts

identifier (for logging)

-> Tracer m (WithName name (RemoteTransitionTrace peerAddr)) 
-> Tracer m (WithName name (AbstractTransitionTrace ConnStateId)) 
-> Tracer m (WithName name (Trace peerAddr (ConnectionHandlerTrace UnversionedProtocol DataFlowProtocolData))) 
-> Tracer m (WithName name (Trace peerAddr)) 
-> Tracer m (WithName name (Debug peerAddr DataFlowProtocolData)) 
-> StdGen 
-> Snocket m socket peerAddr 
-> MakeBearer m socket 
-> ConnStateIdSupply m 
-> (socket -> m ())

configure socket

-> socket

listening socket

-> Maybe peerAddr 
-> acc

Initial state for the server

-> TemperatureBundle (ConnectionId peerAddr -> STM m [req])

Functions to get the next requests for a given connection ^ series of request possible to do with the bidirectional connection manager towards some peer.

-> ProtocolTimeLimits (Handshake UnversionedProtocol Term)

Handshake time limits

-> AcceptedConnectionsLimit 
-> (ConnectionManagerWithExpandedCtx 'InitiatorResponderMode socket peerAddr DataFlowProtocolData UnversionedProtocol ByteString m [resp] acc -> peerAddr -> Async m Void -> m a) 
-> m a 

Runs an example server which runs a single ReqResp protocol for any hot / warm / established peers and also gives access to bidirectional ConnectionManager. This gives a way to connect to other peers. Slightly unfortunate design decision does not give us a way to create a client per connection. This means that this connection manager takes list of req type which it will make to the other side (they will be multiplexed across warm / how / established) protocols.

runInitiatorProtocols :: forall (muxMode :: Mode) addr m a b. (Alternative (STM m), MonadAsync m, MonadCatch m, MonadLabelledSTM m, MonadMask m, MonadSTM m, MonadThrow (STM m), HasInitiator muxMode ~ 'True, MonadSay m) => SingMuxMode muxMode -> Mux muxMode m -> OuroborosBundle muxMode (ExpandedInitiatorContext addr m) (ResponderContext addr) ByteString m a b -> TemperatureBundle (StrictTVar m ControlMessage) -> ConnectionId addr -> m (TemperatureBundle a) Source #

Run all initiator mini-protocols and collect results. Throw exception if any of the thread returned an exception.

This function assumes that there's one established, one warm and one hot mini-protocol, which is compatible with both

oneshotNextRequests :: forall req peerAddr m. MonadSTM m => ClientAndServerData req -> m (TemperatureBundle (ConnectionId peerAddr -> STM m [req])) Source #

Next requests bundle for bidirectional and unidirectional experiments.