diff options
author | Allan Wang <me@allanwang.ca> | 2019-01-04 13:53:45 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-01-04 13:53:45 -0500 |
commit | 96418eb38691b634bb176435b72b49971dc07c27 (patch) | |
tree | 170d42cbfaf394e445387f75d5b74b017e1d0923 /app/src/test | |
parent | 535004b8a28d1b227fa0673f80f6086ca8f4be41 (diff) | |
download | frost-96418eb38691b634bb176435b72b49971dc07c27.tar.gz frost-96418eb38691b634bb176435b72b49971dc07c27.tar.bz2 frost-96418eb38691b634bb176435b72b49971dc07c27.zip |
Prepare new test for unique only
Diffstat (limited to 'app/src/test')
-rw-r--r-- | app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt | 39 |
1 files changed, 39 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..32a781df 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/utils/CoroutineTest.kt @@ -16,8 +16,10 @@ */ package com.pitchedapps.frost.utils +import kotlinx.coroutines.CompletableDeferred 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 +33,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 +209,40 @@ 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 completable = CompletableDeferred<Int>() + 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" + ) + } + } } |