mirror of
https://github.com/corda/corda.git
synced 2025-05-29 13:44:25 +00:00
Deflake NodeInfoWatcherTest (#1811)
* Deflake NodeInfoWatcherTest * Moved to integration tests, added eventually to check the validity
This commit is contained in:
parent
9239050fc8
commit
e8d21f2311
@ -5,22 +5,27 @@ import net.corda.core.internal.createDirectories
|
|||||||
import net.corda.core.internal.div
|
import net.corda.core.internal.div
|
||||||
import net.corda.core.node.NodeInfo
|
import net.corda.core.node.NodeInfo
|
||||||
import net.corda.core.node.services.KeyManagementService
|
import net.corda.core.node.services.KeyManagementService
|
||||||
|
import net.corda.core.utilities.seconds
|
||||||
import net.corda.node.services.identity.InMemoryIdentityService
|
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.MockKeyManagementService
|
||||||
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.contentOf
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.rules.TemporaryFolder
|
import org.junit.rules.TemporaryFolder
|
||||||
import rx.observers.TestSubscriber
|
import rx.observers.TestSubscriber
|
||||||
import rx.schedulers.TestScheduler
|
import rx.schedulers.TestScheduler
|
||||||
|
import java.nio.file.Path
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
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() {
|
class NodeInfoWatcherTest : NodeBasedTest() {
|
||||||
|
|
||||||
@ -67,7 +72,7 @@ class NodeInfoWatcherTest : NodeBasedTest() {
|
|||||||
.subscribe(testSubscriber)
|
.subscribe(testSubscriber)
|
||||||
|
|
||||||
val readNodes = testSubscriber.onNextEvents.distinct()
|
val readNodes = testSubscriber.onNextEvents.distinct()
|
||||||
scheduler.advanceTimeBy(1, TimeUnit.HOURS)
|
advanceTime()
|
||||||
assertEquals(0, readNodes.size)
|
assertEquals(0, readNodes.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,18 +97,24 @@ class NodeInfoWatcherTest : NodeBasedTest() {
|
|||||||
nodeInfoWatcher.nodeInfoUpdates()
|
nodeInfoWatcher.nodeInfoUpdates()
|
||||||
.subscribe(testSubscriber)
|
.subscribe(testSubscriber)
|
||||||
// Ensure the watch service is started.
|
// Ensure the watch service is started.
|
||||||
scheduler.advanceTimeBy(1, TimeUnit.HOURS)
|
advanceTime()
|
||||||
|
|
||||||
// Check no nodeInfos are read.
|
// Check no nodeInfos are read.
|
||||||
assertEquals(0, testSubscriber.valueCount)
|
assertEquals(0, testSubscriber.valueCount)
|
||||||
createNodeInfoFileInPath(nodeInfo)
|
createNodeInfoFileInPath(nodeInfo)
|
||||||
|
|
||||||
scheduler.advanceTimeBy(1, TimeUnit.HOURS)
|
advanceTime()
|
||||||
|
|
||||||
// The same folder can be reported more than once, so take unique values.
|
// We need the WatchService to report a change and that might not happen immediately.
|
||||||
val readNodes = testSubscriber.onNextEvents.distinct()
|
eventually<AssertionError, Unit>(5.seconds) {
|
||||||
assertEquals(1, readNodes.size)
|
// The same folder can be reported more than once, so take unique values.
|
||||||
assertEquals(nodeInfo, readNodes.first())
|
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.
|
// Write a nodeInfo under the right path.
|
Loading…
x
Reference in New Issue
Block a user