diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-10-28 14:37:22 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-10-28 15:24:17 +0200 |
| commit | dd5bbd55fc6e25efdfe93ec16bd37c5350e04c16 (patch) | |
| tree | 30b4cb964836b57632404ccd944fbf03e0eb32eb /opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute | |
| parent | c6f2d16a20bfac466480c0e98341b08b12fc0772 (diff) | |
refactor(compute/service): Do not suspend on guest start
This change updates the `Host` interface to remove the suspend modifiers
to the start, stop, spawn, and delete methods of this interface. We now
assume that the host immediately launches the guest on invocation of
this method.
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute')
| -rw-r--r-- | opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt index 27151422..fc581d3e 100644 --- a/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt +++ b/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt @@ -24,7 +24,6 @@ package org.opendc.compute.simulator import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay -import kotlinx.coroutines.launch import kotlinx.coroutines.suspendCancellableCoroutine import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach @@ -107,20 +106,19 @@ internal class SimHostTest { val flavor = MockFlavor(2, 0) - coroutineScope { - launch { host.spawn(MockServer(UUID.randomUUID(), "a", flavor, vmImage)) } + suspendCancellableCoroutine { cont -> + host.addListener(object : HostListener { + private var finished = 0 - suspendCancellableCoroutine { cont -> - host.addListener(object : HostListener { - private var finished = 0 - - override fun onStateChanged(host: Host, server: Server, newState: ServerState) { - if (newState == ServerState.TERMINATED && ++finished == 1) { - cont.resume(Unit) - } + override fun onStateChanged(host: Host, server: Server, newState: ServerState) { + if (newState == ServerState.TERMINATED && ++finished == 1) { + cont.resume(Unit) } - }) - } + } + }) + val server = MockServer(UUID.randomUUID(), "a", flavor, vmImage) + host.spawn(server) + host.start(server) } // Ensure last cycle is collected @@ -190,9 +188,6 @@ internal class SimHostTest { val flavor = MockFlavor(2, 0) coroutineScope { - launch { host.spawn(MockServer(UUID.randomUUID(), "a", flavor, vmImageA)) } - launch { host.spawn(MockServer(UUID.randomUUID(), "b", flavor, vmImageB)) } - suspendCancellableCoroutine { cont -> host.addListener(object : HostListener { private var finished = 0 @@ -203,6 +198,13 @@ internal class SimHostTest { } } }) + val serverA = MockServer(UUID.randomUUID(), "a", flavor, vmImageA) + host.spawn(serverA) + val serverB = MockServer(UUID.randomUUID(), "b", flavor, vmImageB) + host.spawn(serverB) + + host.start(serverA) + host.start(serverB) } } @@ -259,12 +261,13 @@ internal class SimHostTest { coroutineScope { host.spawn(server) + host.start(server) delay(5000L) host.fail() delay(duration * 1000) host.recover() - suspendCancellableCoroutine<Unit> { cont -> + suspendCancellableCoroutine { cont -> host.addListener(object : HostListener { override fun onStateChanged(host: Host, server: Server, newState: ServerState) { if (newState == ServerState.TERMINATED) { |
