diff options
author | Allan Wang <me@allanwang.ca> | 2019-02-02 00:10:27 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-02-02 00:10:27 -0500 |
commit | 459359672b1f4266bc0f009c35f246fd90cce36a (patch) | |
tree | 41ce6a829a9b31bdc32ab9007d66c313e36985d3 /app/src/test/kotlin/com/pitchedapps | |
parent | e874b788753ce69ea561b41dc13dfb230c750690 (diff) | |
download | frost-459359672b1f4266bc0f009c35f246fd90cce36a.tar.gz frost-459359672b1f4266bc0f009c35f246fd90cce36a.tar.bz2 frost-459359672b1f4266bc0f009c35f246fd90cce36a.zip |
Fix crash
Diffstat (limited to 'app/src/test/kotlin/com/pitchedapps')
-rw-r--r-- | app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt index fb302648..e93f507c 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt @@ -16,9 +16,11 @@ */ package com.pitchedapps.frost.utils +import com.pitchedapps.frost.kotlin.Flyweight import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.async import kotlinx.coroutines.channels.BroadcastChannel @@ -243,4 +245,47 @@ class CoroutineTest { ) } } + + @Test + fun exceptionChecks() { + val mainTag = "main-test" + val mainDispatcher = Executors.newSingleThreadExecutor { r -> + Thread(r, mainTag) + }.asCoroutineDispatcher() + val channel = Channel<Int>() + + val job = SupervisorJob() + + val flyweight = Flyweight<Int, Int>(GlobalScope, 200L) { + throw java.lang.RuntimeException("Flyweight exception") + } + + suspend fun crash(): Boolean = withContext(Dispatchers.IO) { + try { + withContext(Dispatchers.Default) { + flyweight.fetch(0).await() + } + true + } catch (e: java.lang.Exception) { + false + } + } + + runBlocking(mainDispatcher + job) { + launch { + val i = channel.receive() + println("Received $i") + } + launch { + println("A") + println(crash()) + println("B") + channel.offer(1) + } +// launch { +// delay(2000) +// job.cancel() +// } + } + } } |