Skip to content

Commit

Permalink
Merge #1011 #1028
Browse files Browse the repository at this point in the history
1011: Can run Windows integration tests under Wine r=rvl a=rvl

Relates to #703.

# Overview

- [ ] It's possible to execute `cardano-wallet-jormungandr:test:integration` under Wine.

# Comments

The tests run on Windows but there is something weird going on with Wine.

![2019-11-12-14-30-53-wine-integration-tests](https://user-images.githubusercontent.com/1019641/68679174-19e1db00-05ab-11ea-9c62-8a30e2807f77.png)

To build and run the tests under wine, use:
```
wine $(nix-build release.nix -A x86_64-pc-mingw32.tests.cardano-wallet-jormungandr.integration.x86_64-linux -o integration-windows)/cardano-wallet-jormungandr-2019.11.7/integration.exe
```


1028: Fix the initial sleep delay in the chain following r=KtorZ a=Anviking


# Issue Number

#1027


# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] I have changed the initial sleep delay from `0` to `1 s`.


# Comments

- Minor downside: we sleep for the initial delay on startup.

<!-- Additional comments or screenshots to attach if any -->

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
  • Loading branch information
4 people authored Nov 14, 2019
3 parents 91d6efd + 5718446 + bf8844d commit 6873b98
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 21 deletions.
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
1 change: 1 addition & 0 deletions lib/core/src/Cardano/Wallet/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ follow nl tr cps yield rollback header =
delay0 = 1000*1000 -- 1 second

retryDelay :: Int -> Int
retryDelay 0 = delay0
retryDelay delay = min (2*delay) (60 * delay0)

-- | Wait a short delay before querying for blocks again. We also take this
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: 2 additions & 10 deletions lib/jormungandr/test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Cardano.CLI
import Cardano.Faucet
( initFaucet )
import Cardano.Launcher
( ProcessHasExited (..) )
( ProcessHasExited (..), withUtf8Encoding )
import Cardano.Wallet.Api.Server
( Listen (..) )
import Cardano.Wallet.Jormungandr
Expand Down Expand Up @@ -52,8 +52,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 +98,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 +160,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

0 comments on commit 6873b98

Please sign in to comment.