ledger-api-test-tool: Only wait for parties on participants under test. (#9903)

* ledger-api-test-tool: Improve logging when reporting waiting failed.

We use a stringified version of the participant when reporting on a
failed `waitForParties` call.

* ledger-api-test-tool: Only wait for parties on participants under test.

Most tests only use one participant, so we can speed up waiting
considerably if we don't wait on the other participants in those cases.

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Samir Talwar 2021-06-03 14:49:21 +02:00 committed by GitHub
parent b8c02d65b7
commit b22c04654d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -38,15 +38,17 @@ private[testtool] final class LedgerTestContext private[infrastructure] (
* Each test allocates participants, then deconstructs the result and uses the various ledgers
* and parties throughout the test.
*/
def allocate(allocation: ParticipantAllocation): Future[Participants] =
def allocate(allocation: ParticipantAllocation): Future[Participants] = {
val participantAllocations = allocation.partyCounts.map(nextParticipant() -> _)
val participantsUnderTest = participantAllocations.map(_._1)
Future
.sequence(allocation.partyCounts.map(partyCount => {
val participant = nextParticipant()
.sequence(participantAllocations.map { case (participant, partyCount) =>
participant
.preallocateParties(partyCount.count, participants)
.preallocateParties(partyCount.count, participantsUnderTest)
.map(parties => Participant(participant, parties: _*))
}))
})
.map(Participants(_: _*))
}
private[this] def nextParticipant(): ParticipantTestContext =
participantsRing.synchronized {

View File

@ -128,6 +128,8 @@ private[testtool] final class ParticipantTestContext private[participant] (
private[this] val nextSubmissionId: () => String = nextId("submission")
val nextKeyId: () => String = nextId("key")
override def toString: String = s"participant $endpointId"
/** Gets the absolute offset of the ledger end at a point in time. Use [[end]] if you need
* a reference to the moving end of the ledger.
*/
@ -704,7 +706,7 @@ private[testtool] final class ParticipantTestContext private[participant] (
private[infrastructure] def preallocateParties(
n: Int,
participants: Iterable[ParticipantTestContext],
participantsUnderTest: Iterable[ParticipantTestContext],
): Future[Vector[Party]] =
for {
parties <-
@ -713,7 +715,7 @@ private[testtool] final class ParticipantTestContext private[participant] (
} else {
reservePartyNames(n)
}
_ <- waitForParties(participants, parties.toSet)
_ <- waitForParties(participantsUnderTest, parties.toSet)
} yield parties
private def reservePartyNames(n: Int): Future[Vector[Party]] =