Replies: 1 comment 2 replies
-
In your test, @Test
@RunOnVertxContext
fun suspendingTest() {
runBlocking {
// given
val randomAlphabetic = randomAlphabetic(7)
// when
val result = Uni.createFrom()
.emitter<String> { emitter ->
emitter.complete(randomAlphabetic)
}.awaitSuspending()
// then
result shouldBeEqualTo randomAlphabetic
}
} But I suppose that doesn't help. How about this: @Test
fun suspendingTest2() {
runSuspendingTest {
// given
val randomAlphabetic = randomAlphabetic(7)
// when
val result = Uni.createFrom()
.emitter<String> { emitter ->
Thread.sleep(5000L)
emitter.complete(randomAlphabetic)
}
.awaitSuspending()
// then
result shouldBeEqualTo randomAlphabetic
}
}
private fun runSuspendingTest(block: suspend () -> Unit) {
VertxContextSupport.executeBlocking {
runBlocking { block() }
}.await().indefinitely()
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello.
I'm trying to write a test using
@RunOnVertxContext
, that executes suspending functions (R2DBC, Kafka etc).Unfortunately, whenever Mutiny's
awaitSuspending
is executed, the vert.x thread is being blocked, resulting in a series ofio.vertx.core.VertxException: Thread blocked
exceptions being thrown (detailed stack trace below).Below you can find a sample test that reproduces the error.
Interestingly, If the same code containing
awaitSuspending
is executed via HTTP request and triggered via RestAssured, everything works fine.Test to reproduce:
As junit tests cannot be suspending, I had to use
runBlocking
coroutine builder inside the test.I suspect that this may be related to the issue, as the coroutines are not bound to the Vert.x instance managed by quarkus, however doing
runBlocking(Vertx.currentContext().dispatcher())
won't solve it (dispatcher()
fromio.vertx:vertx-lang-kotlin-coroutines
)Stacktrace:
Beta Was this translation helpful? Give feedback.
All reactions