-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the port file and dynamic port generation in client/server tests. (…
…#10604) * Use the port file and dynamic port generation in client/server tests. This creates a runner named `runner_with_port_file` which knows how to interpolate two variables, `%PORT_FILE%` and `%PORT%`. This allows us to use the `port-file` argument to the kvutils runner rather than hard-coding a port for conformance tests. For now, we only use this for generating the kvutils reference ledger export. CHANGELOG_BEGIN CHANGELOG_END * Simplify the runner_with_port_file considerably. It doesn't need to check if the port is open; we trust that the process will do it. This also makes sure the port file will be cleaned up, and reduces the number of dependencies by making use of more functions in `extra`. * Simplify port file generation in the new client-server runner. Co-authored-by: Moritz Kiefer <[email protected]> * Simplify the runner_with_port_file further. This doesn't need to work if the server doesn't take a port file. Co-authored-by: Moritz Kiefer <[email protected]>
- Loading branch information
1 parent
fb19bcb
commit 3227e86
Showing
3 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
bazel_tools/client_server/runner_with_port_file/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
load("//bazel_tools:haskell.bzl", "da_haskell_binary") | ||
|
||
da_haskell_binary( | ||
name = "runner_with_port_file", | ||
srcs = ["Main.hs"], | ||
hackage_deps = [ | ||
"base", | ||
"directory", | ||
"extra", | ||
"filepath", | ||
"process", | ||
"temporary", | ||
], | ||
visibility = ["//visibility:public"], | ||
deps = ["//libs-haskell/da-hs-base"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
module Main (main) where | ||
|
||
import Control.Monad (unless) | ||
import Data.List.Extra (replace, splitOn, stripInfix) | ||
import Data.Maybe (isJust) | ||
import System.Environment (getArgs) | ||
import System.FilePath ((</>)) | ||
import System.Process (callProcess, proc, withCreateProcess) | ||
import System.Exit (exitFailure) | ||
import System.IO (hPutStrLn, stderr) | ||
import System.IO.Temp (withSystemTempDirectory) | ||
|
||
import DA.PortFile | ||
|
||
main :: IO () | ||
main = do | ||
[clientExe, clientArgs, serverExe, serverArgs, _] <- getArgs | ||
let splitArgs = filter (/= "") . splitOn " " | ||
let splitServerArgs = splitArgs serverArgs | ||
let splitClientArgs = splitArgs clientArgs | ||
unless (any (isJust . stripInfix "%PORT_FILE%") splitServerArgs) $ do | ||
hPutStrLn stderr "No server parameters accept a port file." | ||
exitFailure | ||
withSystemTempDirectory "runner" $ \tempDir -> do | ||
let portFile = tempDir </> "portfile" | ||
let interpolatedServerArgs = map (replace "%PORT_FILE%" portFile) splitServerArgs | ||
let serverProc = proc serverExe interpolatedServerArgs | ||
withCreateProcess serverProc $ \_stdin _stdout _stderr _ph -> do | ||
port <- readPortFile maxRetries portFile | ||
let interpolatedClientArgs = map (replace "%PORT%" (show port)) splitClientArgs | ||
callProcess clientExe interpolatedClientArgs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters