summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-17 22:03:02 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-28 15:01:55 +0200
commitd5aed4b1e6e5548728c5978e3b46d1472b62e791 (patch)
tree5ceb12076922ab5e3c724a451150b2b74791314b /opendc-compute/opendc-compute-simulator/src/test
parenteb105ae96191d99745c145e5ef0959f5e5c77fc4 (diff)
refactor(compute/sim): Use workload chaining for boot delay
This change updates the implementation of `SimHost` to use workload chaining for modelling boot delays. Previously, this was implemented by sleeping 1 millisecond using Kotlin coroutines. With this change, we remove the need for coroutines and instead use the `SimDurationWorkload` to model the boot delay. In the future, we envision a user-supplied stochastic boot model to model the boot delay for VM instances.
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src/test')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/SimHostTest.kt70
1 files changed, 68 insertions, 2 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 a5999bcd..02be3f28 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
@@ -70,6 +70,74 @@ internal class SimHostTest {
}
/**
+ * Test a single virtual machine hosted by the hypervisor.
+ */
+ @Test
+ fun testSingle() = runSimulation {
+ val duration = 5 * 60L
+
+ val engine = FlowEngine.create(coroutineContext, clock)
+ val graph = engine.newGraph()
+
+ val machine = SimBareMetalMachine.create(graph, machineModel)
+ val hypervisor = SimHypervisor.create(FlowMultiplexerFactory.maxMinMultiplexer(), SplittableRandom(1))
+
+ val host = SimHost(
+ uid = UUID.randomUUID(),
+ name = "test",
+ meta = emptyMap(),
+ graph,
+ machine,
+ hypervisor
+ )
+ val vmImage = MockImage(
+ UUID.randomUUID(),
+ "<unnamed>",
+ emptyMap(),
+ mapOf(
+ "workload" to
+ SimTrace.ofFragments(
+ SimTraceFragment(0, duration * 1000, 2 * 28.0, 2),
+ SimTraceFragment(duration * 1000, duration * 1000, 2 * 3500.0, 2),
+ SimTraceFragment(duration * 2000, duration * 1000, 0.0, 2),
+ SimTraceFragment(duration * 3000, duration * 1000, 2 * 183.0, 2)
+ ).createWorkload(1)
+ )
+ )
+
+ 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
+
+ override fun onStateChanged(host: Host, server: Server, newState: ServerState) {
+ if (newState == ServerState.TERMINATED && ++finished == 1) {
+ cont.resume(Unit)
+ }
+ }
+ })
+ }
+ }
+
+ // Ensure last cycle is collected
+ delay(1000L * duration)
+ host.close()
+
+ val cpuStats = host.getCpuStats()
+
+ assertAll(
+ { assertEquals(639, cpuStats.activeTime, "Active time does not match") },
+ { assertEquals(2360, cpuStats.idleTime, "Idle time does not match") },
+ { assertEquals(56, cpuStats.stealTime, "Steal time does not match") },
+ { assertEquals(1500001, clock.millis()) }
+ )
+ }
+
+ /**
* Test overcommitting of resources by the hypervisor.
*/
@Test
@@ -86,7 +154,6 @@ internal class SimHostTest {
uid = UUID.randomUUID(),
name = "test",
meta = emptyMap(),
- coroutineContext,
graph,
machine,
hypervisor
@@ -169,7 +236,6 @@ internal class SimHostTest {
uid = UUID.randomUUID(),
name = "test",
meta = emptyMap(),
- coroutineContext,
graph,
machine,
hypervisor