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

Can run Windows integration tests under Wine #1011

Merged
merged 8 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Use pinned Nixpkgs with Haskell.nix overlay
, pkgs ? import ./nix/nixpkgs-haskell.nix { inherit system crossSystem config; }
# Use this git revision for stamping executables
, gitrev ? iohkLib.commitIdFromGitRepo ./.
, gitrev ? iohkLib.commitIdFromGitRepo ./.git
}:

with import ./nix/util.nix { inherit pkgs; };
Expand Down
2 changes: 2 additions & 0 deletions lib/core/cardano-wallet-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ test-suite unit
, tree-diff
, unordered-containers
, yaml
, wai
, warp
build-tools:
hspec-discover
Expand All @@ -221,6 +222,7 @@ test-suite unit
Cardano.Wallet.DB.StateMachine
Cardano.Wallet.DummyTarget.Primitive.Types
Cardano.Wallet.Network.BlockHeadersSpec
Cardano.Wallet.Network.PortsSpec
Cardano.Wallet.NetworkSpec
Cardano.Wallet.Primitive.AddressDerivation.ByronSpec
Cardano.Wallet.Primitive.AddressDerivation.ShelleySpec
Expand Down
11 changes: 6 additions & 5 deletions lib/core/src/Cardano/Wallet/Network/Ports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import Control.Monad.IO.Class
( liftIO )
import Control.Retry
( RetryPolicyM, retrying )
import Data.List
( isInfixOf )
import Data.Streaming.Network
( bindRandomPortTCP )
import Data.Word
Expand All @@ -52,7 +54,6 @@ import Network.Socket
import UnliftIO.Exception
( bracket, throwIO, try )


-- | Wait until a TCP port is open to connections according to a given retry
-- policy. Throws an exception if the time out is reached.
waitForPort :: RetryPolicyM IO -> PortNumber -> IO Bool
Expand Down Expand Up @@ -89,10 +90,10 @@ isPortOpen sockAddr = do
res <- try $ connect sock sockAddr
case res of
Right () -> return True
Left e ->
if (Errno <$> ioe_errno e) == Just eCONNREFUSED
then return False
else throwIO e
Left e
| (Errno <$> ioe_errno e) == Just eCONNREFUSED -> pure False
| "WSAECONNREFUSED" `isInfixOf` show e -> pure False
| otherwise -> throwIO e

-- | Creates a `SockAttr` from host IP and port number.
--
Expand Down
31 changes: 31 additions & 0 deletions lib/core/test/unit/Cardano/Wallet/Network/PortsSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Cardano.Wallet.Network.PortsSpec
( spec
) where

import Prelude

import Cardano.Wallet.Network.Ports
( getRandomPort, isPortOpen, simpleSockAddr )
import Network.HTTP.Types
( status200 )
import Network.Wai
( responseLBS )
import Network.Wai.Handler.Warp
( withApplication )
import Test.Hspec
( Spec, describe, it, shouldReturn )

spec :: Spec
spec = describe "Cardano.Wallet.Network.Ports" $ do
it "isPortOpen detects an available port" $ do
port <- getRandomPort
isPortOpen (localhost port) `shouldReturn` False

it "isPortOpen detects a port in use" $ do
let app = \_req respond -> respond $ responseLBS status200 [] ""
withApplication (pure app) $ \port ->
isPortOpen (localhost (fromIntegral port)) `shouldReturn` True

where
localhost = simpleSockAddr (127,0,0,1)

12 changes: 3 additions & 9 deletions lib/jormungandr/test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import Cardano.Faucet
( initFaucet )
import Cardano.Launcher
( ProcessHasExited (..) )
import Cardano.Launcher
( withUtf8Encoding )
import Cardano.Wallet.Api.Server
( Listen (..) )
import Cardano.Wallet.Jormungandr
Expand Down Expand Up @@ -52,8 +54,6 @@ import Data.Quantity
( Quantity (..) )
import Data.Text
( Text )
import GHC.IO.Encoding
( mkTextEncoding, setLocaleEncoding )
import Network.HTTP.Client
( defaultManagerSettings
, managerResponseTimeout
Expand Down Expand Up @@ -100,8 +100,7 @@ instance KnownCommand Jormungandr where
commandName = "cardano-wallet-jormungandr"

main :: forall t. (t ~ Jormungandr) => IO ()
main = withLogging Nothing Info $ \logging -> do
setUtf8LenientCodecs
main = withUtf8Encoding $ withLogging Nothing Info $ \logging ->
hspec $ do
describe "No backend required" $ do
describe "Cardano.Wallet.NetworkSpec" $ parallel NetworkLayer.spec
Expand Down Expand Up @@ -163,11 +162,6 @@ specWithServer logCfg = aroundAll withContext . after tearDown
serveWallet @'Testnet logCfg (SyncTolerance 10) Nothing "127.0.0.1"
ListenOnRandomPort (Launch jmCfg) setup

-- | Set a utf8 text encoding that doesn't crash when non-utf8 bytes are
-- encountered.
setUtf8LenientCodecs :: IO ()
setUtf8LenientCodecs = mkTextEncoding "UTF-8//IGNORE" >>= setLocaleEncoding

sockAddrPort :: SockAddr -> Port a
sockAddrPort addr = Port . fromIntegral $ case addr of
SockAddrInet p _ -> p
Expand Down
1 change: 1 addition & 0 deletions nix/.stack.nix/cardano-wallet-core.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions nix/haskell-nix-src.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"url": "https://github.com/input-output-hk/haskell.nix",
"rev": "7d96b156c53bc86f3ad79d8588575ee0dc774f3c",
"date": "2019-11-11T01:01:30+13:00",
"sha256": "1nnjz2a0m97sjjq99zixgar7lf4vx1mkjhd80ngx1a7q87f28sa7",
"rev": "ef4b453f8d4589cefbab750bcf551e338e8cba91",
"date": "2019-11-13T21:57:38+13:00",
"sha256": "0qv7k33rfp5791ghqk4l3w8my7arvy486ym3avnqvs5dix6x9czv",
"fetchSubmodules": false
}
4 changes: 2 additions & 2 deletions nix/windows-testing-bundle.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ in pkgs.runCommand name {

${pkgs.lib.concatMapStringsSep "\n" (test: ''
pkg=`ls -1 ${test}`
exe=`cd ${test}; ls -1 $pkg`
exe=`cd ${test}/$pkg; ls -1 *.exe`
name=$pkg-test-$exe
cp ${test}/$pkg/$exe $name
echo $name >> tests.bat
Expand All @@ -58,7 +58,7 @@ in pkgs.runCommand name {

${pkgs.lib.concatMapStringsSep "\n" (bench: ''
pkg=`ls -1 ${bench}`
exe=`cd ${bench}; ls -1 $pkg`
exe=`cd ${bench}/$pkg; ls -1 *.exe`
name=$pkg-bench-$exe
cp ${bench}/$pkg/$exe $name
'') benchmarks}
Expand Down