diff --git a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/TestTransaction.kt b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/TestTransaction.kt index e9e6078..1491c1c 100644 --- a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/TestTransaction.kt +++ b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/TestTransaction.kt @@ -4,7 +4,6 @@ import io.anthonyberg.connector.shared.database.ActionResultDatabase import io.anthonyberg.connector.shared.database.DriverFactory import io.anthonyberg.connector.shared.database.TestDatabase import kotlinx.datetime.Clock -import kotlinx.datetime.Instant /** * Database transactions for testing procedures @@ -35,15 +34,11 @@ class TestTransaction (driverFactory: DriverFactory) { * Tells the database that the test has ended * * @param id ID of the Test - * - * @return The final time for when the test ended */ - fun endTest(id: Int): Instant { + fun endTest(id: Int) { val currentTime = Clock.System.now() testDb.endTest(testId = id.toLong(), endUTC = currentTime.toString()) - - return currentTime } /** @@ -72,10 +67,8 @@ class TestTransaction (driverFactory: DriverFactory) { * Tells the database that the test has ended and adds the final state * * @param id ID of the ActionResult - * - * @return The time for when the test for the specific action finished */ - fun finishAction(id: Int, endState: String): Instant { + fun finishAction(id: Int, endState: String) { val currentTime = Clock.System.now() actionResultDb.finishResult( @@ -83,7 +76,5 @@ class TestTransaction (driverFactory: DriverFactory) { endState = endState, endUTC = currentTime.toString() ) - - return currentTime } } diff --git a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/ActionResultDatabase.kt b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/ActionResultDatabase.kt index d4386e2..c97e972 100644 --- a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/ActionResultDatabase.kt +++ b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/ActionResultDatabase.kt @@ -15,14 +15,18 @@ internal class ActionResultDatabase (driverFactory: DriverFactory) { initState: String, startUTC: String ): Long { - dbQuery.startResult( - testId = testId, - actionId = actionId, - initState = initState, - startUTC = startUTC - ) + val id = dbQuery.transactionWithResult { + dbQuery.startResult( + testId = testId, + actionId = actionId, + initState = initState, + startUTC = startUTC + ) - return dbQuery.lastInsertedRowId().executeAsOne() + dbQuery.lastInsertedRowId().executeAsOne() + } + + return id } /** diff --git a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/TestDatabase.kt b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/TestDatabase.kt index a23e4a2..57cb25c 100644 --- a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/TestDatabase.kt +++ b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/TestDatabase.kt @@ -10,12 +10,15 @@ internal class TestDatabase (driverFactory: DriverFactory) { * @return ID of the Test created */ internal fun startTest(procedureId: Long, startUTC: String) : Long { - dbQuery.startTest( - procedureId = procedureId, - startUTC = startUTC, - ) + val id = dbQuery.transactionWithResult { + dbQuery.startTest( + procedureId = procedureId, + startUTC = startUTC, + ) + dbQuery.lastInsertedRowId().executeAsOne() + } - return dbQuery.lastInsertedRowId().executeAsOne() + return id } /**