Skip to content

Commit

Permalink
Add test for error composition for a successful resourceScope
Browse files Browse the repository at this point in the history
  • Loading branch information
kyay10 committed Nov 1, 2024
1 parent d6824af commit 8e3eac6
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -780,4 +780,33 @@ class ResourceTest {
wasActive.await() shouldBe true
res.isActive() shouldBe false
}

@Test
fun addsSuppressedErrorsFromReleasers() = runTest {
val promise = CompletableDeferred<ExitCase>()
val wasActive = CompletableDeferred<Boolean>()
val error = RuntimeException("BOOM!")
val error2 = RuntimeException("BOOM 2!")
val error3 = RuntimeException("BOOM 3!")
val res = Res()

val e = shouldThrow<RuntimeException> {
resourceScope {
val r = install({ res }) { r, e ->
promise.complete(e)
r.shutdown()
throw error2
}
onClose { throw error3 }
wasActive.complete(r.isActive())
onRelease { throw error }
}
}

e shouldBe error
e.suppressedExceptions shouldBe listOf(error3, error2)
promise.await() shouldBe ExitCase.Completed
wasActive.await() shouldBe true
res.isActive() shouldBe false
}
}

0 comments on commit 8e3eac6

Please sign in to comment.