From 459359672b1f4266bc0f009c35f246fd90cce36a Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 2 Feb 2019 00:10:27 -0500 Subject: Fix crash --- .../com/pitchedapps/frost/utils/CoroutineTest.kt | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'app/src/test/kotlin/com') 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() + + val job = SupervisorJob() + + val flyweight = Flyweight(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() +// } + } + } } -- cgit v1.2.3