CORDA-649: Second attempt to make PersistentNetworkMapCacheTest more stable (#1738)

This commit is contained in:
Viktor Kolomeyko 2017-10-02 10:50:39 +01:00 committed by GitHub
parent f961412396
commit 33e8105a29
4 changed files with 29 additions and 8 deletions

View File

@ -27,7 +27,6 @@ buildscript {
ext.jersey_version = '2.25' ext.jersey_version = '2.25'
ext.jolokia_version = '2.0.0-M3' ext.jolokia_version = '2.0.0-M3'
ext.assertj_version = '3.6.1' ext.assertj_version = '3.6.1'
ext.kotlintest_version = '2.0.5'
ext.slf4j_version = '1.7.25' ext.slf4j_version = '1.7.25'
ext.log4j_version = '2.7' ext.log4j_version = '2.7'
ext.bouncycastle_version = constants.getProperty("bouncycastleVersion") ext.bouncycastle_version = constants.getProperty("bouncycastleVersion")

View File

@ -127,7 +127,6 @@ dependencies {
// Unit testing helpers. // Unit testing helpers.
testCompile "junit:junit:$junit_version" testCompile "junit:junit:$junit_version"
testCompile "org.assertj:assertj-core:${assertj_version}" testCompile "org.assertj:assertj-core:${assertj_version}"
testCompile "io.kotlintest:kotlintest:${kotlintest_version}"
testCompile project(':test-utils') testCompile project(':test-utils')
testCompile project(':client:jfx') testCompile project(':client:jfx')
testCompile project(':finance') testCompile project(':finance')

View File

@ -1,8 +1,6 @@
package net.corda.node.services.network package net.corda.node.services.network
import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.fibers.Suspendable
import io.kotlintest.eventually
import io.kotlintest.milliseconds
import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowLogic
import net.corda.core.flows.FlowSession import net.corda.core.flows.FlowSession
import net.corda.core.flows.InitiatedBy import net.corda.core.flows.InitiatedBy
@ -17,8 +15,8 @@ import net.corda.testing.*
import net.corda.testing.node.NodeBasedTest import net.corda.testing.node.NodeBasedTest
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.Before import org.junit.Before
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import java.time.Duration
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFails import kotlin.test.assertFails
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -114,7 +112,6 @@ class PersistentNetworkMapCacheTest : NodeBasedTest() {
assertFails { startNode(CHARLIE.name, noNetworkMap = true).getOrThrow(2.seconds) } assertFails { startNode(CHARLIE.name, noNetworkMap = true).getOrThrow(2.seconds) }
} }
@Ignore("Unstable test that needs more work")
@Test @Test
fun `new node joins network without network map started`() { fun `new node joins network without network map started`() {
@ -146,9 +143,11 @@ class PersistentNetworkMapCacheTest : NodeBasedTest() {
// This is prediction of the longest time it will take to get the cluster into a stable state such that further // This is prediction of the longest time it will take to get the cluster into a stable state such that further
// testing can be performed upon it // testing can be performed upon it
val maxInstabilityInterval = BRIDGE_RETRY_MS * allTheStartedNodesPopulation.size * 2 val maxInstabilityInterval = BRIDGE_RETRY_MS * allTheStartedNodesPopulation.size * 30
logger.info("Instability interval is set to: $maxInstabilityInterval ms")
eventually(maxInstabilityInterval.milliseconds) { // TODO: Re-visit this sort of re-try for stable cluster once network map redesign is finished.
eventually<AssertionError, Unit>(Duration.ofMillis(maxInstabilityInterval)) {
logger.info("Checking connectivity") logger.info("Checking connectivity")
checkConnectivity(listOf(otherNodes[0], nms)) // Checks connectivity from A to NMS. checkConnectivity(listOf(otherNodes[0], nms)) // Checks connectivity from A to NMS.
logger.info("Loading caches") logger.info("Loading caches")

View File

@ -0,0 +1,24 @@
package net.corda.testing
import java.time.Duration
/**
* Ideas borrowed from "io.kotlintest" with some improvements made
* This is meant for use from Kotlin code use only mainly due to it's inline/reified nature
*/
inline fun <reified E : Throwable, R>eventually(duration: Duration, f: () -> R): R {
val end = System.nanoTime() + duration.toNanos()
var times = 0
while (System.nanoTime() < end) {
try {
return f()
} catch (e: Throwable) {
when(e) {
is E -> {}// ignore and continue
else -> throw e // unexpected exception type - rethrow
}
}
times++
}
throw AssertionError("Test failed after $duration; attempted $times times")
}