Skip to content
Permalink
Browse files

Merge pull request #528 from input-output-hk/piotr/serve_timeout_test

Timeout test for serve for jormungandr and http-bridge
  • Loading branch information...
KtorZ committed Jul 11, 2019
2 parents d69e14c + 9b923f6 commit c23d7e6e03927ea8749904f3830d1b2922e8644c
@@ -120,13 +120,13 @@ jobs:
script:
- travis_retry curl -L -o hermes-testnet.tar.gz https://raw.githubusercontent.com/input-output-hk/cardano-wallet/master/lib/http-bridge/test/data/cardano-http-bridge/hermes-testnet.tar.gz
- tar xzf hermes-testnet.tar.gz -C $HOME
- stack --no-terminal test --fast cardano-wallet-http-bridge:integration
- stack --no-terminal test --fast cardano-wallet-http-bridge:integration --ta "--skip PR_DISABLED"

- stage: checks 🔬
if: type = pull_request OR (branch IN (bors/staging, bors/trying))
name: "Tests: integration (jormungandr)"
script:
- stack --no-terminal test --fast cardano-wallet-jormungandr:integration
- stack --no-terminal test --fast cardano-wallet-jormungandr:integration --ta "--skip PR_DISABLED"

################################################################################
#
@@ -997,7 +997,7 @@ collectStreams (nOut0, nErr0) p = do
hSetBuffering o LineBuffering
hSetBuffering e LineBuffering
let io = race
(threadDelay (45 * oneSecond))
(threadDelay (65 * oneSecond))
(collect mvar ((o, nOut0), (e, nErr0)) ph)
void $ io `finally` do
-- NOTE
@@ -113,6 +113,7 @@ main = do
hSetEncoding stdout utf8
hSetEncoding stderr utf8
hspec $ do
describe "PR_DISABLED Server CLI timeout test" (ServerCLI.specNoBackend @t)
describe "Cardano.WalletSpec" Wallet.spec
describe "Cardano.Wallet.HttpBridge.NetworkSpec" HttpBridge.spec
describe "Launcher CLI tests" (LauncherCLI.spec @t)
@@ -138,16 +139,16 @@ main = do
PortCLI.specCommon @t
PortCLI.specWithRandomPort @t defaultPort
beforeAll startCluster $ afterAll _cleanup $ after tearDown $ do
describe "Wallets API endpoint tests" (Wallets.spec @t)
describe "Transactions API endpoint tests" (Transactions.spec @t)
describe "Addresses API endpoint tests" (Addresses.spec @t)
describe "PR_DISABLED Wallets API endpoint tests" (Wallets.spec @t)
describe "PR_DISABLED Transactions API endpoint tests" (Transactions.spec @t)
describe "PR_DISABLED Addresses API endpoint tests" (Addresses.spec @t)
describe "Wallets CLI tests" (WalletsCLI.spec @t)
describe "Transactions CLI tests" (TransactionsCLI.spec @t)
describe "Addresses CLI tests" (AddressesCLI.spec @t)
describe "Server CLI tests" (ServerCLI.spec @t)
describe "Transactions CLI tests (bridge specific)"
(TransactionsCLIBridge.spec @t)
describe "Transactions API endpoint tests (bridge specific)"
describe "PR_DISABLED Transactions API endpoint tests (bridge specific)"
(TransactionsBridge.spec @t)
where
oneSecond :: Int
@@ -1,22 +1,33 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Test.Integration.HttpBridge.Scenario.CLI.Server
( spec
, specNoBackend
) where

import Prelude

