Stabilise NodeStatePersistenceTests (#2079)

Pass notary identity into flow in `NodeStatePersistenceTests` rather than resolving it from the network map cache, which avoids a race condition between the flow starting and the notary registration being sent to the cache.
This commit is contained in:
Ross Nicoll 2017-11-17 18:13:10 +00:00 committed by GitHub
parent 817748c87e
commit 1f98293377
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,28 +40,32 @@ class NodeStatePersistenceTests {
val user = User("mark", "dadada", setOf(startFlow<SendMessageFlow>(), invokeRpc("vaultQuery"))) val user = User("mark", "dadada", setOf(startFlow<SendMessageFlow>(), invokeRpc("vaultQuery")))
val message = Message("Hello world!") val message = Message("Hello world!")
driver(isDebug = true, startNodesInProcess = isQuasarAgentSpecified()) { val stateAndRef: StateAndRef<MessageState>? = driver(isDebug = true, startNodesInProcess = isQuasarAgentSpecified()) {
val nodeName = { val nodeName = {
val nodeHandle = startNode(rpcUsers = listOf(user)).getOrThrow() val nodeHandle = startNode(rpcUsers = listOf(user)).getOrThrow()
val nodeName = nodeHandle.nodeInfo.chooseIdentity().name val nodeName = nodeHandle.nodeInfo.chooseIdentity().name
// Ensure the notary node has finished starting up, before starting a flow that needs a notary
defaultNotaryNode.getOrThrow()
nodeHandle.rpcClientToNode().start(user.username, user.password).use { nodeHandle.rpcClientToNode().start(user.username, user.password).use {
it.proxy.startFlow(::SendMessageFlow, message).returnValue.getOrThrow() it.proxy.startFlow(::SendMessageFlow, message, defaultNotaryIdentity).returnValue.getOrThrow()
} }
nodeHandle.stop() nodeHandle.stop()
nodeName nodeName
}() }()
val nodeHandle = startNode(providedName = nodeName, rpcUsers = listOf(user)).getOrThrow() val nodeHandle = startNode(providedName = nodeName, rpcUsers = listOf(user)).getOrThrow()
nodeHandle.rpcClientToNode().start(user.username, user.password).use { val result = nodeHandle.rpcClientToNode().start(user.username, user.password).use {
val page = it.proxy.vaultQuery(MessageState::class.java) val page = it.proxy.vaultQuery(MessageState::class.java)
val stateAndRef = page.states.singleOrNull() page.states.singleOrNull()
}
nodeHandle.stop()
result
}
assertNotNull(stateAndRef) assertNotNull(stateAndRef)
val retrievedMessage = stateAndRef!!.state.data.message val retrievedMessage = stateAndRef!!.state.data.message
assertEquals(message, retrievedMessage) assertEquals(message, retrievedMessage)
} }
} }
}
}
fun isQuasarAgentSpecified(): Boolean { fun isQuasarAgentSpecified(): Boolean {
val jvmArgs = ManagementFactory.getRuntimeMXBean().inputArguments val jvmArgs = ManagementFactory.getRuntimeMXBean().inputArguments
@ -126,7 +130,7 @@ open class MessageContract : Contract {
} }
@StartableByRPC @StartableByRPC
class SendMessageFlow(private val message: Message) : FlowLogic<SignedTransaction>() { class SendMessageFlow(private val message: Message, private val notary: Party) : FlowLogic<SignedTransaction>() {
companion object { companion object {
object GENERATING_TRANSACTION : ProgressTracker.Step("Generating transaction based on the message.") object GENERATING_TRANSACTION : ProgressTracker.Step("Generating transaction based on the message.")
object VERIFYING_TRANSACTION : ProgressTracker.Step("Verifying contract constraints.") object VERIFYING_TRANSACTION : ProgressTracker.Step("Verifying contract constraints.")
@ -142,8 +146,6 @@ class SendMessageFlow(private val message: Message) : FlowLogic<SignedTransactio
@Suspendable @Suspendable
override fun call(): SignedTransaction { override fun call(): SignedTransaction {
val notary = serviceHub.networkMapCache.notaryIdentities.first()
progressTracker.currentStep = GENERATING_TRANSACTION progressTracker.currentStep = GENERATING_TRANSACTION
val messageState = MessageState(message = message, by = ourIdentity) val messageState = MessageState(message = message, by = ourIdentity)