Skip to content

Commit 7c05911

Browse files
committed
Added basic unit test for AtomicExecutor
1 parent 31ca6e3 commit 7c05911

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.ably.chat
2+
3+
import java.util.concurrent.Executors
4+
import kotlinx.coroutines.CoroutineScope
5+
import kotlinx.coroutines.asCoroutineDispatcher
6+
import kotlinx.coroutines.delay
7+
import kotlinx.coroutines.test.runTest
8+
import org.junit.Assert.assertEquals
9+
import org.junit.Test
10+
11+
class AtomicExecutorTest {
12+
13+
@Test
14+
fun `should perform given operation`() = runTest {
15+
val singleThreadedDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
16+
val atomicExecutor = AtomicExecutor(CoroutineScope(singleThreadedDispatcher))
17+
val deferred = atomicExecutor.execute {
18+
delay(5000)
19+
return@execute "Hello"
20+
}
21+
val result = deferred.receive()
22+
assert(result.isSuccess)
23+
assertEquals("Hello", result.getOrNull())
24+
}
25+
}

0 commit comments

Comments
 (0)