diff options
author | Allan Wang <me@allanwang.ca> | 2019-01-04 01:56:04 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-01-04 01:56:04 -0500 |
commit | 339ce9db98c1e6dfb1c8d69f81806680b1efa666 (patch) | |
tree | 75b3366004ddf08359490d4d4b83d63366c0a68d /app/src/test/kotlin | |
parent | 8c77e02e89dfec7bff04a397dfc82613ccd1242a (diff) | |
download | frost-339ce9db98c1e6dfb1c8d69f81806680b1efa666.tar.gz frost-339ce9db98c1e6dfb1c8d69f81806680b1efa666.tar.bz2 frost-339ce9db98c1e6dfb1c8d69f81806680b1efa666.zip |
Convert global continuations to completable deferred
Diffstat (limited to 'app/src/test/kotlin')
-rw-r--r-- | app/src/test/kotlin/com/pitchedapps/frost/kotlin/FlyweightTest.kt | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/app/src/test/kotlin/com/pitchedapps/frost/kotlin/FlyweightTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/kotlin/FlyweightTest.kt index 0eee530e..79f81002 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/kotlin/FlyweightTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/kotlin/FlyweightTest.kt @@ -54,7 +54,7 @@ class FlyweightTest { @Test fun basic() { - assertEquals(2, runBlocking { flyweight.fetch(1) }, "Invalid result") + assertEquals(2, runBlocking { flyweight.fetch(1).await() }, "Invalid result") assertEquals(1, callCount.get(), "1 call expected") } @@ -62,9 +62,7 @@ class FlyweightTest { fun multipleWithOneKey() { val results: List<Int> = runBlocking { (0..1000).map { - flyweight.scope.async { - flyweight.fetch(1) - } + flyweight.fetch(1) }.map { it.await() } } assertEquals(1, callCount.get(), "1 call expected") @@ -75,12 +73,12 @@ class FlyweightTest { @Test fun consecutiveReuse() { runBlocking { - flyweight.fetch(1) + flyweight.fetch(1).await() assertEquals(1, callCount.get(), "1 call expected") - flyweight.fetch(1) + flyweight.fetch(1).await() assertEquals(1, callCount.get(), "Reuse expected") Thread.sleep(300) - flyweight.fetch(1) + flyweight.fetch(1).await() assertEquals(2, callCount.get(), "Refetch expected") } } @@ -88,10 +86,10 @@ class FlyweightTest { @Test fun invalidate() { runBlocking { - flyweight.fetch(1) + flyweight.fetch(1).await() assertEquals(1, callCount.get(), "1 call expected") flyweight.invalidate(1) - flyweight.fetch(1) + flyweight.fetch(1).await() assertEquals(2, callCount.get(), "New call expected") } } @@ -100,10 +98,10 @@ class FlyweightTest { fun destroy() { runBlocking { val longRunningResult = async { flyweight.fetch(LONG_RUNNING_KEY) } - flyweight.fetch(1) + flyweight.fetch(1).await() flyweight.cancel() try { - flyweight.fetch(1) + flyweight.fetch(1).await() fail("Flyweight should not be fulfilled after it is destroyed") } catch (e: Exception) { assertEquals("Flyweight is not active", e.message, "Incorrect error found on fetch after destruction") |