Skip to content

Commit

Permalink
Add customizable timeout for shorter ci times for waitForConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Jun 4, 2019
1 parent 87fba13 commit 7d1343b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion exe/wallet/Main.hs
Expand Up @@ -334,7 +334,7 @@ execServer (Port port) (Port bridgePort) = do
network `seq` return () -- Force evaluation of ENV[network]
db <- MVar.newDBLayer
nw <- HttpBridge.newNetworkLayer bridgePort
waitForConnection nw
waitForConnection nw 20
let tl = HttpBridge.newTransactionLayer
wallet <- newWalletLayer @_ @HttpBridge db nw tl
Server.start settings wallet
Expand Down
3 changes: 2 additions & 1 deletion lib/core/src/Cardano/Wallet/Network.hs
Expand Up @@ -79,8 +79,9 @@ instance Exception ErrPostTx
-- | Tries to waits 20 s, until 'networkTip networkLayer' succeeds.
waitForConnection
:: NetworkLayer IO
-> Int -- ^ Number of retries / timeout in seconds
-> IO ()
waitForConnection nw = loop 20
waitForConnection nw = loop
where
loop :: Int -> IO ()
loop retries = runExceptT (networkTip nw) >>= \case
Expand Down
Expand Up @@ -159,7 +159,7 @@ spec = do
describe "waitForConnection" $ do
it "times out after a short while" $ do
nw <- newNetworkLayer
waitForConnection nw `shouldThrow` \case
waitForConnection nw 2 `shouldThrow` \case
ErrNetworkTipNetworkUnreachable _ -> True
_ -> False

Expand All @@ -171,7 +171,7 @@ spec = do
-- returns within (3s + 3s extra)
res <- race
(threadDelay 6000000)
(waitForConnection c )
(waitForConnection c 20)
res `shouldSatisfy` isRight
cancel handle

Expand Down
3 changes: 2 additions & 1 deletion lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs
Expand Up @@ -132,8 +132,9 @@ instance Exception ErrUnexpectedNetworkFailure
-- "Cardano.Wallet.Network".
waitForConnection
:: Jormungandr IO
-> Int -- ^ Number of retries / timeout in seconds
-> IO ()
waitForConnection j = loop 20
waitForConnection j = loop
where
loop :: Int -> IO ()
loop retries = runExceptT (getTipId j) >>= \case
Expand Down
Expand Up @@ -71,7 +71,7 @@ spec = do
describe "waitForConnection" $ do
it "times out after a short while" $ do
c <- newClient
waitForConnection c `shouldThrow` \case
waitForConnection c 2 `shouldThrow` \case
ErrNetworkUnreachable _ -> True

it "returns when the network becomes availible" $ do
Expand All @@ -82,7 +82,7 @@ spec = do
-- returns within (3s + 3s extra)
res <- race
(threadDelay 6000000)
(waitForConnection c )
(waitForConnection c 20)
res `shouldSatisfy` isRight
cancel handle

Expand All @@ -98,7 +98,7 @@ spec = do
startNode = do
handle <- async $ launch $ return $ jormungandrWithSetup (return ())
client <- newClient
waitForConnection client
waitForConnection client 20
return (handle, client)

closeNode (handle, _) = do
Expand Down

0 comments on commit 7d1343b

Please sign in to comment.