Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests in nix release build #766

Merged
merged 12 commits into from
Oct 24, 2019
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let

haskellPackages = import ./nix/default.nix {
inherit pkgs haskell src;
inherit cardano-http-bridge cardano-sl-node jormungandr;
inherit cardano-http-bridge cardano-sl-node jmPkgs;
inherit (iohkLib.nix-tools) iohk-extras iohk-module;
};

Expand Down
2 changes: 2 additions & 0 deletions lib/core-integration/cardano-wallet-core-integration.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ library
, text
, text-class
, time
, QuickCheck
hs-source-dirs:
src
exposed-modules:
Expand All @@ -76,3 +77,4 @@ library
Test.Integration.Scenario.CLI.Port
Test.Integration.Scenario.CLI.Transactions
Test.Integration.Scenario.CLI.Wallets
Cardano.Wallet.TransactionSpecShared
7 changes: 7 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,21 @@ data ListenError

ioToListenError :: HostPreference -> Listen -> IOException -> Maybe ListenError
ioToListenError hostPreference portOpt e
-- A socket is already listening on that address and port
| isAlreadyInUseError e =
Just (ListenErrorAddressAlreadyInUse (listenPort portOpt))
-- Usually caused by trying to listen on a privileged port
| isPermissionError e =
Just ListenErrorOperationNotPermitted
-- Bad hostname
| isDoesNotExistError e =
Just (ListenErrorHostDoesNotExist hostPreference)
-- Address is valid, but can't be used for listening -- Linux
| show (ioeGetErrorType e) == "invalid argument" =
Just (ListenErrorInvalidAddress hostPreference)
-- Address is valid, but can't be used for listening -- Darwin
| show (ioeGetErrorType e) == "unsupported operation" =
Just (ListenErrorInvalidAddress hostPreference)
| otherwise =
Nothing
where
Expand Down
12 changes: 10 additions & 2 deletions lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ import Control.Lens
( Lens', at, (^.) )
import Control.Monad
( replicateM )
import Control.Monad.IO.Class
( liftIO )
import Crypto.Hash
( hash )
import Data.Aeson
Expand Down Expand Up @@ -163,6 +165,8 @@ import Servant
)
import Servant.Swagger.Test
( validateEveryToJSON )
import System.Environment
( lookupEnv )
import Test.Aeson.GenericSpecs
( GoldenDirectoryOption (CustomDirectoryName)
, Proxy (Proxy)
Expand Down Expand Up @@ -1019,8 +1023,12 @@ specification :: Swagger
specification =
unsafeDecode bytes
where
bytes = $(makeRelativeToProject "../../specifications/api/swagger.yaml"
>>= embedFile)
bytes = $(
let swaggerYaml = "../../specifications/api/swagger.yaml"
in liftIO (lookupEnv "SWAGGER_YAML") >>=
maybe (makeRelativeToProject swaggerYaml) pure >>=
embedFile
)
unsafeDecode =
either (error . (msg <>) . show) Prelude.id . Yaml.decodeEither'
msg = "Whoops! Failed to parse or find the api specification document: "
Expand Down
4 changes: 3 additions & 1 deletion lib/http-bridge/cardano-wallet-http-bridge.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ test-suite unit
, bytestring
, cardano-crypto
, cardano-wallet-core
, cardano-wallet-core-integration
, cardano-wallet-http-bridge
, cborg
, containers
Expand Down Expand Up @@ -153,7 +154,6 @@ test-suite unit
Cardano.Wallet.HttpBridge.Primitive.AddressDerivation.SequentialSpec
Cardano.Wallet.HttpBridge.Primitive.TypesSpec
Cardano.Wallet.HttpBridge.TransactionSpec
Cardano.Wallet.TransactionSpecShared
Data.PackfileSpec
Servant.Extra.ContentTypesSpec

Expand Down Expand Up @@ -199,6 +199,8 @@ test-suite http-bridge-integration
, text-class
, time
, transformers
build-tools:
cardano-wallet-http-bridge
type:
exitcode-stdio-1.0
hs-source-dirs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,11 @@ import System.IO
import System.IO.Temp
( withSystemTempDirectory, withSystemTempFile )
import System.Process
( createProcess
, proc
, terminateProcess
, waitForProcess
, withCreateProcess
)
( terminateProcess, withCreateProcess )
import Test.Hspec
( Spec, describe, it, pendingWith )
import Test.Hspec.Expectations.Lifted
( shouldBe, shouldReturn )
( shouldBe )
import Test.Integration.Framework.DSL
( KnownCommand (..)
, cardanoWalletCLI
Expand All @@ -66,7 +61,7 @@ import Test.Integration.Framework.DSL
import Test.Integration.Framework.TestData
( versionLine )
import Test.Utils.Ports
( findPort, randomUnusedTCPPorts )
( findPort )

import qualified Data.Text.IO as TIO

Expand Down Expand Up @@ -156,26 +151,6 @@ spec = do
TIO.hGetContents o >>= TIO.putStrLn
TIO.hGetContents e >>= TIO.putStrLn

describe "DaedalusIPC" $ do
let defaultArgs nodePort =
[ commandName @t, "launch", "--node-port", show nodePort ]
let tests =
[ (const ["--random-port"], " [SERIAL]")
, (\fixedPort -> ["--port", fixedPort], "")
, (const [], " [SERIAL]")
]
forM_ tests $ \(args, tag) -> do
let title = "should reply with the port when asked "
<> show (args "FIXED") <> tag
it title $ withTempDir $ \d -> do
[fixedPort, nodePort] <- randomUnusedTCPPorts 2
let filepath = "test/integration/js/mock-daedalus.js"
let stateDir = ["--state-dir", d]
let scriptArgs = concat
[defaultArgs nodePort, args (show fixedPort), stateDir]
(_, _, _, ph) <- createProcess (proc filepath scriptArgs)
waitForProcess ph `shouldReturn` ExitSuccess

describe "LOGGING - cardano-wallet launch logging [SERIAL]" $ do
it "LOGGING - Launch can log --verbose" $ withTempDir $ \d -> do
pendingWith "See 'LAUNCH - Restoration workers restart'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,11 @@ import System.Exit
import System.IO.Temp
( withSystemTempDirectory )
import System.Process
( createProcess
, proc
, terminateProcess
, waitForProcess
, withCreateProcess
)
( terminateProcess, withCreateProcess )
import Test.Hspec
( Spec, SpecWith, describe, it )
import Test.Hspec.Expectations.Lifted
( shouldBe, shouldContain, shouldReturn )
( shouldBe, shouldContain )
import Test.Integration.Framework.DSL
( Context (..)
, KnownCommand (..)
Expand All @@ -49,8 +44,6 @@ import Test.Integration.Framework.DSL
)
import Test.Integration.Framework.TestData
( versionLine )
import Test.Utils.Ports
( findPort )

spec :: forall t. KnownCommand t => SpecWith (Context t)
spec = do
Expand Down Expand Up @@ -82,29 +75,6 @@ spec = do
err `shouldBe` mempty
c `shouldBe` ExitFailure 1

describe "DaedalusIPC" $ do
let defaultArgs nodePort =
[ commandName @t
, "serve"
, "--node-port"
, show nodePort
]

let filepath = "test/integration/js/mock-daedalus.js"

it "Should reply with the port --random" $ \ctx -> do
let scriptArgs = defaultArgs (ctx ^. typed @(Port "node"))
++ ["--random-port"]
(_, _, _, ph) <- createProcess (proc filepath scriptArgs)
waitForProcess ph `shouldReturn` ExitSuccess

it "Should reply with the port --random" $ \ctx -> do
walletPort <- findPort
let scriptArgs = defaultArgs (ctx ^. typed @(Port "node"))
++ ["--port", show walletPort]
(_, _, _, ph) <- createProcess (proc filepath scriptArgs)
waitForProcess ph `shouldReturn` ExitSuccess

describe "LOGGING - cardano-wallet serve logging" $ do
it "LOGGING - Launch can log --verbose" $ \ctx -> do
let args = ["serve", "--random-port", "--verbose"
Expand Down
1 change: 0 additions & 1 deletion lib/http-bridge/test/integration/js

This file was deleted.

This file was deleted.

5 changes: 4 additions & 1 deletion lib/jormungandr/cardano-wallet-jormungandr.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ test-suite unit
, bytestring
, cardano-crypto
, cardano-wallet-core
, cardano-wallet-core-integration
, cardano-wallet-jormungandr
, containers
, directory
Expand Down Expand Up @@ -165,7 +166,6 @@ test-suite unit
Cardano.Wallet.Jormungandr.EnvironmentSpec
Cardano.Wallet.Jormungandr.NetworkSpec
Cardano.Wallet.Jormungandr.TransactionSpec
Cardano.Wallet.TransactionSpecShared

test-suite integration
default-language:
Expand Down Expand Up @@ -227,6 +227,9 @@ test-suite integration
, transformers
, warp
, yaml
build-tools:
nodejs
, cardano-wallet-jormungandr
type:
exitcode-stdio-1.0
hs-source-dirs:
Expand Down
1 change: 0 additions & 1 deletion lib/jormungandr/test/integration/js

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions lib/launcher/test/data/forever.sh

This file was deleted.

3 changes: 0 additions & 3 deletions lib/launcher/test/data/once.sh

This file was deleted.

27 changes: 18 additions & 9 deletions lib/launcher/test/unit/Cardano/LauncherSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,35 @@ spec = do

it "1st process exits with 0, others are cancelled" $ do
let commands =
[ Command "./test/data/once.sh" ["0"] (pure ()) Inherit
, Command "./test/data/forever.sh" [] (pure ()) Inherit
[ mockCommand 0 (pure ())
, foreverCommand
]
(ProcessHasExited name code) <- launch nullTracer commands
name `shouldBe` cmdName (commands !! 0)
code `shouldBe` ExitSuccess

it "2nd process exits with 0, others are cancelled" $ do
let commands =
[ Command "./test/data/forever.sh" [] (pure ()) Inherit
, Command "./test/data/once.sh" ["0"] (pure ()) Inherit
[ foreverCommand
, mockCommand 0 (pure ())
]
(ProcessHasExited name code) <- launch nullTracer commands
name `shouldBe` cmdName (commands !! 1)
code `shouldBe` ExitSuccess

it "1st process exits with 14, others are cancelled" $ do
let commands =
[ Command "./test/data/once.sh" ["14"] (pure ()) Inherit
, Command "./test/data/forever.sh" [] (pure ()) Inherit
[ mockCommand 14 (pure ())
, foreverCommand
]
(ProcessHasExited name code) <- launch nullTracer commands
name `shouldBe` cmdName (commands !! 0)
code `shouldBe` (ExitFailure 14)

it "2nd process exits with 14, others are cancelled" $ do
let commands =
[ Command "./test/data/forever.sh" [] (pure ()) Inherit
, Command "./test/data/once.sh" ["14"] (pure ()) Inherit
[ foreverCommand
, mockCommand 14 (pure ())
]
(ProcessHasExited name code) <- launch nullTracer commands
name `shouldBe` cmdName (commands !! 1)
Expand All @@ -78,7 +78,7 @@ spec = do
mvar <- newEmptyMVar
let before = putMVar mvar "executed"
let commands =
[ Command "./test/data/once.sh" ["0"] before Inherit
[ mockCommand 0 before
]
(ProcessHasExited _ code) <- launch nullTracer commands
code `shouldBe` ExitSuccess
Expand All @@ -90,3 +90,12 @@ spec = do
]
ProcessDidNotStart name _exc <- launch nullTracer commands
name `shouldBe` "foobar"

-- | A command that will run for a short time then exit with the given status.
mockCommand :: Int -> IO () -> Command
mockCommand exitStatus before =
Command "sh" ["-c", "sleep 1; exit " ++ show exitStatus] before Inherit

-- | A command that will run for longer than the other commands.
foreverCommand :: Command
foreverCommand = Command "sleep" ["30"] (pure ()) Inherit
45 changes: 0 additions & 45 deletions nix/.stack.nix/bimap.nix

This file was deleted.

Loading