https://kotlinlang.org logo
#coroutines
Title
# coroutines
n

nerses

02/08/2018, 1:40 PM
Hi, I am not getting how Exception propagation is happening. Here is a pseudo code and test
Copy code
fun populate(hotels: List<Hotel>) {
        
        val context = newFixedThreadPoolContext(threadpoolCoreSize, "thread-geo")

          context.use { c ->
                val jobs = hotels.map { hotel ->
                    launch(c) {
                        repo.suspendableFun()
                    }
                }
                runBlocking(c) {
                    jobs.forEach({ it.join() })
                }
            }
  }
and
Copy code
@Test(expectedExceptions = [RuntimeException::class])
    fun `populate should throw exceptionIn`() = runBlocking {
        //and
        given(repo.suspendableFun()).willThrow(RuntimeException(""))

        //when
        victim.populate(hotelList())

        //then
        //The exception is thrown
    }
i

Ilmir Usmanov [JB]

02/08/2018, 1:47 PM
Try to replace
suspendFun
with
suspendableFun
.
n

nerses

02/08/2018, 1:48 PM
it’s the same, sorry
i was just simplifying the code to post here
i

Ilmir Usmanov [JB]

02/08/2018, 2:30 PM
Yes, I reproduced the problem. Will file the issue shortly. Thank you!
BTW, if I throw the exception in suspendableFun, without mocking it, the exception is propagated as expected.
n

nerses

02/08/2018, 2:56 PM
oh, so it’s a genuine bug 🙂 I was thinking i am doing something wrong 🙂
@Ilmir Usmanov [JB] can you give me the ticket number once you’ve created it?
i

Ilmir Usmanov [JB]

02/08/2018, 3:24 PM
n

nerses

02/08/2018, 3:48 PM
thanks @Ilmir Usmanov [JB]
2 Views