| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
NovaNet.TestNet
Description
A simulated network that runs entirely in pure code (State monad). Supports configurable latency, loss, jitter, duplicates, and reordering. Multi-peer world simulation for integration tests.
No real sockets — two NetPeer states in the same process with manual packet routing between them.
Synopsis
- data TestNet a
- runTestNet :: TestNet a -> TestNetState -> (a, TestNetState)
- data TestNetConfig = TestNetConfig {}
- data TestNetState = TestNetState {
- tnsCurrentTime :: !MonoTime
- tnsLocalAddr :: !SockAddr
- tnsInFlight :: !(Seq InFlightPacket)
- tnsInbox :: !(Seq (ByteString, SockAddr))
- tnsConfig :: !TestNetConfig
- tnsRng :: !Word64
- tnsClosed :: !Bool
- data InFlightPacket = InFlightPacket {
- ifpFrom :: !SockAddr
- ifpTo :: !SockAddr
- ifpData :: !ByteString
- ifpDeliverAt :: !MonoTime
- initialTestNetState :: SockAddr -> TestNetState
- defaultTestNetConfig :: TestNetConfig
- advanceTime :: MonoTime -> TestNet ()
- simulateLatency :: Word64 -> TestNet ()
- simulateLoss :: Double -> TestNet ()
- getPendingPackets :: TestNet [InFlightPacket]
- data TestWorld = TestWorld {
- twPeers :: !(Map SockAddr TestNetState)
- twGlobalTime :: !MonoTime
- newTestWorld :: TestWorld
- runPeerInWorld :: SockAddr -> TestNet a -> TestWorld -> (a, TestWorld)
- deliverPackets :: TestWorld -> TestWorld
- worldAdvanceTime :: MonoTime -> TestWorld -> TestWorld
Test network monad
Pure deterministic network monad.
Instances
| Applicative TestNet Source # | |
| Functor TestNet Source # | |
| Monad TestNet Source # | |
| MonadNetwork TestNet Source # | |
| MonadTime TestNet Source # | |
Defined in NovaNet.TestNet Methods | |
| MonadState TestNetState TestNet Source # | |
Defined in NovaNet.TestNet Methods get :: TestNet TestNetState # put :: TestNetState -> TestNet () # state :: (TestNetState -> (a, TestNetState)) -> TestNet a # | |
runTestNet :: TestNet a -> TestNetState -> (a, TestNetState) Source #
Run a test network computation.
State
data TestNetConfig Source #
Test network configuration.
Constructors
| TestNetConfig | |
Fields
| |
Instances
| Show TestNetConfig Source # | |
Defined in NovaNet.TestNet Methods showsPrec :: Int -> TestNetConfig -> ShowS # show :: TestNetConfig -> String # showList :: [TestNetConfig] -> ShowS # | |
data TestNetState Source #
State of the test network for one peer.
Constructors
| TestNetState | |
Fields
| |
Instances
| Show TestNetState Source # | |
Defined in NovaNet.TestNet Methods showsPrec :: Int -> TestNetState -> ShowS # show :: TestNetState -> String # showList :: [TestNetState] -> ShowS # | |
| MonadState TestNetState TestNet Source # | |
Defined in NovaNet.TestNet Methods get :: TestNet TestNetState # put :: TestNetState -> TestNet () # state :: (TestNetState -> (a, TestNetState)) -> TestNet a # | |
data InFlightPacket Source #
A packet in transit.
Constructors
| InFlightPacket | |
Fields
| |
Instances
| Show InFlightPacket Source # | |
Defined in NovaNet.TestNet Methods showsPrec :: Int -> InFlightPacket -> ShowS # show :: InFlightPacket -> String # showList :: [InFlightPacket] -> ShowS # | |
initialTestNetState :: SockAddr -> TestNetState Source #
Create initial state for a peer.
defaultTestNetConfig :: TestNetConfig Source #
Default: no latency, no loss, no jitter.
Operations
advanceTime :: MonoTime -> TestNet () Source #
Advance time and deliver packets that are ready.
simulateLatency :: Word64 -> TestNet () Source #
Set simulated one-way latency (milliseconds).
simulateLoss :: Double -> TestNet () Source #
Set simulated packet loss rate (0.0 to 1.0).
getPendingPackets :: TestNet [InFlightPacket] Source #
Get all packets currently in flight.
Multi-peer world
A world containing multiple peers for integration testing.
Constructors
| TestWorld | |
Fields
| |
newTestWorld :: TestWorld Source #
Create a new empty test world.
runPeerInWorld :: SockAddr -> TestNet a -> TestWorld -> (a, TestWorld) Source #
Run a TestNet action for a specific peer. Auto-creates if missing.
deliverPackets :: TestWorld -> TestWorld Source #
Deliver all ready packets between peers.