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 {
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
trait AbstractTriggerDaoFixture extends SuiteMixin {
self: Suite =>
@ -553,6 +588,7 @@ trait TriggerDaoOracleFixture
// TODO: rename once Oracle and Postgres migrations are completed
trait TriggerServiceWithCantonFixture
extends AbstractTriggerDaoCantonFixture
with ToxiSandboxWithCantonFixture
with AbstractAuthFixture {
self: Suite =>
@ -581,8 +617,7 @@ trait TriggerServiceWithCantonFixture
val host = InetAddress.getLoopbackAddress
val ledgerConfig = LedgerConfig(
host.getHostName,
// TODO: set this to be the toxi proxy port in a future PR
suiteResource.value.head.value,
toxiSandboxPort.value,
TimeProviderType.Static,
java.time.Duration.ofSeconds(30),
Cli.DefaultMaxInboundMessageSize,

View File

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