aboutsummaryrefslogtreecommitdiff
path: root/app/src/test/kotlin/com/pitchedapps/frost/utils
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-01-05 00:26:37 -0500
committerGitHub <noreply@github.com>2019-01-05 00:26:37 -0500
commit5c89202f74f68ee6f273296014b5fff837520246 (patch)
tree08245d02eb04045ec2c5d475ce6db4efe481a412 /app/src/test/kotlin/com/pitchedapps/frost/utils
parent8c77e02e89dfec7bff04a397dfc82613ccd1242a (diff)
parent635bdddebbc52ec67cfb157830c3fc8b32f9a6e7 (diff)
downloadfrost-5c89202f74f68ee6f273296014b5fff837520246.tar.gz
frost-5c89202f74f68ee6f273296014b5fff837520246.tar.bz2
frost-5c89202f74f68ee6f273296014b5fff837520246.zip
Merge pull request #1313 from AllanWang/enhancement/deferred
Enhancement/deferred
Diffstat (limited to 'app/src/test/kotlin/com/pitchedapps/frost/utils')
-rw-r--r--app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt37
1 files changed, 37 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 72eb6076..e7520794 100644
--- a/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt
+++ b/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt
@@ -18,6 +18,7 @@ package com.pitchedapps.frost.utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.async
import kotlinx.coroutines.channels.BroadcastChannel
@@ -31,6 +32,7 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.util.concurrent.Executors
import kotlin.coroutines.EmptyCoroutineContext
+import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
@@ -206,4 +208,39 @@ class CoroutineTest {
)
}
}
+
+ /**
+ * When using [uniqueOnly] for channels with limited capacity,
+ * the duplicates should not count towards the actual capacity
+ */
+ @Ignore("Not yet working as unique only buffered removes the capacity limitation of the channel")
+ @Test
+ fun uniqueOnlyBuffer() {
+ val channel = Channel<Int>(3)
+ runBlocking {
+
+ val deferred = async {
+ listen(channel.uniqueOnly(GlobalScope)) {
+ // Throttle consumer
+ delay(50)
+ return@listen false
+ }
+ }
+
+ listOf(0, 1, 1, 1, 1, 1, 2, 2, 2).forEach {
+ delay(10)
+ channel.offer(it)
+ }
+
+ channel.close()
+
+ val data = deferred.await()
+
+ assertEquals(
+ listOf(0, 1, 2),
+ data,
+ "Unique receiver should not have two consecutive events that are equal"
+ )
+ }
+ }
}