mirror of
https://github.com/corda/corda.git
synced 2025-01-18 10:46:38 +00:00
node-driver: Polling doesn't timeout, just prints warning
This commit is contained in:
parent
9cbdf001fb
commit
5f33bedc13
@ -154,7 +154,7 @@ private fun getTimestampAsDirectoryName(): String {
|
||||
}
|
||||
|
||||
fun addressMustBeBound(hostAndPort: HostAndPort) {
|
||||
poll {
|
||||
poll("address $hostAndPort to bind") {
|
||||
try {
|
||||
Socket(hostAndPort.hostText, hostAndPort.port).close()
|
||||
Unit
|
||||
@ -165,7 +165,7 @@ fun addressMustBeBound(hostAndPort: HostAndPort) {
|
||||
}
|
||||
|
||||
fun addressMustNotBeBound(hostAndPort: HostAndPort) {
|
||||
poll {
|
||||
poll("address $hostAndPort to unbind") {
|
||||
try {
|
||||
Socket(hostAndPort.hostText, hostAndPort.port).close()
|
||||
null
|
||||
@ -175,17 +175,17 @@ fun addressMustNotBeBound(hostAndPort: HostAndPort) {
|
||||
}
|
||||
}
|
||||
|
||||
fun <A> poll(f: () -> A?): A {
|
||||
fun <A> poll(pollName: String, pollIntervalMs: Long = 500, warnCount: Int = 120, f: () -> A?): A {
|
||||
var counter = 0
|
||||
var result = f()
|
||||
while (result == null && counter < 120) {
|
||||
counter++
|
||||
Thread.sleep(500)
|
||||
while (result == null) {
|
||||
if (counter == warnCount) {
|
||||
log.warn("Been polling $pollName for ${pollIntervalMs * warnCount / 1000.0} seconds...")
|
||||
}
|
||||
counter = (counter % warnCount) + 1
|
||||
Thread.sleep(pollIntervalMs)
|
||||
result = f()
|
||||
}
|
||||
if (result == null) {
|
||||
throw Exception("Poll timed out")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@ -326,7 +326,7 @@ class DriverDSL(
|
||||
advertisedServices = setOf(NetworkMapService.Type)
|
||||
)
|
||||
networkMapCache.addMapService(messagingService, fakeNodeInfo, true)
|
||||
networkMapNodeInfo = poll {
|
||||
networkMapNodeInfo = poll("network map cache for $networkMapName") {
|
||||
networkMapCache.partyNodes.forEach {
|
||||
if (it.identity.name == networkMapName) {
|
||||
return@poll it
|
||||
|
@ -13,7 +13,7 @@ class DriverTests {
|
||||
fun nodeMustBeUp(networkMapCache: NetworkMapCache, nodeInfo: NodeInfo, nodeName: String) {
|
||||
val address = nodeInfo.address as ArtemisMessagingComponent.Address
|
||||
// Check that the node is registered in the network map
|
||||
poll {
|
||||
poll("network map cache for $nodeName") {
|
||||
networkMapCache.get().firstOrNull {
|
||||
it.identity.name == nodeName
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user