NOTICK Fix timing issue in FlowIsKilledTest (#6264)

Also remove `Configurator` that seems to fail on some agents.
This commit is contained in:
Dan Newton 2020-05-19 16:54:34 +01:00 committed by GitHub
parent fc2bb2ed4e
commit 36a11e868a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 34 deletions

View File

@ -20,10 +20,7 @@ import net.corda.testing.core.CHARLIE_NAME
import net.corda.testing.core.singleIdentity
import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.driver
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.core.config.Configurator
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.Before
import org.junit.Test
import java.util.concurrent.Semaphore
import kotlin.test.assertEquals
@ -36,11 +33,6 @@ class FlowIsKilledTest {
const val EXCEPTION_MESSAGE = "Goodbye, cruel world!"
}
@Before
fun setup() {
Configurator.setLevel("net.corda.node.services.statemachine", Level.DEBUG)
}
@Test(timeout = 300_000)
fun `manually handle the isKilled check`() {
driver(DriverParameters(notarySpecs = emptyList(), startNodesInProcess = true)) {
@ -111,7 +103,6 @@ class FlowIsKilledTest {
assertFailsWith<UnexpectedFlowEndException> {
handle.returnValue.getOrThrow(1.minutes)
}
assertTrue(AFlowThatGetsMurderedByItsFriend.receivedKilledException)
assertEquals(11, AFlowThatGetsMurderedByItsFriendResponder.position)
val aliceCheckpoints = alice.rpc.startFlow(::GetNumberOfCheckpointsFlow).returnValue.getOrThrow(20.seconds)
assertEquals(1, aliceCheckpoints)
@ -121,7 +112,7 @@ class FlowIsKilledTest {
}
@Test(timeout = 300_000)
fun `manually handle killed flows using checkForIsNotKilled`() {
fun `manually handle killed flows using checkFlowIsNotKilled`() {
driver(DriverParameters(notarySpecs = emptyList(), startNodesInProcess = true)) {
val alice = startNode(providedName = ALICE_NAME).getOrThrow()
alice.rpc.let { rpc ->
@ -140,7 +131,7 @@ class FlowIsKilledTest {
}
@Test(timeout = 300_000)
fun `manually handle killed flows using checkForIsNotKilled with lazy message`() {
fun `manually handle killed flows using checkFlowIsNotKilled with lazy message`() {
driver(DriverParameters(notarySpecs = emptyList(), startNodesInProcess = true)) {
val alice = startNode(providedName = ALICE_NAME).getOrThrow()
alice.rpc.let { rpc ->
@ -192,6 +183,7 @@ class FlowIsKilledTest {
companion object {
val lockA = Semaphore(0)
val lockB = Semaphore(0)
var isKilled = false
var position = 0
}
@ -208,6 +200,7 @@ class FlowIsKilledTest {
position = i
logger.info("i = $i")
if (isKilled) {
AFlowThatWantsToDieAndKillsItsFriends.isKilled = true
throw KilledFlowException(runId, EXCEPTION_MESSAGE)
}
@ -244,6 +237,9 @@ class FlowIsKilledTest {
} catch (e: UnexpectedFlowEndException) {
receivedKilledExceptions[ourIdentity.name] = true
locks[ourIdentity.name]!!.release()
require(AFlowThatWantsToDieAndKillsItsFriends.isKilled) {
"The initiator must be killed when this exception is received"
}
throw e
}
}
@ -253,19 +249,16 @@ class FlowIsKilledTest {
@InitiatingFlow
class AFlowThatGetsMurderedByItsFriend(private val party: Party) : FlowLogic<Unit>() {
companion object {
var receivedKilledException = false
}
@Suspendable
override fun call() {
val sessionOne = initiateFlow(party)
// trigger sessions with 2 counter parties
sessionOne.sendAndReceive<String>("what is up")
try {
sessionOne.sendAndReceive<String>("what is up")
sessionOne.receive<String>()
} catch (e: UnexpectedFlowEndException) {
receivedKilledException = true
require(AFlowThatGetsMurderedByItsFriendResponder.isKilled) {
"The responder must be killed when this exception is received"
}
throw e
}
}
@ -277,6 +270,7 @@ class FlowIsKilledTest {
companion object {
val lockA = Semaphore(0)
val lockB = Semaphore(0)
var isKilled = false
var flowId: StateMachineRunId? = null
var position = 0
}
@ -289,6 +283,7 @@ class FlowIsKilledTest {
for (i in 0..100) {
position = i
if (isKilled) {
AFlowThatGetsMurderedByItsFriendResponder.isKilled = true
throw KilledFlowException(runId, EXCEPTION_MESSAGE)
}

View File

@ -17,9 +17,6 @@ import net.corda.testing.core.BOB_NAME
import net.corda.testing.core.singleIdentity
import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.driver
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.core.config.Configurator
import org.junit.Before
import org.junit.Test
import java.time.Duration
import java.time.Instant
@ -27,11 +24,6 @@ import kotlin.test.assertTrue
class FlowSleepTest {
@Before
fun setup() {
Configurator.setLevel("net.corda.node.services.statemachine", Level.DEBUG)
}
@Test(timeout = 300_000)
fun `flow can sleep`() {
driver(DriverParameters(notarySpecs = emptyList(), startNodesInProcess = true)) {

View File

@ -34,10 +34,7 @@ import net.corda.testing.driver.NodeParameters
import net.corda.testing.driver.OutOfProcess
import net.corda.testing.driver.driver
import net.corda.testing.node.internal.FINANCE_CORDAPPS
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.core.config.Configurator
import org.assertj.core.api.Assertions
import org.junit.Before
import org.junit.Test
import java.time.Duration
import java.util.concurrent.Semaphore
@ -50,11 +47,6 @@ import kotlin.test.assertTrue
class KillFlowTest {
@Before
fun setup() {
Configurator.setLevel("net.corda.node.services.statemachine", Level.DEBUG)
}
@Test(timeout = 300_000)
fun `a killed flow will end when it reaches the next suspension point`() {
driver(DriverParameters(notarySpecs = emptyList(), startNodesInProcess = true)) {