toxi proxy trigger service Canton test migration (#16829)

This commit is contained in:
Carl Pulley 2023-05-10 14:01:31 +01:00 committed by GitHub
parent 8fb76c5b63
commit 3d8033ddc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 53 deletions

View File

@ -418,7 +418,7 @@ trait ToxiproxyFixture extends BeforeAndAfterAll with AkkaBeforeAndAfterAll {
} }
} }
// TODO: migrate this code in a future PR // TODO: delete once Oracle and Postgres migrations are completed
trait ToxiSandboxFixture extends BeforeAndAfterAll with ToxiproxyFixture with SandboxFixture { trait ToxiSandboxFixture extends BeforeAndAfterAll with ToxiproxyFixture with SandboxFixture {
self: Suite => self: Suite =>
@ -450,6 +450,41 @@ trait ToxiSandboxFixture extends BeforeAndAfterAll with ToxiproxyFixture with Sa
} }
} }
// TODO: rename once Oracle and Postgres migrations are completed
trait ToxiSandboxWithCantonFixture
extends BeforeAndAfterAll
with ToxiproxyFixture
with CantonFixture {
self: Suite =>
protected def toxiSandboxPort: Port = resource._1
protected def toxiSandboxProxy: Proxy = resource._2
private var resource: (Port, Proxy) = _
override protected def beforeAll(): Unit = {
super.beforeAll()
val host = InetAddress.getLoopbackAddress
val lock = LockedFreePort.find()
val port = lock.port
val proxy = toxiproxyClient.createProxy(
"sandbox",
s"${host.getHostName}:$port",
s"${host.getHostName}:${suiteResource.value.head}",
)
lock.unlock()
resource = (port, proxy)
}
override protected def afterAll(): Unit = {
toxiSandboxProxy.delete()
super.afterAll()
}
}
// TODO: delete once Oracle and Postgres migrations are completed // TODO: delete once Oracle and Postgres migrations are completed
trait AbstractTriggerDaoFixture extends SuiteMixin { trait AbstractTriggerDaoFixture extends SuiteMixin {
self: Suite => self: Suite =>
@ -553,6 +588,7 @@ trait TriggerDaoOracleFixture
// TODO: rename once Oracle and Postgres migrations are completed // TODO: rename once Oracle and Postgres migrations are completed
trait TriggerServiceWithCantonFixture trait TriggerServiceWithCantonFixture
extends AbstractTriggerDaoCantonFixture extends AbstractTriggerDaoCantonFixture
with ToxiSandboxWithCantonFixture
with AbstractAuthFixture { with AbstractAuthFixture {
self: Suite => self: Suite =>
@ -581,8 +617,7 @@ trait TriggerServiceWithCantonFixture
val host = InetAddress.getLoopbackAddress val host = InetAddress.getLoopbackAddress
val ledgerConfig = LedgerConfig( val ledgerConfig = LedgerConfig(
host.getHostName, host.getHostName,
// TODO: set this to be the toxi proxy port in a future PR toxiSandboxPort.value,
suiteResource.value.head.value,
TimeProviderType.Static, TimeProviderType.Static,
java.time.Duration.ofSeconds(30), java.time.Duration.ofSeconds(30),
Cli.DefaultMaxInboundMessageSize, Cli.DefaultMaxInboundMessageSize,

View File

@ -1337,57 +1337,55 @@ trait AbstractTriggerServiceTestWithCanton extends AbstractTriggerServiceTestHel
} yield succeed } yield succeed
} }
// TODO: complete refactor of toxi proxy test in a future PR it should "restart trigger on initialization failure due to failed connection" taggedAs availabilitySecurity
// it should "restart trigger on initialization failure due to failed connection" taggedAs availabilitySecurity .setHappyCase(
// .setHappyCase( "A failed ledger connection will start the trigger later"
// "A failed ledger connection will start the trigger later" ) inClaims withTriggerService(
// ) inClaims withTriggerService( List(dar)
// List(dar) ) { uri: Uri =>
// ) { uri: Uri => for {
// for { client <- defaultLedgerClient()
// client <- defaultLedgerClient() party <- allocateParty(client)
// party <- allocateParty(client) // Simulate a failed ledger connection which will prevent triggers from initializing.
// // Simulate a failed ledger connection which will prevent triggers from initializing. _ <- Future(toxiSandboxProxy.disable())
// _ <- Future(toxiSandboxProxy.disable()) resp <- startTrigger(uri, s"$testPkgId:TestTrigger:trigger", party)
// resp <- startTrigger(uri, s"$testPkgId:TestTrigger:trigger", party) // The start request should succeed and an entry should be added to the running trigger store,
// // The start request should succeed and an entry should be added to the running trigger store, // even though the trigger will not be able to start.
// // even though the trigger will not be able to start. partyTrigger <- parseTriggerId(resp)
// partyTrigger <- parseTriggerId(resp) _ <- assertTriggerIds(uri, party, Vector(partyTrigger))
// _ <- assertTriggerIds(uri, party, Vector(partyTrigger)) // Check the log for an initialization failure.
// // Check the log for an initialization failure. _ <- assertTriggerStatus(partyTrigger, _ should contain("stopped: initialization failure"))
// _ <- assertTriggerStatus(partyTrigger, _ should contain("stopped: initialization failure")) // Finally establish the connection and check that the trigger eventually starts.
// // Finally establish the connection and check that the trigger eventually starts. _ <- Future(toxiSandboxProxy.enable())
// _ <- Future(toxiSandboxProxy.enable()) _ <- assertTriggerStatus(partyTrigger, _.last should ===("running"))
// _ <- assertTriggerStatus(partyTrigger, _.last should ===("running")) } yield succeed
// } yield succeed }
// }
// TODO: complete refactor of toxi proxy test in a future PR it should "restart trigger on run-time failure due to dropped connection" taggedAs availabilitySecurity
// it should "restart trigger on run-time failure due to dropped connection" taggedAs availabilitySecurity .setHappyCase(
// .setHappyCase( "A connection error during runtime of a trigger will restart the trigger"
// "A connection error during runtime of a trigger will restart the trigger" ) inClaims withTriggerService(
// ) inClaims withTriggerService( List(dar)
// List(dar) ) { uri: Uri =>
// ) { uri: Uri => // Simulate the ledger being briefly unavailable due to network connectivity loss.
// // Simulate the ledger being briefly unavailable due to network connectivity loss. // We continually restart the trigger until the connection returns.
// // We continually restart the trigger until the connection returns. for {
// for { client <- defaultLedgerClient()
// client <- defaultLedgerClient() party <- allocateParty(client)
// party <- allocateParty(client) // Request a trigger be started for party.
// // Request a trigger be started for party. resp <- startTrigger(uri, s"$testPkgId:TestTrigger:trigger", party)
// resp <- startTrigger(uri, s"$testPkgId:TestTrigger:trigger", party) partyTrigger <- parseTriggerId(resp)
// partyTrigger <- parseTriggerId(resp) _ <- assertTriggerIds(uri, party, Vector(partyTrigger))
// _ <- assertTriggerIds(uri, party, Vector(partyTrigger)) // Proceed when it's confirmed to be running.
// // Proceed when it's confirmed to be running. _ <- assertTriggerStatus(partyTrigger, _.last should ===("running"))
// _ <- assertTriggerStatus(partyTrigger, _.last should ===("running")) // Simulate brief network connectivity loss and observe the trigger fail.
// // Simulate brief network connectivity loss and observe the trigger fail. _ <- Future(toxiSandboxProxy.disable())
// _ <- Future(toxiSandboxProxy.disable()) _ <- assertTriggerStatus(partyTrigger, _ should contain("stopped: runtime failure"))
// _ <- assertTriggerStatus(partyTrigger, _ should contain("stopped: runtime failure")) // Finally check the trigger is restarted after the connection returns.
// // Finally check the trigger is restarted after the connection returns. _ <- Future(toxiSandboxProxy.enable())
// _ <- Future(toxiSandboxProxy.enable()) _ <- assertTriggerStatus(partyTrigger, _.last should ===("running"))
// _ <- assertTriggerStatus(partyTrigger, _.last should ===("running")) } yield succeed
// } yield succeed }
// }
it should "restart triggers with initialization errors" taggedAs availabilitySecurity it should "restart triggers with initialization errors" taggedAs availabilitySecurity
.setHappyCase( .setHappyCase(