From 2dea92e8b796ca47cf59cafbcfee57427169f6f8 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Fri, 27 Dec 2019 14:49:12 +1000 Subject: [PATCH] tests: remove duplicate isPortOpen There was a sticky package interdependency that meant that isPortOpen needed to be copy&pasted into two packages. One of the copies missed a bug fix. Since the package interdependency is no longer there, delete the broken copy. --- .../cardano-wallet-jormungandr.cabal | 3 ++ .../test/integration}/Test/Utils/Ports.hs | 48 ++----------------- .../cardano-wallet-test-utils.cabal | 3 -- nix/.stack.nix/cardano-wallet-jormungandr.nix | 2 + nix/.stack.nix/cardano-wallet-test-utils.nix | 2 - 5 files changed, 9 insertions(+), 49 deletions(-) rename lib/{test-utils/src => jormungandr/test/integration}/Test/Utils/Ports.hs (52%) diff --git a/lib/jormungandr/cardano-wallet-jormungandr.cabal b/lib/jormungandr/cardano-wallet-jormungandr.cabal index 7c59931abd8..205791adaca 100644 --- a/lib/jormungandr/cardano-wallet-jormungandr.cabal +++ b/lib/jormungandr/cardano-wallet-jormungandr.cabal @@ -224,6 +224,7 @@ test-suite integration , network , persistent , process + , random-shuffle , retry , safe , servant @@ -233,6 +234,7 @@ test-suite integration , text-class , time , transformers + , unliftio , warp , yaml build-tools: @@ -258,6 +260,7 @@ test-suite integration Test.Integration.Jormungandr.Scenario.CLI.StakePools Test.Integration.Jormungandr.Scenario.CLI.Transactions Test.Integration.Jormungandr.Scenario.CLI.Mnemonics + Test.Utils.Ports benchmark latency default-language: diff --git a/lib/test-utils/src/Test/Utils/Ports.hs b/lib/jormungandr/test/integration/Test/Utils/Ports.hs similarity index 52% rename from lib/test-utils/src/Test/Utils/Ports.hs rename to lib/jormungandr/test/integration/Test/Utils/Ports.hs index 996bc5810ce..54e5f3510c1 100644 --- a/lib/test-utils/src/Test/Utils/Ports.hs +++ b/lib/jormungandr/test/integration/Test/Utils/Ports.hs @@ -11,36 +11,20 @@ module Test.Utils.Ports ( randomUnusedTCPPorts , findPort - , isPortOpen - , simpleSockAddr ) where import Prelude +import Cardano.Wallet.Network.Ports + ( isPortOpen + , simpleSockAddr + ) import Control.Monad ( filterM ) import Data.List ( sort ) -import Data.Word - ( Word8 ) -import Foreign.C.Error - ( Errno (..), eCONNREFUSED ) -import GHC.IO.Exception - ( IOException (..) ) -import Network.Socket - ( Family (AF_INET) - , PortNumber - , SockAddr (SockAddrInet) - , SocketType (Stream) - , close' - , connect - , socket - , tupleToHostAddress - ) import System.Random.Shuffle ( shuffleM ) -import UnliftIO.Exception - ( bracket, throwIO, try ) -- | Get a list of random TCPv4 ports that currently do not have any servers -- listening on them. It may return less than the requested number of ports. @@ -59,27 +43,3 @@ randomUnusedTCPPorts count = do -- called. findPort :: IO Int findPort = head <$> randomUnusedTCPPorts 1 - --- | Checks whether @connect()@ to a given TCPv4 `SockAddr` succeeds or --- returns `eCONNREFUSED`. --- --- Rethrows connection exceptions in all other cases (e.g. when the host --- is unroutable). -isPortOpen :: SockAddr -> IO Bool -isPortOpen sockAddr = do - bracket (socket AF_INET Stream 6 {- TCP -}) close' $ \sock -> 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 - - --- | Creates a `SockAttr` from host IP and port number. --- --- Example: --- > simpleSockAddr (127,0,0,1) 8000 -simpleSockAddr :: (Word8, Word8, Word8, Word8) -> PortNumber -> SockAddr -simpleSockAddr addr port = SockAddrInet port (tupleToHostAddress addr) diff --git a/lib/test-utils/cardano-wallet-test-utils.cabal b/lib/test-utils/cardano-wallet-test-utils.cabal index 323c43dfbc5..992c236eea6 100644 --- a/lib/test-utils/cardano-wallet-test-utils.cabal +++ b/lib/test-utils/cardano-wallet-test-utils.cabal @@ -39,11 +39,9 @@ library , iohk-monitoring , network , QuickCheck - , random-shuffle , stm , template-haskell , time - , unliftio , wai-app-static , warp hs-source-dirs: @@ -51,7 +49,6 @@ library exposed-modules: Test.Hspec.Extra Test.Utils.Paths - Test.Utils.Ports Test.Utils.StaticServer Test.Utils.Time Test.Utils.Trace diff --git a/nix/.stack.nix/cardano-wallet-jormungandr.nix b/nix/.stack.nix/cardano-wallet-jormungandr.nix index 2482832d029..b6704781434 100644 --- a/nix/.stack.nix/cardano-wallet-jormungandr.nix +++ b/nix/.stack.nix/cardano-wallet-jormungandr.nix @@ -199,6 +199,7 @@ in { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }: (hsPkgs."network" or (buildDepError "network")) (hsPkgs."persistent" or (buildDepError "persistent")) (hsPkgs."process" or (buildDepError "process")) + (hsPkgs."random-shuffle" or (buildDepError "random-shuffle")) (hsPkgs."retry" or (buildDepError "retry")) (hsPkgs."safe" or (buildDepError "safe")) (hsPkgs."servant" or (buildDepError "servant")) @@ -208,6 +209,7 @@ in { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }: (hsPkgs."text-class" or (buildDepError "text-class")) (hsPkgs."time" or (buildDepError "time")) (hsPkgs."transformers" or (buildDepError "transformers")) + (hsPkgs."unliftio" or (buildDepError "unliftio")) (hsPkgs."warp" or (buildDepError "warp")) (hsPkgs."yaml" or (buildDepError "yaml")) ]; diff --git a/nix/.stack.nix/cardano-wallet-test-utils.nix b/nix/.stack.nix/cardano-wallet-test-utils.nix index 4df9a46ec50..bf19050905a 100644 --- a/nix/.stack.nix/cardano-wallet-test-utils.nix +++ b/nix/.stack.nix/cardano-wallet-test-utils.nix @@ -70,11 +70,9 @@ in { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }: (hsPkgs."iohk-monitoring" or (buildDepError "iohk-monitoring")) (hsPkgs."network" or (buildDepError "network")) (hsPkgs."QuickCheck" or (buildDepError "QuickCheck")) - (hsPkgs."random-shuffle" or (buildDepError "random-shuffle")) (hsPkgs."stm" or (buildDepError "stm")) (hsPkgs."template-haskell" or (buildDepError "template-haskell")) (hsPkgs."time" or (buildDepError "time")) - (hsPkgs."unliftio" or (buildDepError "unliftio")) (hsPkgs."wai-app-static" or (buildDepError "wai-app-static")) (hsPkgs."warp" or (buildDepError "warp")) ];