mirror of
https://github.com/corda/corda.git
synced 2025-06-17 22:58:19 +00:00
Fix tests that check ports are bound/unbound (#756)
* Specifically, DriverTests and WebserverDriverTests * RPCDriver.startRpcBroker now waits for port to be unbound, as was probably intended * Explicitly drop network map future while ensuring the error is logged
This commit is contained in:
@ -261,7 +261,11 @@ class ListenProcessDeathException(message: String) : Exception(message)
|
||||
/**
|
||||
* @throws ListenProcessDeathException if [listenProcess] dies before the check succeeds, i.e. the check can't succeed as intended.
|
||||
*/
|
||||
fun addressMustBeBound(executorService: ScheduledExecutorService, hostAndPort: HostAndPort, listenProcess: Process): ListenableFuture<Unit> {
|
||||
fun addressMustBeBound(executorService: ScheduledExecutorService, hostAndPort: HostAndPort, listenProcess: Process) {
|
||||
addressMustBeBoundFuture(executorService, hostAndPort, listenProcess).getOrThrow()
|
||||
}
|
||||
|
||||
fun addressMustBeBoundFuture(executorService: ScheduledExecutorService, hostAndPort: HostAndPort, listenProcess: Process): ListenableFuture<Unit> {
|
||||
return poll(executorService, "address $hostAndPort to bind") {
|
||||
if (!listenProcess.isAlive) {
|
||||
throw ListenProcessDeathException("The process that was expected to listen on $hostAndPort has died with status: ${listenProcess.exitValue()}")
|
||||
@ -275,7 +279,11 @@ fun addressMustBeBound(executorService: ScheduledExecutorService, hostAndPort: H
|
||||
}
|
||||
}
|
||||
|
||||
fun addressMustNotBeBound(executorService: ScheduledExecutorService, hostAndPort: HostAndPort): ListenableFuture<Unit> {
|
||||
fun addressMustNotBeBound(executorService: ScheduledExecutorService, hostAndPort: HostAndPort) {
|
||||
addressMustNotBeBoundFuture(executorService, hostAndPort).getOrThrow()
|
||||
}
|
||||
|
||||
fun addressMustNotBeBoundFuture(executorService: ScheduledExecutorService, hostAndPort: HostAndPort): ListenableFuture<Unit> {
|
||||
return poll(executorService, "address $hostAndPort to unbind") {
|
||||
try {
|
||||
Socket(hostAndPort.host, hostAndPort.port).close()
|
||||
@ -608,7 +616,7 @@ class DriverDSL(
|
||||
)
|
||||
_shutdownManager = ShutdownManager(executorService)
|
||||
if (networkMapStartStrategy.startDedicated) {
|
||||
startDedicatedNetworkMapService()
|
||||
startDedicatedNetworkMapService().andForget(log) // Allow it to start concurrently with other nodes.
|
||||
}
|
||||
}
|
||||
|
||||
@ -634,7 +642,7 @@ class DriverDSL(
|
||||
log.info("Starting network-map-service")
|
||||
val startNode = startNode(executorService, config.parseAs<FullNodeConfiguration>(), config, quasarJarPath, debugPort, systemProperties)
|
||||
registerProcess(startNode)
|
||||
return startNode.flatMap { addressMustBeBound(executorService, dedicatedNetworkMapAddress, it) }
|
||||
return startNode.flatMap { addressMustBeBoundFuture(executorService, dedicatedNetworkMapAddress, it) }
|
||||
}
|
||||
|
||||
override fun <A> pollUntilNonNull(pollName: String, pollInterval: Duration, warnCount: Int, check: () -> A?): ListenableFuture<A> {
|
||||
@ -693,7 +701,7 @@ class DriverDSL(
|
||||
errorLogPath = nodeConf.baseDirectory / LOGS_DIRECTORY_NAME / "error.log",
|
||||
workingDirectory = nodeConf.baseDirectory
|
||||
)
|
||||
}.flatMap { process -> addressMustBeBound(executorService, nodeConf.p2pAddress, process).map { process } }
|
||||
}.flatMap { process -> addressMustBeBoundFuture(executorService, nodeConf.p2pAddress, process).map { process } }
|
||||
}
|
||||
|
||||
private fun startWebserver(
|
||||
@ -713,7 +721,7 @@ class DriverDSL(
|
||||
),
|
||||
errorLogPath = Paths.get("error.$className.log")
|
||||
)
|
||||
}.flatMap { process -> addressMustBeBound(executorService, handle.webAddress, process).map { process } }
|
||||
}.flatMap { process -> addressMustBeBoundFuture(executorService, handle.webAddress, process).map { process } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user