Use install script in integration test for unix. (#1952)

* Use install script in unix integration test.

* Fix waitForProcess
This commit is contained in:
Fran 2019-07-01 10:21:04 +01:00 committed by mergify[bot]
parent 709112e92b
commit 074dadaf12
2 changed files with 38 additions and 25 deletions

View File

@ -52,13 +52,18 @@ main =
tests :: FilePath -> FilePath -> TestTree
tests damlDir tmpDir = testGroup "Integration tests"
[ testCase "install" $ do
releaseTarball <- locateRunfiles (mainWorkspace </> "release" </> "sdk-release-tarball.tar.gz")
createDirectory tarballDir
runConduitRes
$ sourceFileBS releaseTarball
.| Zlib.ungzip
.| Tar.Conduit.untar (Tar.Conduit.restoreFile throwError tarballDir)
callProcessQuiet (tarballDir </> "daml" </> damlInstallerName) ["install", "--activate", "--set-path=no", tarballDir]
releaseTarball <- locateRunfiles (mainWorkspace </> "release" </> "sdk-release-tarball.tar.gz")
createDirectory tarballDir
runConduitRes
$ sourceFileBS releaseTarball
.| Zlib.ungzip
.| Tar.Conduit.untar (Tar.Conduit.restoreFile throwError tarballDir)
if isWindows
then callProcessQuiet
(tarballDir </> "daml" </> damlInstallerName)
["install", "--install-assistant=yes", "--set-path=no", tarballDir]
else runCreateProcessQuiet
(shell (tarballDir </> "install.sh"))
, testCase "daml version" $ callProcessQuiet damlName ["version"]
, testCase "daml --help" $ callProcessQuiet damlName ["--help"]
, testCase "daml new --list" $ callProcessQuiet damlName ["new", "--list"]
@ -267,8 +272,9 @@ quickstartTests quickstartDir mvnDir = testGroup "quickstart" $
withCurrentDirectory quickstartDir $
withDevNull $ \devNull -> do
p :: Int <- fromIntegral <$> getFreePort
withCreateProcess ((proc damlName ["sandbox", "--port", show p, "target/daml/iou.dar"]) { std_out = UseHandle devNull }) $
\_ _ _ ph -> race_ (waitForProcess' "sandbox" [] ph) $ do
let sandboxProc = (proc damlName ["sandbox", "--port", show p, "target/daml/iou.dar"]) { std_out = UseHandle devNull }
withCreateProcess sandboxProc $
\_ _ _ ph -> race_ (waitForProcess' sandboxProc ph) $ do
waitForConnectionOnPort (threadDelay 100000) p
addr : _ <- getAddrInfo
(Just socketHints)
@ -278,7 +284,7 @@ quickstartTests quickstartDir mvnDir = testGroup "quickstart" $
(socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr))
close
(\s -> connect s (addrAddress addr))
-- waitForProcess' will block on Windows so we explicitely kill the process.
-- waitForProcess' will block on Windows so we explicitly kill the process.
terminateProcess ph
] <>
-- The mvn tests seem to fail on Windows for some reason so for now we disable them.
@ -296,12 +302,14 @@ quickstartTests quickstartDir mvnDir = testGroup "quickstart" $
withDevNull $ \devNull1 ->
withDevNull $ \devNull2 -> do
sandboxPort :: Int <- fromIntegral <$> getFreePort
withCreateProcess ((proc damlName ["sandbox", "--", "--port", show sandboxPort, "--", "--scenario", "Main:setup", "target/daml/iou.dar"]) { std_out = UseHandle devNull1 }) $
\_ _ _ ph -> race_ (waitForProcess' "sandbox" [] ph) $ do
let sandboxProc = (proc damlName ["sandbox", "--", "--port", show sandboxPort, "--", "--scenario", "Main:setup", "target/daml/iou.dar"]) { std_out = UseHandle devNull1 }
withCreateProcess sandboxProc $
\_ _ _ ph -> race_ (waitForProcess' sandboxProc ph) $ do
waitForConnectionOnPort (threadDelay 500000) sandboxPort
restPort :: Int <- fromIntegral <$> getFreePort
withCreateProcess ((proc "mvn" [mvnRepoFlag, "-Dledgerport=" <> show sandboxPort, "-Drestport=" <> show restPort, "exec:java@run-quickstart"]) { std_out = UseHandle devNull2 }) $
\_ _ _ ph -> race_ (waitForProcess' "mvn" [] ph) $ do
let mavenProc = (proc "mvn" [mvnRepoFlag, "-Dledgerport=" <> show sandboxPort, "-Drestport=" <> show restPort, "exec:java@run-quickstart"]) { std_out = UseHandle devNull2 }
withCreateProcess mavenProc $
\_ _ _ ph -> race_ (waitForProcess' mavenProc ph) $ do
let url = "http://localhost:" <> show restPort <> "/iou"
waitForHttpServer (threadDelay 1000000) url
threadDelay 5000000
@ -311,9 +319,9 @@ quickstartTests quickstartDir mvnDir = testGroup "quickstart" $
resp <- httpLbs req manager
responseBody resp @?=
"{\"0\":{\"issuer\":\"EUR_Bank\",\"owner\":\"Alice\",\"currency\":\"EUR\",\"amount\":100.0,\"observers\":[]}}"
-- waitForProcess' will block on Windows so we explicitely kill the process.
-- waitForProcess' will block on Windows so we explicitly kill the process.
terminateProcess ph
-- waitForProcess' will block on Windows so we explicitely kill the process.
-- waitForProcess' will block on Windows so we explicitly kill the process.
terminateProcess ph
]
where
@ -361,13 +369,18 @@ damlInstallerName
| otherwise = "daml"
-- | Like call process but hides stdout.
callProcessQuiet :: FilePath -> [String] -> IO ()
callProcessQuiet cmd args = do
(exit, _out, err) <- readCreateProcessWithExitCode (proc cmd args) ""
runCreateProcessQuiet :: CreateProcess -> IO ()
runCreateProcessQuiet createProcess = do
(exit, _out, err) <- readCreateProcessWithExitCode createProcess ""
hPutStr stderr err
unless (exit == ExitSuccess) $ throwIO $ ProcessExitFailure exit cmd args
unless (exit == ExitSuccess) $ throwIO $ ProcessExitFailure exit createProcess
data ProcessExitFailure = ProcessExitFailure !ExitCode !FilePath ![String]
-- | Like call process but hides stdout.
callProcessQuiet :: FilePath -> [String] -> IO ()
callProcessQuiet cmd args =
runCreateProcessQuiet (proc cmd args)
data ProcessExitFailure = ProcessExitFailure !ExitCode !CreateProcess
deriving (Show, Typeable)
instance Exception ProcessExitFailure
@ -396,10 +409,10 @@ socketHints :: AddrInfo
socketHints = defaultHints { addrFlags = [AI_NUMERICHOST, AI_NUMERICSERV], addrSocketType = Stream }
-- | Like waitForProcess' but throws ProcessExitFailure if the process fails to start.
waitForProcess' :: String -> [String] -> ProcessHandle -> IO ()
waitForProcess' cmd args ph = do
waitForProcess' :: CreateProcess -> ProcessHandle -> IO ()
waitForProcess' cp ph = do
e <- waitForProcess ph
unless (e == ExitSuccess) $ throwIO $ ProcessExitFailure e cmd args
unless (e == ExitSuccess) $ throwIO $ ProcessExitFailure e cp
-- | Getting a dev-null handle in a cross-platform way seems to be somewhat tricky so we instead
-- use a temporary file.

View File

@ -1,5 +1,5 @@
:: Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
:: SPDX-License-Identifier: Apache-2.0
%~dp0daml\daml install %~dp0 --activate
%~dp0daml\daml install %~dp0 --install-assistant=yes