Skip to content

Commit

Permalink
Use canton sandbox in script+trigger compat tests (digital-asset#12514)
Browse files Browse the repository at this point in the history
Part of digital-asset#11831. This kills another two uses of sandbox-kv.

Also fixes a daml-helper issue where we weren't passing "localhost" to the
ledger flags, so it was complaining about starting outside of a project.

changelog_begin
changelog_end
  • Loading branch information
sofiafaro-da authored Jan 20, 2022
1 parent 9c03e79 commit a5f56e0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion bazel_tools/client_server/client_server_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def client_server_test(
server = None,
server_args = [],
server_files = [],
server_files_prefix = "",
data = [],
**kwargs):
"""Create a client-server test.
Expand Down Expand Up @@ -65,7 +66,7 @@ client=$$(canonicalize_rlocation $$(get_exe $(rootpaths {client})))
server=$$(canonicalize_rlocation $$(get_exe $(rootpaths {server})))
server_args="{server_args}"
for file in {server_files}; do
server_args+=" $$(canonicalize_rlocation $$file)"
server_args+=" {server_files_prefix}$$(canonicalize_rlocation $$file)"
done
client_args="$$@"
Expand All @@ -86,6 +87,7 @@ $$runner $$client "$$client_args" $$server "$$server_args" "$$runner_args"
server = server,
server_args = _escape_args(server_args),
server_files = _escape_args(server_files),
server_files_prefix = server_files_prefix,
),
**kwargs
)
3 changes: 2 additions & 1 deletion compatibility/bazel_tools/daml_script/daml_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ def daml_script_test(compiler_version, runner_version):
runner = "//bazel_tools/client_server:runner",
runner_args = ["6865"],
server = daml_runner,
server_args = ["sandbox-kv" if versions.is_at_least("2.0.0", runner_version) else "sandbox"],
server_args = ["sandbox"],
server_files = [
"$(rootpath {})".format(compiled_dar),
],
server_files_prefix = "--dar=" if versions.is_at_least("2.0.0", runner_version) else "",
tags = ["exclusive"],
)
3 changes: 2 additions & 1 deletion compatibility/bazel_tools/daml_trigger/daml_trigger.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ chmod +x $(OUTS)
runner = "//bazel_tools/client_server:runner",
runner_args = ["6865"],
server = daml_runner,
server_args = ["sandbox-kv" if versions.is_at_least("2.0.0", runner_version) else "sandbox"],
server_args = ["sandbox"],
server_files = [
"$(rootpath {})".format(compiled_dar),
],
server_files_prefix = "--dar=" if versions.is_at_least("2.0.0", runner_version) else "",
tags = ["exclusive"],
)
7 changes: 7 additions & 0 deletions daml-assistant/daml-helper/src/DA/Daml/Helper/Ledger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module DA.Daml.Helper.Ledger (
LedgerFlags(..),
RemoteDalf(..),
defaultLedgerFlags,
sandboxLedgerFlags,
getDefaultArgs,
LedgerApi(..),
L.ClientSSLConfig(..),
Expand Down Expand Up @@ -103,6 +104,12 @@ defaultLedgerFlags api = LedgerFlags
, fMaxReceiveLengthM = Nothing
}

sandboxLedgerFlags :: Int -> LedgerFlags
sandboxLedgerFlags port = (defaultLedgerFlags Grpc)
{ fHostM = Just "localhost"
, fPortM = Just port
}

data LedgerArgs = LedgerArgs
{ api :: LedgerApi
, sslConfigM :: Maybe L.ClientSSLConfig
Expand Down
2 changes: 1 addition & 1 deletion daml-assistant/daml-helper/src/DA/Daml/Helper/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ runCommand = \case
sandboxPort <- readPortFileWith decodeCantonSandboxPort (unsafeProcessHandle ph) maxRetries cantonPortFile
putStrLn ("Listening at port " <> show sandboxPort)
forM_ darPaths $ \darPath -> do
runLedgerUploadDar ((defaultLedgerFlags Grpc) {fPortM = Just sandboxPort}) (Just darPath)
runLedgerUploadDar (sandboxLedgerFlags sandboxPort) (Just darPath)
whenJust portFileM $ \portFile -> do
putStrLn ("Writing ledger API port to " <> portFile)
writeFileUTF8 portFile (show sandboxPort)
Expand Down
6 changes: 3 additions & 3 deletions daml-assistant/daml-helper/src/DA/Daml/Helper/Start.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ withSandbox StartOptions{..} darPath scenarioArgs sandboxArgs kont =
withCantonSandbox cantonOptions sandboxArgs $ \ph -> do
putStrLn "Waiting for canton sandbox to start."
sandboxPort <- readPortFileWith decodeCantonSandboxPort (unsafeProcessHandle ph) maxRetries portFile
runLedgerUploadDar ((defaultLedgerFlags Grpc) {fPortM = Just sandboxPort}) (Just darPath)
runLedgerUploadDar (sandboxLedgerFlags sandboxPort) (Just darPath)
kont ph (SandboxPort sandboxPort)

oldSandbox sandbox = withTempDir $ \tempDir -> do
Expand Down Expand Up @@ -268,9 +268,9 @@ runStart startOptions@StartOptions{..} =
whenJust mbOutputPath $ \_outputPath -> do
runCodegen lang []
doReset (SandboxPort sandboxPort) =
runLedgerReset $ (defaultLedgerFlags Grpc) {fPortM = Just sandboxPort}
runLedgerReset (sandboxLedgerFlags sandboxPort)
doUploadDar darPath (SandboxPort sandboxPort) =
runLedgerUploadDar ((defaultLedgerFlags Grpc) {fPortM = Just sandboxPort}) (Just darPath)
runLedgerUploadDar (sandboxLedgerFlags sandboxPort) (Just darPath)
listenForKeyPress projectConfig darPath sandboxPort runInitScript = do
hSetBuffering stdin NoBuffering
void $
Expand Down

0 comments on commit a5f56e0

Please sign in to comment.