Skip to content

Commit

Permalink
Migrate migration tests to Sandbox on X (#12407)
Browse files Browse the repository at this point in the history
* Migrate migration tests to Sandbox on X

This PR switches the data continuity tests for Sandbox from Sandbox
classic to Sandbox on X for newer versions. (Data continuity between
the two is expected and desired).

changelog_begin
changelog_end

* fmt

changelog_begin
changelog_end

* fix process mgmt

changelog_begin
changelog_end

* .
  • Loading branch information
cocreature authored Jan 17, 2022
1 parent 903f473 commit 8baaf72
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
35 changes: 32 additions & 3 deletions compatibility/sandbox-migration/runner/Migration/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Migration.Runner (main) where
-- 6. Stop postgres.

import Control.Exception
import Control.Lens
import Control.Monad
import Data.Either
import Data.List
Expand All @@ -26,6 +27,8 @@ import Sandbox
( createSandbox
, defaultSandboxConf
, destroySandbox
, maxRetries
, readPortFile
, sandboxPort
, SandboxConfig(..)
)
Expand Down Expand Up @@ -78,6 +81,10 @@ main = do
runTest appendOnly jdbcUrl platformAssistants
(ProposeAccept.test step modelDar `interleave` KeyTransfer.test step modelDar `interleave` Divulgence.test step modelDar)


supportsSandboxOnX :: SemVer.Version -> Bool
supportsSandboxOnX v = v == SemVer.initial || v >= (SemVer.initial & SemVer.major .~ 2)

supportsAppendOnly :: SemVer.Version -> Bool
supportsAppendOnly v = v == SemVer.initial
-- Note: until the append-only migration is frozen, only the head version of it should be used
Expand Down Expand Up @@ -108,11 +115,32 @@ assistantVersion path =

withSandbox :: AppendOnly -> FilePath -> T.Text -> (Int -> IO a) -> IO a
withSandbox (AppendOnly appendOnly) assistant jdbcUrl f =
withTempFile $ \portFile ->
bracket (createSandbox portFile stderr sandboxConfig) destroySandbox $ \resource ->
f (sandboxPort resource)
withTempDir $ \dir ->
withSandbox' (dir </> "portfile") f
where
withSandbox' portFile f
| supportsSandboxOnX version = withSandboxOnX portFile f
| otherwise = bracket (createSandbox portFile stderr sandboxConfig) destroySandbox (\r -> f (sandboxPort r))
version = assistantVersion assistant
-- The CLI of sandbox on x is not compatible with Sandbox
-- so rather than using the utilities from the Sandbox module
-- we spin it up directly.
withSandboxOnX portFile f = do
let args =
[ "--contract-id-seeding=testing-weak", "--enable-conflict-checking", "--mutable-contract-state-cache"
, "--ledger-id=" <> ledgerid
, "--participant=participant-id=sandbox-participant,port=0,port-file=" <> portFile <> ",server-jdbc-url=" <> T.unpack jdbcUrl <> ",ledgerid=" <> ledgerid
]
-- Locating sandbox on x relative to the assistant is easier than making
-- the bash script make the decision on whether it needs to pass in
-- the assistant or sandbox on x.
bracket (createProcess (proc (takeDirectory assistant </> "sandbox-on-x") args) { create_group = True })
-- This is a shell script so we kill the whole process group.
(\process@(_, _, _, ph) -> interruptProcessGroupOf ph >> cleanupProcess process >> void (waitForProcess ph))
$ \_ -> do
port <- readPortFile maxRetries portFile
f port
ledgerid = "myledger"
sandboxConfig = defaultSandboxConf
{ sandboxBinary = assistant
, sandboxArgs =
Expand All @@ -121,4 +149,5 @@ withSandbox (AppendOnly appendOnly) assistant jdbcUrl f =
, "--contract-id-seeding=testing-weak"
] <>
[ "--enable-append-only-schema" | supportsAppendOnly version && appendOnly ]
, mbLedgerId = Just ledgerid
}
2 changes: 1 addition & 1 deletion compatibility/sandbox-migration/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---
set -euox pipefail
set -euo pipefail

RUNNER="$(rlocation $TEST_WORKSPACE/sandbox-migration/sandbox-migration-runner)"
MODEL_DAR="$(rlocation $TEST_WORKSPACE/sandbox-migration/migration-model.dar)"
Expand Down
8 changes: 6 additions & 2 deletions compatibility/sandbox-migration/util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# SPDX-License-Identifier: Apache-2.0

load("@os_info//:os_info.bzl", "is_linux")
load("//bazel_tools:versions.bzl", "versions")

def runfiles(ver):
return ["@daml-sdk-{}//:daml".format(ver)] + (["@daml-sdk-{}//:sandbox-on-x".format(ver)] if versions.is_at_least("2.0.0", ver) else [])

def migration_test(name, versions, tags, quick_tags, **kwargs):
native.sh_test(
Expand All @@ -12,7 +16,7 @@ def migration_test(name, versions, tags, quick_tags, **kwargs):
"//sandbox-migration:sandbox-migration-runner",
"//sandbox-migration:migration-model.dar",
"//sandbox-migration:migration-step",
] + ["@daml-sdk-{}//:daml".format(ver) for ver in versions],
] + [dep for ver in versions for dep in runfiles(ver)],
args = versions,
tags = tags + quick_tags,
**kwargs
Expand All @@ -28,7 +32,7 @@ def migration_test(name, versions, tags, quick_tags, **kwargs):
"//sandbox-migration:sandbox-migration-runner",
"//sandbox-migration:migration-model.dar",
"//sandbox-migration:migration-step",
] + ["@daml-sdk-{}//:daml".format(ver) for ver in versions],
] + [dep for ver in versions for dep in runfiles(ver)],
args = ["--append-only"] + versions,
**kwargs
)

0 comments on commit 8baaf72

Please sign in to comment.