Yonatan Karp-Rudin
06/27/2024, 6:16 AMawaitability
library and wait for the data to be available.
With the horrible help of ChatGPT I wrote the following test:
@Test
fun `should fetch comics and store it in the database`() =
testApplication {
// Given
environment {
withLastComicId()
withComic(1)
}
// When
application {
module()
}
// Then
val repository: WebComicsPort by inject()
val comics =
await untilNotNull { runBlocking { repository.getComicsById(2940) } }
comics shouldNotBe null
}
The problem I'm facing is that actually nothing happens, I see that the application module function is called and then everything stucks. My assumption was that the awaitability
library using Thread.sleep()
internally and locking the thread, but even when writing some custom code it still doesn't work 😅
Thanks in advance 🙏Mariusz Sołtysiak
06/27/2024, 6:44 AMSzymon Jeziorski
06/27/2024, 6:59 AMuntilNotNull
would lock the inner thread forever, awaitility
should still stop throw
ConditionTimeoutException
after configured timeout (defaults to 10 seconds) and kill inner thread performing lambda execution.
In your case I would put awaitiliy aside for a moment and check if repository
is correctly injected, and if repository.getComicsById
is being correctly invoked and returns proper valueYonatan Karp-Rudin
06/27/2024, 11:25 AM