Fix MockNetwork non-daemon thread leak. (#2397)

This commit is contained in:
Andrzej Cichocki 2018-01-22 11:00:40 +00:00 committed by GitHub
parent f59560bb06
commit d00438b86f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View File

@ -0,0 +1,26 @@
package net.corda.testing.node
import net.corda.core.internal.div
import net.corda.testing.common.internal.ProjectStructure.projectRootDir
import net.corda.testing.node.internal.ProcessUtilities.startJavaProcess
import org.junit.Test
import kotlin.test.assertEquals
class MockNetworkIntegrationTests {
companion object {
@JvmStatic
fun main(args: Array<String>) {
MockNetwork(emptyList()).run {
repeat(2) { createNode() }
runNetwork()
stopNodes()
}
}
}
@Test
fun `does not leak non-daemon threads`() {
val quasar = projectRootDir / "lib" / "quasar.jar"
assertEquals(0, startJavaProcess<MockNetworkIntegrationTests>(emptyList(), extraJvmArguments = listOf("-javaagent:$quasar")).waitFor())
}
}

View File

@ -161,6 +161,7 @@ class InMemoryMessagingNetwork internal constructor(
handleEndpointMap.clear()
messageReceiveQueues.clear()
timer.cancel()
}
@CordaSerializable

View File

@ -8,9 +8,10 @@ import java.nio.file.Path
object ProcessUtilities {
inline fun <reified C : Any> startJavaProcess(
arguments: List<String>,
jdwpPort: Int? = null
jdwpPort: Int? = null,
extraJvmArguments: List<String> = emptyList()
): Process {
return startJavaProcessImpl(C::class.java.name, arguments, defaultClassPath, jdwpPort, emptyList(), null, null, null)
return startJavaProcessImpl(C::class.java.name, arguments, defaultClassPath, jdwpPort, extraJvmArguments, null, null, null)
}
fun startCordaProcess(