BUILD: Try to fix flaky FailNodeOnNotMigratedAttachmentContractsTableNameTests.

* Ensure that this test stops nodes that it starts.
* Also ensure that random ephemeral ports can be reused.
This commit is contained in:
Chris Rankin 2019-03-18 17:25:01 +00:00 committed by Mike Hearn
parent 866f07c741
commit f378f0eba6
2 changed files with 10 additions and 10 deletions

View File

@ -14,7 +14,6 @@ import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.driver
import net.corda.testing.driver.internal.RandomFree
import net.corda.testing.node.User
import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.Test
import java.nio.file.Path
@ -36,19 +35,19 @@ class FailNodeOnNotMigratedAttachmentContractsTableNameTests {
val user = User("mark", "dadada", setOf(Permissions.startFlow<SendMessageFlow>(), Permissions.invokeRpc("vaultQuery")))
val message = Message("Hello world!")
val baseDir: Path = driver(DriverParameters(startNodesInProcess = true, portAllocation = RandomFree, extraCordappPackagesToScan = listOf(MessageState::class.packageName))) {
// Just start a node to make this test less flaky.
startNode(rpcUsers = listOf(user)).getOrThrow()
val (nodeName, baseDir) = {
val (nodeName, baseDir) = run {
defaultNotaryNode.getOrThrow()
val nodeHandle = startNode(rpcUsers = listOf(user)).getOrThrow()
val nodeName = nodeHandle.nodeInfo.singleIdentity().name
CordaRPCClient(nodeHandle.rpcAddress).start(user.username, user.password).use {
it.proxy.startFlow(::SendMessageFlow, message, defaultNotaryIdentity).returnValue.getOrThrow()
val nodeName = try {
CordaRPCClient(nodeHandle.rpcAddress).start(user.username, user.password).use {
it.proxy.startFlow(::SendMessageFlow, message, defaultNotaryIdentity).returnValue.getOrThrow()
}
nodeHandle.nodeInfo.singleIdentity().name
} finally {
nodeHandle.stop()
}
nodeHandle.stop()
Pair(nodeName, nodeHandle.baseDirectory)
}()
}
// replace the correct table name with one from the former release
DriverManager.getConnection("jdbc:h2:file://$baseDir/persistence", "sa", "").use {

View File

@ -81,6 +81,7 @@ val InProcess.internalServices: StartedNodeServices get() = services as StartedN
object RandomFree : PortAllocation() {
override fun nextPort(): Int {
return ServerSocket().use {
it.reuseAddress = true
it.bind(InetSocketAddress(0))
it.localPort
}