Skip to content

Commit

Permalink
Extend ConfigManagementServiceIT with tests on generation checking (#…
Browse files Browse the repository at this point in the history
…9753)

changelog_begin
changelog_end
  • Loading branch information
nmarton-da authored May 20, 2021
1 parent f5c84a2 commit f947c02
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,83 @@ final class ConfigManagementServiceIT extends LedgerTestSuite {
// TODO(JM): Test that sets the time model and verifies that a transaction with invalid
// ttl/mrt won't be accepted. Can only implement once ApiSubmissionService properly
// uses currently set configuration.

test(
"CMSetConflicting",
"Conflicting generation should be rejected",
allocate(NoParties),
runConcurrently = false,
)(implicit ec => { case Participants(Participant(ledger)) =>
for {
// Get the current time model
response1 <- ledger.getTimeModel()
oldTimeModel = {
assert(response1.timeModel.isDefined, "Expected time model to be defined")
response1.timeModel.get
}

// Set a new time model with the next generation
t1 <- ledger.time()
_ <- ledger.setTimeModel(
mrt = t1.plusSeconds(30),
generation = response1.configurationGeneration,
newTimeModel = oldTimeModel,
)

// Set a new time model with the same generation
t2 <- ledger.time()
failure <- ledger
.setTimeModel(
mrt = t2.plusSeconds(30),
generation = response1.configurationGeneration,
newTimeModel = oldTimeModel,
)
.mustFail("setting Time Model with an outdated generation")
} yield {
assertGrpcError(failure, Status.Code.INVALID_ARGUMENT, "")
}
})

test(
"CMConcurrentSetConflicting",
"Two concurrent conflicting generation should be rejected/accepted",
allocate(NoParties),
runConcurrently = false,
)(implicit ec => { case Participants(Participant(ledger)) =>
for {
// Get the current time model
response1 <- ledger.getTimeModel()
oldTimeModel = {
assert(response1.timeModel.isDefined, "Expected time model to be defined")
response1.timeModel.get
}

// Set a new time model with the next generation in parallel
t1 <- ledger.time()
f1 = ledger.setTimeModel(
mrt = t1.plusSeconds(30),
generation = response1.configurationGeneration,
newTimeModel = oldTimeModel,
)
f2 = ledger.setTimeModel(
mrt = t1.plusSeconds(30),
generation = response1.configurationGeneration,
newTimeModel = oldTimeModel,
)

failure <- f1
.flatMap(_ => f2)
.mustFail("setting Time Model with an outdated generation")

// Check if generation got updated (meaning, one of the above succeeded)
response2 <- ledger.getTimeModel()
} yield {
assert(
response1.configurationGeneration + 1 == response2.configurationGeneration,
s"New configuration's generation (${response2.configurationGeneration} should be original configurations's generation (${response1.configurationGeneration} + 1) )",
)
assertGrpcError(failure, Status.Code.ABORTED, "")
}
})

}

0 comments on commit f947c02

Please sign in to comment.