Skip to content

Commit e7960a5

Browse files
Avoid using the same database in tests that start a local validator participant (#3177)
Fixes DACH-NY/cn-test-failures#6394 ...but also does some refactoring to make it more ergonomic and (hopefully) a bit less error-prone to write tests that use a throwaway validator participant. Signed-off-by: Martin Florian <[email protected]>
1 parent 4198469 commit e7960a5

File tree

9 files changed

+94
-184
lines changed

9 files changed

+94
-184
lines changed

apps/app/src/main/scala/org/lfdecentralizedtrust/splice/config/ConfigTransforms.scala

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -671,17 +671,6 @@ object ConfigTransforms {
671671
)
672672
}
673673

674-
def bumpSelfHostedParticipantPortsBy(bump: Int): ConfigTransform = {
675-
val transforms = Seq(
676-
updateAllValidatorConfigs { case (name, config) =>
677-
if (name.startsWith("sv")) config
678-
else
679-
config.focus(_.participantClient).modify(portTransform(bump, _))
680-
}
681-
)
682-
transforms.foldLeft((c: SpliceConfig) => c)((f, tf) => f compose tf)
683-
}
684-
685674
def withBftSequencer(config: SvAppBackendConfig): SvAppBackendConfig =
686675
config
687676
.focus(_.localSynchronizerNode)

apps/app/src/test/resources/include/self-hosted-sv-participant-postgres-storage.conf

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/app/src/test/resources/include/self-hosted-validator-disable-json-api.conf

Lines changed: 0 additions & 1 deletion
This file was deleted.

apps/app/src/test/resources/include/self-hosted-validator-participant-postgres-storage.conf

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/app/src/test/resources/include/validator-participant.conf

Lines changed: 0 additions & 53 deletions
This file was deleted.

apps/app/src/test/scala/org/lfdecentralizedtrust/splice/integration/EnvironmentDefinition.scala

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.lfdecentralizedtrust.splice.integration
22

3-
import better.files.{File, Resource}
3+
import better.files.{File, Resource, *}
44
import com.digitalasset.canton.admin.api.client.data.User
55
import com.digitalasset.canton.config.CantonRequireTypes.InstanceName
66
import com.digitalasset.canton.config.RequireTypes.{NonNegativeLong, NonNegativeNumeric}
@@ -80,6 +80,14 @@ case class EnvironmentDefinition(
8080
.copy(setup = _ => ())
8181
}
8282

