Add node scheduler db tests inside use block (#3075)

This commit is contained in:
Anthony Keenan 2018-05-04 13:03:02 +01:00 committed by GitHub
parent 57b617c7d9
commit f8a4368310
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -234,7 +234,7 @@ class NodeSchedulerPersistenceTest : NodeSchedulerServiceTestBase() {
val timeInTheFuture = mark + 1.days val timeInTheFuture = mark + 1.days
val stateRef = StateRef(SecureHash.zeroHash, 0) val stateRef = StateRef(SecureHash.zeroHash, 0)
val database = configureDatabase(dataSourceProps, databaseConfig, rigorousMock()) configureDatabase(dataSourceProps, databaseConfig, rigorousMock()).use { database ->
val scheduler = database.transaction { val scheduler = database.transaction {
createScheduler(database) createScheduler(database)
} }
@ -245,9 +245,10 @@ class NodeSchedulerPersistenceTest : NodeSchedulerServiceTestBase() {
} }
// XXX: For some reason without the commit the db closes without writing the transactions // XXX: For some reason without the commit the db closes without writing the transactions
database.dataSource.connection.commit() database.dataSource.connection.commit()
// Force the thread to shut down with operations waiting // Force the thread to shut down with operations waiting
scheduler.cancelAndWait() scheduler.cancelAndWait()
database.close() }
val flowLogic = rigorousMock<FlowLogic<*>>() val flowLogic = rigorousMock<FlowLogic<*>>()
val logicRef = rigorousMock<FlowLogicRef>() val logicRef = rigorousMock<FlowLogicRef>()
@ -255,15 +256,15 @@ class NodeSchedulerPersistenceTest : NodeSchedulerServiceTestBase() {
transactionStates[stateRef] = transactionStateMock(logicRef, timeInTheFuture) transactionStates[stateRef] = transactionStateMock(logicRef, timeInTheFuture)
flows[logicRef] = flowLogic flows[logicRef] = flowLogic
val newDatabase = configureDatabase(dataSourceProps, DatabaseConfig(), rigorousMock()) configureDatabase(dataSourceProps, DatabaseConfig(), rigorousMock()).use { database ->
val newScheduler = newDatabase.transaction { val newScheduler = database.transaction {
createScheduler(newDatabase) createScheduler(database)
} }
testClock.advanceBy(1.days) testClock.advanceBy(1.days)
assertStarted(flowLogic) assertStarted(flowLogic)
newScheduler.join() newScheduler.join()
newDatabase.close() }
} }
@Ignore("Temporarily") @Ignore("Temporarily")
@ -277,8 +278,8 @@ class NodeSchedulerPersistenceTest : NodeSchedulerServiceTestBase() {
val ssr2 = ScheduledStateRef(stateRef, timeInTheFuture) val ssr2 = ScheduledStateRef(stateRef, timeInTheFuture)
val logicRef = rigorousMock<FlowLogicRef>() val logicRef = rigorousMock<FlowLogicRef>()
val flowLogic = rigorousMock<FlowLogic<*>>() val flowLogic = rigorousMock<FlowLogic<*>>()
val database = configureDatabase(dataSourceProps, databaseConfig, rigorousMock())
configureDatabase(dataSourceProps, databaseConfig, rigorousMock()).use { database ->
val scheduler = database.transaction { val scheduler = database.transaction {
createScheduler(database) createScheduler(database)
} }
@ -296,6 +297,6 @@ class NodeSchedulerPersistenceTest : NodeSchedulerServiceTestBase() {
assertStarted(flowLogic) assertStarted(flowLogic)
scheduler.join() scheduler.join()
database.close() }
} }
} }