From 68feb1c35fa37379f492803fb3bf047321883d4d Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Fri, 31 Jul 2020 08:32:20 +0100 Subject: [PATCH] CORDA-3932 Correct race condition in FlowVersioningTest (#6536) Correct race condition in FlowVersioningTest where the last message is read (and the session close can be triggered) before one side has finished reading metadata from the session. --- .../statemachine/FlowVersioningTest.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt index e2fc51282b..a6b04d6441 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt @@ -33,13 +33,19 @@ class FlowVersioningTest : NodeBasedTest() { private class PretendInitiatingCoreFlow(val initiatedParty: Party) : FlowLogic>() { @Suspendable override fun call(): Pair { - // Execute receive() outside of the Pair constructor to avoid Kotlin/Quasar instrumentation bug. val session = initiateFlow(initiatedParty) - val alicePlatformVersionAccordingToBob = session.receive().unwrap { it } - return Pair( - alicePlatformVersionAccordingToBob, - session.getCounterpartyFlowInfo().flowVersion - ) + return try { + // Get counterparty flow info before we receive Alice's data, to ensure the flow is still open + val bobPlatformVersionAccordingToAlice = session.getCounterpartyFlowInfo().flowVersion + // Execute receive() outside of the Pair constructor to avoid Kotlin/Quasar instrumentation bug. + val alicePlatformVersionAccordingToBob = session.receive().unwrap { it } + Pair( + alicePlatformVersionAccordingToBob, + bobPlatformVersionAccordingToAlice + ) + } finally { + session.close() + } } }