Deflake NodeInfoWatcherTest (#1811)

* Deflake NodeInfoWatcherTest

* Moved to integration tests, added eventually to check the validity
This commit is contained in:
Alberto Arri 2017-10-05 17:15:40 +01:00 committed by GitHub
parent 9239050fc8
commit e8d21f2311

View File

@ -5,22 +5,27 @@ import net.corda.core.internal.createDirectories
import net.corda.core.internal.div
import net.corda.core.node.NodeInfo
import net.corda.core.node.services.KeyManagementService
import net.corda.core.utilities.seconds
import net.corda.node.services.identity.InMemoryIdentityService
import net.corda.testing.*
import net.corda.testing.ALICE
import net.corda.testing.ALICE_KEY
import net.corda.testing.DEV_TRUST_ROOT
import net.corda.testing.eventually
import net.corda.testing.getTestPartyAndCertificate
import net.corda.testing.node.MockKeyManagementService
import net.corda.testing.node.NodeBasedTest
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.contentOf
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import rx.observers.TestSubscriber
import rx.schedulers.TestScheduler
import java.nio.file.Path
import java.util.concurrent.TimeUnit
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.contentOf
import java.nio.file.Path
class NodeInfoWatcherTest : NodeBasedTest() {
@ -67,7 +72,7 @@ class NodeInfoWatcherTest : NodeBasedTest() {
.subscribe(testSubscriber)
val readNodes = testSubscriber.onNextEvents.distinct()
scheduler.advanceTimeBy(1, TimeUnit.HOURS)
advanceTime()
assertEquals(0, readNodes.size)
}
@ -92,18 +97,24 @@ class NodeInfoWatcherTest : NodeBasedTest() {
nodeInfoWatcher.nodeInfoUpdates()
.subscribe(testSubscriber)
// Ensure the watch service is started.
scheduler.advanceTimeBy(1, TimeUnit.HOURS)
advanceTime()
// Check no nodeInfos are read.
assertEquals(0, testSubscriber.valueCount)
createNodeInfoFileInPath(nodeInfo)
scheduler.advanceTimeBy(1, TimeUnit.HOURS)
advanceTime()
// The same folder can be reported more than once, so take unique values.
val readNodes = testSubscriber.onNextEvents.distinct()
assertEquals(1, readNodes.size)
assertEquals(nodeInfo, readNodes.first())
// We need the WatchService to report a change and that might not happen immediately.
eventually<AssertionError, Unit>(5.seconds) {
// The same folder can be reported more than once, so take unique values.
val readNodes = testSubscriber.onNextEvents.distinct()
assertEquals(1, readNodes.size)
assertEquals(nodeInfo, readNodes.first())
}
}
private fun advanceTime() {
scheduler.advanceTimeBy(1, TimeUnit.HOURS)
}
// Write a nodeInfo under the right path.