Skip to content

Commit

Permalink
fix CLI/Server launcher tests not waiting long enough for the launche…
Browse files Browse the repository at this point in the history
…r to be up
  • Loading branch information
KtorZ committed Jun 14, 2019
1 parent f6f125c commit 14589c9
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/core/test/integration/Test/Integration/Scenario/CLI/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ module Test.Integration.Scenario.CLI.Server

import Prelude

import Control.Concurrent
( threadDelay )
import System.Directory
( listDirectory, removeDirectory )
import System.Exit
( ExitCode (..) )
import System.IO.Temp
( withSystemTempDirectory )
import System.Process
( CreateProcess
( CreateProcess (..)
, StdStream (..)
, createProcess
, proc
, terminateProcess
Expand All @@ -23,16 +22,18 @@ import System.Process
import Test.Hspec
( Spec, describe, it, shouldContain, shouldReturn )

import qualified Data.Text.IO as TIO

spec :: Spec
spec = do
describe "Launcher should start the server with a database" $ do
it "should create the database file" $ withTempDir $ \d -> do
removeDirectory d
launcher d
ls <- listDirectory d
ls `shouldContain` ["wallet.db"]

it "should work with empty state directory" $ withTempDir $ \d -> do
removeDirectory d
launcher d
ls <- listDirectory d
ls `shouldContain` ["wallet.db"]
Expand All @@ -46,12 +47,9 @@ spec = do
withTempDir :: (FilePath -> IO a) -> IO a
withTempDir = withSystemTempDirectory "integration-state"

waitForStartup :: IO ()
waitForStartup = threadDelay (2 * 1000 * 1000)

launcher :: FilePath -> IO ()
launcher stateDir = withCreateProcess cmd $ \_ _ _ ph -> do
waitForStartup
launcher stateDir = withCreateProcess cmd $ \_ _ (Just stderr) ph -> do
TIO.hGetContents stderr >>= TIO.putStrLn
terminateProcess ph
where
cmd = proc' "cardano-wallet" ["launch", "--state-dir", stateDir]
Expand All @@ -68,4 +66,5 @@ launcher stateDir = withCreateProcess cmd $ \_ _ _ ph -> do
--
-- So one hacky way to work around it is by running programs under "stack exec".
proc' :: FilePath -> [String] -> CreateProcess
proc' cmd args = proc "stack" (["exec", cmd, "--"] ++ args)
proc' cmd args = (proc "stack" (["exec", "--", cmd] ++ args))
{ std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe }

0 comments on commit 14589c9

Please sign in to comment.