Skip to content

Commit

Permalink
Remove InMemoryKVParticipantState (digital-asset#4674)
Browse files Browse the repository at this point in the history
This removes the sample/reference implementation of kvutils
InMemoryKVParticipantState.
This used to be the only implementation of kvutils, but now with the
simplified kvutils api we have ledger-on-memory and ledger-on-sql.

InMemoryKVParticipantState was also used for the ledger dump utility,
which now uses ledger-on-memory.

* Runner now supports a multi participant configuration
This change removes the "extra participants" config and goes for consistent
participant setup with --participant.

* Run all conformance tests in the repository in verbose mode.

This means we'll print stack traces on error, which should make it
easier to figure out what's going on with flaky tests on CI.

This doesn't change the default for other users of the
ledger-api-test-tool; we just add the flag for:

  - ledger-api-test-tool-on-canton
  - ledger-on-memory
  - ledger-on-sql
  - sandbox




Fixes digital-asset#4225.

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
gerolf-da authored Feb 26, 2020
1 parent 6638e57 commit d617922
Show file tree
Hide file tree
Showing 34 changed files with 397 additions and 1,211 deletions.
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ jobs:
gcloud auth activate-service-account --key-file=$GCS_KEY
export BOTO_CONFIG=/dev/null
bazel build //ledger/api-server-damlonx/reference-v2:reference-ledger-dump
gsutil cp bazel-bin/ledger/api-server-damlonx/reference-v2/reference-ledger-dump.out \
bazel build //ledger/participant-state/kvutils:reference-ledger-dump
gsutil cp bazel-bin/ledger/participant-state/kvutils/reference-ledger-dump.out \
gs://daml-dumps/release/ledger/api-server-damlonx/reference-v2/reference-ledger-dump-$(release_tag)
env:
GOOGLE_APPLICATION_CREDENTIALS_CONTENT: $(GOOGLE_APPLICATION_CREDENTIALS_CONTENT)
Expand Down
10 changes: 6 additions & 4 deletions bazel_tools/client_server/client_server_build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ def _client_server_build_impl(ctx):
outputs = [ctx.outputs.out],
inputs = ctx.files.data,
tools = depset([
ctx.executable._runner,
ctx.executable.runner,
ctx.executable.client,
ctx.executable.server,
]),
command = """
export {output_env}="{output_path}"
{runner} "{client}" "{client_args} {client_files}" "{server}" "{server_args} {server_files}" &> runner.log
{runner} "{client}" "{client_args} {client_files}" "{server}" "{server_args} {server_files}" "{runner_args}" &> runner.log
if [ "$?" -ne 0 ]; then
{cat} runner.log
exit 1
Expand All @@ -22,9 +22,10 @@ def _client_server_build_impl(ctx):
cat = posix.commands["cat"],
output_env = ctx.attr.output_env,
output_path = ctx.outputs.out.path,
runner = ctx.executable._runner.path,
runner = ctx.executable.runner.path,
client = ctx.executable.client.path,
server = ctx.executable.server.path,
runner_args = " ".join(ctx.attr.runner_args),
server_args = " ".join(ctx.attr.server_args),
server_files = " ".join([f.path for f in ctx.files.server_files]),
client_args = " ".join(ctx.attr.client_args),
Expand All @@ -40,12 +41,13 @@ def _client_server_build_impl(ctx):
client_server_build = rule(
implementation = _client_server_build_impl,
attrs = {
"_runner": attr.label(
"runner": attr.label(
cfg = "host",
allow_single_file = True,
executable = True,
default = Label("@//bazel_tools/client_server/runner:runner"),
),
"runner_args": attr.string_list(),
"client": attr.label(
cfg = "target",
executable = True,
Expand Down
12 changes: 8 additions & 4 deletions bazel_tools/client_server/client_server_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def _client_server_test_impl(ctx):
set -eou pipefail
runner=$(rlocation "$TEST_WORKSPACE/{runner}")
runner_args="{runner_args}"
client=$(rlocation "$TEST_WORKSPACE/{client}")
server=$(rlocation "$TEST_WORKSPACE/{server}")
server_args="{server_args}"
Expand All @@ -29,9 +30,10 @@ if [ -z "$client_args" ]; then
done
fi
$runner "$client" "$client_args" "$server" "$server_args"
$runner "$client" "$client_args" "$server" "$server_args" "$runner_args"
""".format(
runner = ctx.executable._runner.short_path,
runner = ctx.executable.runner.short_path,
runner_args = _expand_args(ctx, ctx.attr.runner_args),
client = ctx.executable.client.short_path,
client_args = _expand_args(ctx, ctx.attr.client_args),
client_files = _expand_args(ctx, ctx.attr.client_files),
Expand All @@ -43,7 +45,7 @@ $runner "$client" "$client_args" "$server" "$server_args"
)

runfiles = ctx.runfiles(files = [wrapper], collect_data = True)
runfiles = runfiles.merge(ctx.attr._runner[DefaultInfo].default_runfiles)
runfiles = runfiles.merge(ctx.attr.runner[DefaultInfo].default_runfiles)
runfiles = runfiles.merge(ctx.attr.client[DefaultInfo].default_runfiles)
runfiles = runfiles.merge(ctx.attr.server[DefaultInfo].default_runfiles)

Expand All @@ -58,12 +60,13 @@ client_server_test = rule(
test = True,
executable = True,
attrs = {
"_runner": attr.label(
"runner": attr.label(
cfg = "host",
allow_single_file = True,
executable = True,
default = Label("@//bazel_tools/client_server/runner:runner"),
),
"runner_args": attr.string_list(),
"client": attr.label(
cfg = "target",
executable = True,
Expand Down Expand Up @@ -102,6 +105,7 @@ Example:
```bzl
client_server_test(
name = "my_test",
runner_args = [],
client = ":my_client",
client_args = ["--extra-argument"],
client_files = ["$(rootpath :target-for-client)"]
Expand Down
3 changes: 2 additions & 1 deletion bazel_tools/client_server/runner/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import System.Process
import System.IO.Extra (withTempFile)
import Data.List.Split (splitOn)


main :: IO ()
main = do
[clientExe, clientArgs, serverExe, serverArgs] <- getArgs
[clientExe, clientArgs, serverExe, serverArgs, _runnerArgs] <- getArgs
withTempFile $ \tempFile -> do
let splitArgs = filter (/= "") . splitOn " "
let serverProc = proc serverExe $ ["--port-file", tempFile] <> splitArgs serverArgs
Expand Down
23 changes: 23 additions & 0 deletions bazel_tools/client_server/runner_with_port_check/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2020 The DAML Authors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

load("//bazel_tools:haskell.bzl", "da_haskell_binary")

da_haskell_binary(
name = "runner",
srcs = ["Main.hs"],
hackage_deps = [
"base",
"extra",
"process",
"async",
"text",
"safe",
"split",
"network",
"monad-loops",
"safe-exceptions",
],
visibility = ["//visibility:public"],
deps = ["//libs-haskell/da-hs-base"],
)
39 changes: 39 additions & 0 deletions bazel_tools/client_server/runner_with_port_check/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- Copyright (c) 2020 The DAML Authors. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

module Main(main) where

import System.Environment
import Control.Exception.Safe
import Control.Monad.Loops (untilJust)
import System.Process
import Data.List.Split (splitOn)
import Control.Monad (forM_)
import Network.Socket
import Control.Concurrent

main :: IO ()
main = do
[clientExe, clientArgs, serverExe, serverArgs, runnerArgs] <- getArgs
let splitArgs = filter (/= "") . splitOn " "
let serverProc = proc serverExe (splitArgs serverArgs)
let ports :: [Int] = read <$> splitArgs runnerArgs
withCreateProcess serverProc $ \_stdin _stdout _stderr _ph -> do
forM_ ports $ \port -> waitForConnectionOnPort (threadDelay 500000) port
callProcess clientExe (splitArgs clientArgs)


waitForConnectionOnPort :: IO () -> Int -> IO ()
waitForConnectionOnPort sleep port = do
let hints = defaultHints { addrFlags = [AI_NUMERICHOST, AI_NUMERICSERV], addrSocketType = Stream }
addr : _ <- getAddrInfo (Just hints) (Just "127.0.0.1") (Just $ show port)
untilJust $ do
r <- tryIO $ checkConnection addr
case r of
Left _ -> sleep *> pure Nothing
Right _ -> pure $ Just ()
where
checkConnection addr = bracket
(socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr))
close
(\s -> connect s (addrAddress addr))
13 changes: 9 additions & 4 deletions daml-script/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,20 @@ client_server_test(
client = ":test_client_multi_participant",
client_args = [
"-w",
"--target-port=6865",
"--extra-participant-port=6866",
],
client_files = ["$(rootpath :script-test.dar)"],
data = [":script-test.dar"],
server = "//ledger/api-server-damlonx/reference-v2",
runner = "@//bazel_tools/client_server/runner_with_port_check:runner",
runner_args = [
"6865",
"6866",
],
server = "//ledger/ledger-on-memory:app",
server_args = [
"--port=6865",
"--jdbc-url=jdbc:h2:mem:daml_on_x;db_close_delay=-1;db_close_on_exit=false",
"--extra-participant=second-participant,6866,jdbc:h2:mem:daml_on_x2;db_close_delay=-1;db_close_on_exit=false",
"--participant participant-id=daml_on_x,port=6865",
"--participant participant-id=daml_on_x2,port=6866",
],
server_files = ["$(rootpath :script-test.dar)"],
tags = ["exclusive"],
Expand Down
Loading

0 comments on commit d617922

Please sign in to comment.