import Control.Concurrent
( threadDelay )
import Control.Monad
( forM_ )
import System.Exit
( ExitCode (..) )
import System.IO.Temp
( withSystemTempDirectory )
import System.Process
( terminateProcess, withCreateProcess )
( createProcess
, proc
, terminateProcess
, waitForProcess
, withCreateProcess
)
import Test.Hspec
( SpecWith, describe, it )
( Spec, SpecWith, describe, it )
import Test.Hspec.Expectations.Lifted
( shouldBe )
( shouldBe, shouldReturn )
import Test.Integration.Framework.DSL
( Context (..)
, KnownCommand (..)
@@ -42,6 +53,20 @@ spec = do
terminateProcess ph
threadDelay oneSecond

describe "DaedalusIPC" $ do
let defaultArgs =
[ commandName @t , "serve" ]
let tests =
[ defaultArgs ++ ["--random-port"]
, defaultArgs ++ ["--port", "8082"]
]
forM_ tests $ \args -> do
let title = "should reply with the port when asked " <> show args
it title $ \_ -> do
let filepath = "test/integration/js/mock-daedalus.js"
(_, _, _, ph) <- createProcess (proc filepath args)
waitForProcess ph `shouldReturn` ExitSuccess

describe "LOGGING - cardano-wallet serve logging" $ do
it "LOGGING - Launch can log --verbose" $ \_ -> do
let args = ["serve", "--random-port", "--verbose"]
@@ -68,6 +93,21 @@ spec = do
out `shouldContainT` "Info"
out `shouldContainT` "Notice"

specNoBackend :: forall t. KnownCommand t => Spec
specNoBackend = do
it "TIMEOUT - Times out gracefully after 60 seconds" $ do
let args = ["serve"]
let process = proc' (commandName @t) args
(out, err) <- collectStreams (61, 61) process
out `shouldContainT` "Waited too long for http-bridge to become available.\
\ Giving up!"
err `shouldContainT` "Hint (1): If you're launching the wallet server\
\ on your own, double-check that http-bridge is up-and-running and\
\ listening on the same port given to '--node-port' (i.e. tcp/8080)."
err `shouldContainT` "Hint (2): Should you be starting from scratch,\
\ make sure to have a good-enough network connection to synchronize\
\ the first blocks in a timely manner."

oneSecond :: Int
oneSecond = 1000000

@@ -108,18 +108,19 @@ instance KnownCommand (Jormungandr n) where

main :: forall t. (t ~ Jormungandr 'Testnet) => IO ()
main = hspec $ do
describe "PR_DISABLED Server CLI timeout test" (ServerCLI.specNoBackend @t)
describe "Cardano.Wallet.NetworkSpec" Network.spec
describe "Mnemonics CLI tests" (MnemonicsCLI.spec @t)
describe "Miscellaneous CLI tests" (MiscellaneousCLI.spec @t)
describe "Ports CLI (negative) tests" (PortCLI.specNegative @t)
describe "Launcher CLI tests" (LauncherCLI.spec @t)
beforeAll (start Nothing) $ afterAll _cleanup $ after tearDown $ do
-- API e2e Testing
describe "Addresses API endpoint tests" Addresses.spec
describe "Transactions API endpoint tests" Transactions.spec
describe "Transactions API endpoint tests (Jormungandr specific)"
describe "PR_DISABLED Addresses API endpoint tests" Addresses.spec
describe "PR_DISABLED Transactions API endpoint tests" Transactions.spec
describe "PR_DISABLED Transactions API endpoint tests (Jormungandr specific)"
(TransactionsJormungandr.spec @t)
describe "Wallets API endpoint tests" Wallets.spec
describe "PR_DISABLED Wallets API endpoint tests" Wallets.spec
-- Command-Line e2e Testing
describe "Addresses CLI tests" (AddressesCLI.spec @t)
describe "Server CLI tests" (ServerCLI.spec @t)
@@ -1,22 +1,33 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Test.Integration.Jormungandr.Scenario.CLI.Server
( spec
, specNoBackend
) where

import Prelude

import Control.Concurrent
( threadDelay )
import Control.Monad
( forM_ )
import System.Exit
( ExitCode (..) )
import System.IO.Temp
( withSystemTempDirectory )
import System.Process
( terminateProcess, withCreateProcess )
( createProcess
, proc
, terminateProcess
, waitForProcess
, withCreateProcess
)
import Test.Hspec
( SpecWith, describe, it )
( Spec, SpecWith, describe, it )
import Test.Hspec.Expectations.Lifted
( shouldBe )
( shouldBe, shouldReturn )
import Test.Integration.Framework.DSL
( Context (..)
, KnownCommand (..)
@@ -31,30 +42,42 @@ import Test.Integration.Framework.TestData

spec :: forall t. KnownCommand t => SpecWith (Context t)
spec = do
let block0H =
"dba597bee5f0987efbf56f6bd7f44c38158a7770d0cb28a26b5eca40613a7ebd"
describe "SERVER - cardano-wallet serve" $ do
it "SERVER - Can start cardano-wallet serve --database" $ \_ -> do
withTempDir $ \d -> do
let db = d ++ "/db-file"
let args =
[ "serve", "--database", db, "--genesis-hash"
, "dba597bee5f0987efbf56f6bd7f44c38\
\158a7770d0cb28a26b5eca40613a7ebd"
]
[ "serve", "--database", db, "--genesis-hash", block0H ]
let process = proc' (commandName @t) args
withCreateProcess process $ \_ _ _ ph -> do
expectPathEventuallyExist db
terminateProcess ph
threadDelay oneSecond

describe "DaedalusIPC" $ do
let defaultArgs =
[ commandName @t , "serve" , "--genesis-hash", block0H ]
let tests =
[ defaultArgs ++ ["--random-port"]
, defaultArgs ++ ["--port", "8082"]
]
forM_ tests $ \args -> do
let title = "should reply with the port when asked " <> show args
it title $ \_ -> do
let filepath = "test/integration/js/mock-daedalus.js"
(_, _, _, ph) <- createProcess (proc filepath args)
waitForProcess ph `shouldReturn` ExitSuccess

describe "LOGGING - cardano-wallet serve logging" $ do
it "LOGGING - Launch can log --verbose" $ \_ -> do
let args =
["serve"
, "--random-port"
, "--verbose"
, "--genesis-hash"
, "dba597bee5f0987efbf56f6bd7f44c38\
\158a7770d0cb28a26b5eca40613a7ebd"
, block0H
]
let process = proc' (commandName @t) args
(out, _) <- collectStreams (20, 0) process
@@ -69,8 +92,7 @@ spec = do
, "--random-port"
, "--quiet"
, "--genesis-hash"
, "dba597bee5f0987efbf56f6bd7f44c38\
\158a7770d0cb28a26b5eca40613a7ebd"
, block0H
]
let process = proc' (commandName @t) args
(out, err) <- collectStreams (10, 10) process
@@ -82,8 +104,7 @@ spec = do
["serve"
, "--random-port"
, "--genesis-hash"
, "dba597bee5f0987efbf56f6bd7f44c38\
\158a7770d0cb28a26b5eca40613a7ebd"
, block0H
]
let process = proc' (commandName @t) args
(out, _) <- collectStreams (5, 0) process
@@ -92,6 +113,24 @@ spec = do
out `shouldContainT` "Info"
out `shouldContainT` "Notice"

specNoBackend :: forall t. KnownCommand t => Spec
specNoBackend = do
it "TIMEOUT - Times out gracefully after 60 seconds" $ do
let args =
["serve"
, "--genesis-hash"
, "1234"
]
let process = proc' (commandName @t) args
(out, err) <- collectStreams (61, 61) process
out `shouldContainT` "Waited too long for Jörmungandr to become available.\
\ Giving up!"
err `shouldContainT` "Hint (1): If you're launching the wallet server\
\ on your own, double-check that Jörmungandr is up-and-running and\
\ listening on the same port given to '--node-port' (i.e. tcp/8080)."
err `shouldContainT` "Hint (2): Should you be starting from scratch,\
\ make sure to have a good-enough network connection to synchronize\
\ the first blocks in a timely manner."

oneSecond :: Int
oneSecond = 1000000

0 comments on commit c23d7e6

Please sign in to comment.
You can’t perform that action at this time.