Skip to content

Commit 3307ec1

Browse files
authored
Merge pull request #13 from oscoin/f/network-delays
Inject Network Faults in Tests
2 parents 86b5c0e + 04f26eb commit 3307ec1

File tree

12 files changed

+668
-430
lines changed

12 files changed

+668
-430
lines changed

.stylish-haskell.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ steps:
8686
# > )
8787
#
8888
# Default: inline
89-
long_list_align: new_line_multiline
89+
long_list_align: multiline
9090

9191
# Align empty list (importing instances)
9292
#

gossip.cabal

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ common common
3030
, base
3131
, bytestring
3232
, containers
33+
, safe-exceptions
3334
, splitmix
3435
, stm
3536
, transformers
@@ -82,11 +83,9 @@ library
8283
, hashable
8384
, list-t
8485
, microlens
85-
, microlens-mtl
8686
, mtl
8787
, network
8888
, random
89-
, safe-exceptions
9089
, serialise
9190
, stm-containers < 1
9291
, text
@@ -104,11 +103,15 @@ test-suite tests
104103
algebraic-graphs == 0.2.*
105104
, gossip
106105
, hedgehog
106+
, hedgehog-quickcheck
107+
, QuickCheck
108+
, random
107109

108110
other-modules:
109111
Network.Gossip.Test.Assert
110112
Network.Gossip.Test.Broadcast
111113
Network.Gossip.Test.Gen
114+
Network.Gossip.Test.Helpers
112115
Network.Gossip.Test.Membership
113116

114117
ghc-options:

src/Network/Gossip/HyParView.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ import Codec.Serialise (Serialise)
5858
import Control.Applicative (liftA2)
5959
import Control.Concurrent.STM
6060
import Control.Exception.Safe
61-
(Exception, SomeException, toException, tryAny)
61+
( Exception
62+
, SomeException
63+
, toException
64+
, tryAny
65+
)
6266
import Control.Monad (when)
6367
import Control.Monad.Reader
6468
import Control.Monad.Trans.Cont

src/Network/Gossip/HyParView/Periodic.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import qualified Network.Gossip.HyParView as H
1515

1616
import Control.Concurrent (threadDelay)
1717
import Control.Concurrent.Async
18-
(Async, Concurrently(..), async, uninterruptibleCancel)
18+
( Async
19+
, Concurrently(..)
20+
, async
21+
, uninterruptibleCancel
22+
)
1923
import Control.Exception.Safe (bracket)
2024
import Control.Monad (forever)
2125
import Data.Hashable (Hashable)

src/Network/Gossip/IO/Run.hs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ import Data.Foldable (toList)
3131
import Data.Hashable (Hashable)
3232
import GHC.Generics (Generic)
3333
import Network.Socket (HostName, PortNumber)
34+
import Prelude hiding (round)
3435
import qualified System.Random.SplitMix as SplitMix
3536

3637
data ProtocolMessage n =
37-
ProtocolPlumtree (P.Message n)
38-
| ProtocolHyParView (H.RPC n)
38+
ProtocolPlumtree (P.RPC n)
39+
| ProtocolHyParView (H.RPC n)
3940
deriving (Eq, Generic)
4041

4142
instance (Eq n, Hashable n, Serialise n) => Serialise (ProtocolMessage n)
@@ -97,9 +98,13 @@ withGossip self
9798
bootstrap env
9899
k env
99100
where
100-
sendIHaves env to xs =
101+
sendIHaves env to round xs =
101102
runNetwork env $
102-
S.send to $ WirePayload (ProtocolPlumtree (P.IHaveM xs))
103+
S.send to . WirePayload . ProtocolPlumtree $ P.RPC
104+
{ P.rpcSender = self
105+
, P.rpcRound = Just round
106+
, P.rpcPayload = P.IHave xs
107+
}
103108

104109
listen env = async $
105110
runNetwork env (S.listen (evalNetwork env) host port)
@@ -133,8 +138,8 @@ evalPlumtree env@Env { envApplyMessage, envLookupMessage } = go
133138
`onException` runHyParView env (H.eject to)
134139
k >>= go
135140

136-
P.SendLazy to ihaves k -> do
137-
runScheduler env $ PS.sendLazy to ihaves
141+
P.SendLazy to round ihaves k -> do
142+
runScheduler env $ PS.sendLazy to round ihaves
138143
k >>= go
139144

140145
P.Later t mid action k -> do

0 commit comments

Comments
 (0)