83+
def withStandardSetup: EnvironmentDefinition =
84+
this
85+
.withAllocatedUsers()
86+
.withInitializedNodes()
87+
.withTrafficTopupsEnabled
88+
.withInitialPackageVersions
89+
.withEagerAppActivityMarkerConversion
90+
8391
def withAllocatedUsers(
8492
extraIgnoredSvPrefixes: Seq[String] = Seq.empty,
8593
extraIgnoredValidatorPrefixes: Seq[String] = Seq.empty,
@@ -478,21 +486,29 @@ object EnvironmentDefinition extends CommonAppInstanceReferences {
478486

479487
// Prefer this to `4Svs` for better test performance (unless your really need >1 SV of course).
480488
def simpleTopology1Sv(testName: String): EnvironmentDefinition = {
481-
fromResources(Seq("simple-topology-1sv.conf"), testName)
482-
.withAllocatedUsers()
483-
.withInitializedNodes()
484-
.withTrafficTopupsEnabled
485-
.withInitialPackageVersions
486-
.withEagerAppActivityMarkerConversion
489+
fromResources(Seq("simple-topology-1sv.conf"), testName).withStandardSetup
487490
}
488491

489492
def simpleTopology4Svs(testName: String): EnvironmentDefinition = {
490-
fromResources(Seq("simple-topology.conf"), testName)
491-
.withAllocatedUsers()
492-
.withInitializedNodes()
493-
.withTrafficTopupsEnabled
494-
.withInitialPackageVersions
495-
.withEagerAppActivityMarkerConversion
493+
fromResources(Seq("simple-topology.conf"), testName).withStandardSetup
494+
}
495+
496+
def simpleTopology1SvWithLocalValidator(testName: String): EnvironmentDefinition = {
497+
val testResourcesPath: File = "apps" / "app" / "src" / "test" / "resources"
498+
fromFiles(
499+
testName,
500+
testResourcesPath / "simple-topology-1sv.conf",
501+
testResourcesPath / "local-validator-node" / "validator-app" / "app.conf",
502+
).withStandardSetup.withManualStart
503+
}
504+
505+
def simpleTopology4SvsWithLocalValidator(testName: String): EnvironmentDefinition = {
506+
val testResourcesPath: File = "apps" / "app" / "src" / "test" / "resources"
507+
fromFiles(
508+
testName,
509+
testResourcesPath / "simple-topology.conf",
510+
testResourcesPath / "local-validator-node" / "validator-app" / "app.conf",
511+
).withStandardSetup.withManualStart
496512
}
497513

498514
def simpleTopology1SvWithSimTime(testName: String): EnvironmentDefinition =
Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
package org.lfdecentralizedtrust.splice.integration.tests
22

3-
import better.files.File
43
import org.apache.pekko.http.scaladsl.model.Uri
5-
import org.lfdecentralizedtrust.splice.config.ConfigTransforms
64
import org.lfdecentralizedtrust.splice.integration.EnvironmentDefinition
75
import org.lfdecentralizedtrust.splice.integration.tests.SpliceTests.IntegrationTest
8-
import org.lfdecentralizedtrust.splice.util.{ProcessTestUtil, WalletTestUtil}
6+
import org.lfdecentralizedtrust.splice.util.{ProcessTestUtil, StandaloneCanton, WalletTestUtil}
97
import org.lfdecentralizedtrust.splice.unit.http.{
108
SystemProperties,
119
SystemPropertiesSupport,
1210
TinyProxySupport,
1311
}
1412

15-
import scala.concurrent.duration.*
16-
1713
class ValidatorProxyIntegrationTest
1814
extends IntegrationTest
1915
with WalletTestUtil
2016
with ProcessTestUtil
17+
with StandaloneCanton
2118
with TinyProxySupport
2219
with SystemPropertiesSupport {
20+
21+
override def dbsSuffix = "validator_proxy"
22+
val dbName = s"participant_alice_validator_${dbsSuffix}"
23+
override def usesDbs = Seq(dbName) ++ super.usesDbs
24+
25+
// Can sometimes be unhappy when doing funky `withCanton` things; disabling them for simplicity
2326
override protected def runTokenStandardCliSanityCheck: Boolean = false
2427
override protected def runUpdateHistorySanityCheck: Boolean = false
2528

29+
override def environmentDefinition: SpliceEnvironmentDefinition = {
30+
EnvironmentDefinition.simpleTopology1SvWithLocalValidator(this.getClass.getSimpleName)
31+
}
32+
2633
"validator should start and tap, using http forward proxy" in { implicit env =>
2734
val host = "127.0.0.1"
2835
initDsoWithSv1Only()
@@ -37,22 +44,19 @@ class ValidatorProxyIntegrationTest
3744
.set("https.nonProxyHosts", "")
3845
withProperties(props) {
3946
withCanton(
40-
cantonArgs,
41-
cantonExtraConfig,
47+
Seq(
48+
testResourcesPath / "standalone-participant-extra.conf"
49+
),
50+
Seq.empty,
4251
"validator-proxy-test",
52+
"EXTRA_PARTICIPANT_ADMIN_USER" -> aliceValidatorLocalBackend.config.ledgerApiUser,
53+
"EXTRA_PARTICIPANT_DB" -> dbName,
4354
"JAVA_TOOL_OPTIONS" -> props.toJvmOptionString,
4455
) {
45-
aliceValidatorBackend.start()
46-
clue("Wait for validator initialization") {
47-
// Need to wait for the participant node to startup for the user allocation to go through
48-
eventuallySucceeds(timeUntilSuccess = 120.seconds) {
49-
EnvironmentDefinition.withAllocatedValidatorUser(aliceValidatorBackend)
50-
}
51-
aliceValidatorBackend.waitForInitialization()
52-
}
56+
aliceValidatorLocalBackend.startSync()
5357
actAndCheck(
5458
"Onboard wallet user",
55-
onboardWalletUser(aliceWalletClient, aliceValidatorBackend),
59+
onboardWalletUser(aliceWalletClient, aliceValidatorLocalBackend),
5660
)(
5761
"We can tap and list",
5862
_ => {
@@ -75,12 +79,12 @@ class ValidatorProxyIntegrationTest
7579
) shouldBe true
7680
proxy.proxiedConnectRequest(
7781
host,
78-
aliceValidatorBackend.config.clientAdminApi.port.unwrap,
82+
aliceValidatorLocalBackend.config.clientAdminApi.port.unwrap,
7983
) shouldBe true
8084

8185
proxy.proxiedConnectRequest(
8286
host,
83-
aliceValidatorBackend.participantClient.config.ledgerApi.port.unwrap,
87+
aliceValidatorLocalBackend.participantClient.config.ledgerApi.port.unwrap,
8488
) shouldBe true
8589

8690
val sequencerPort = Uri(
@@ -99,36 +103,4 @@ class ValidatorProxyIntegrationTest
99103
}
100104
}
101105
}
102-
103-
val includeTestResourcesPath: File = testResourcesPath / "include"
104-
105-
val cantonArgs: Seq[File] = Seq(
106-
includeTestResourcesPath / "validator-participant.conf",
107-
includeTestResourcesPath / "self-hosted-validator-disable-json-api.conf",
108-
includeTestResourcesPath / "self-hosted-validator-participant-postgres-storage.conf",
109-
includeTestResourcesPath / "storage-postgres.conf",
110-
)
111-
val cantonExtraConfig: Seq[String] =
112-
Seq(
113-
"canton.participants.validatorParticipant.ledger-api.port=7501",
114-
"canton.participants.validatorParticipant.admin-api.port=7502",
115-
)
116-
val ParticipantLedgerPort = 7501
117-
val ParticipantAdminPort = 7502
118-
override protected def extraPortsToWaitFor: Seq[(String, Int)] = Seq(
119-
("ParticipantLedgerApi", ParticipantLedgerPort),
120-
("ParticipantAdminApi", ParticipantAdminPort),
121-
)
122-
123-
override def environmentDefinition: SpliceEnvironmentDefinition = {
124-
EnvironmentDefinition
125-
.simpleTopology1Sv(this.getClass.getSimpleName)
126-
.withPreSetup(_ => ())
127-
.addConfigTransforms((_, conf) =>
128-
ConfigTransforms.bumpSelfHostedParticipantPortsBy(2000)(conf)
129-
)
130-
// Do not allocate validator users here, as we deal with all of them manually
131-
.withAllocatedUsers(extraIgnoredValidatorPrefixes = Seq(""))
132-
.withManualStart
133-
}
134106
}

0 commit comments

Comments
 (0)