summaryrefslogtreecommitdiff
path: root/odcsim-core/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2019-05-13 20:45:49 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2019-05-14 12:55:57 +0200
commit720d1f433e0fed0ee48cbebdb8f995e5d5fc7405 (patch)
tree21c5828f6dd6e0551e2675ef6fa73118818b797a /odcsim-core/src/test
parent03acc77d4f2841ea66a9200ab170e33a2d0518aa (diff)
bug: Replace initial behavior after starting coroutine
This change fixes the bug where suspending immediately after launching the coroutine, without replacing the current behavior causes a failure in the BehaviorInterpreter. This is because the initial behavior was not properly set.
Diffstat (limited to 'odcsim-core/src/test')
-rw-r--r--odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt15
1 files changed, 14 insertions, 1 deletions
diff --git a/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt b/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt
index 98486149..d057024c 100644
--- a/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt
+++ b/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt
@@ -32,19 +32,32 @@ import com.nhaarman.mockitokotlin2.mock
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
+import kotlin.coroutines.suspendCoroutine
/**
* Test suite for [SuspendingBehavior] using Kotlin Coroutines.
*/
@DisplayName("Coroutines")
internal class CoroutinesTest {
- private val ctx = mock<ActorContext<Nothing>>()
@Test
fun `should immediately return new behavior`() {
+ val ctx = mock<ActorContext<Nothing>>()
val behavior = suspending<Nothing> { empty() }
val interpreter = BehaviorInterpreter(behavior)
interpreter.start(ctx)
assertTrue(interpreter.behavior as Behavior<*> is EmptyBehavior)
}
+
+ @Test
+ fun `should be able to invoke regular suspend methods`() {
+ val ctx = mock<ActorContext<Unit>>()
+ val behavior = suspending<Unit> {
+ suspendCoroutine<Unit> { cont -> }
+ stopped()
+ }
+ val interpreter = BehaviorInterpreter(behavior)
+ interpreter.start(ctx)
+ interpreter.interpretMessage(ctx, Unit)
+ }
}