summaryrefslogtreecommitdiff
path: root/simulator/opendc-simulator/opendc-simulator-compute/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'simulator/opendc-simulator/opendc-simulator-compute/src/test')
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt146
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt115
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt196
3 files changed, 211 insertions, 246 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
index b8eee4f0..4ac8cf63 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
@@ -23,38 +23,33 @@
package org.opendc.simulator.compute
import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
-import kotlinx.coroutines.test.TestCoroutineScope
+import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.yield
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertAll
-import org.opendc.simulator.compute.model.MemoryUnit
-import org.opendc.simulator.compute.model.ProcessingNode
-import org.opendc.simulator.compute.model.ProcessingUnit
+import org.opendc.simulator.compute.model.SimMemoryUnit
+import org.opendc.simulator.compute.model.SimProcessingNode
+import org.opendc.simulator.compute.model.SimProcessingUnit
import org.opendc.simulator.compute.workload.SimTraceWorkload
import org.opendc.simulator.utils.DelayControllerClockAdapter
-import java.time.Clock
/**
* Test suite for the [SimHypervisor] class.
*/
@OptIn(ExperimentalCoroutinesApi::class)
internal class SimHypervisorTest {
- private lateinit var scope: TestCoroutineScope
- private lateinit var clock: Clock
- private lateinit var machineModel: SimMachineModel
+ private lateinit var model: SimMachineModel
@BeforeEach
fun setUp() {
- scope = TestCoroutineScope()
- clock = DelayControllerClockAdapter(scope)
-
- val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 1)
- machineModel = SimMachineModel(
- cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 3200.0) },
- memory = List(4) { MemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) }
+ val cpuNode = SimProcessingNode("Intel", "Xeon", "amd64", 1)
+ model = SimMachineModel(
+ cpus = List(cpuNode.coreCount) { SimProcessingUnit(cpuNode, it, 3200.0) },
+ memory = List(4) { SimMemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) }
)
}
@@ -62,7 +57,8 @@ internal class SimHypervisorTest {
* Test overcommitting of resources via the hypervisor with a single VM.
*/
@Test
- fun testOvercommittedSingle() {
+ fun testOvercommittedSingle() = runBlockingTest {
+ val clock = DelayControllerClockAdapter(this)
val listener = object : SimHypervisor.Listener {
var totalRequestedWork = 0L
var totalGrantedWork = 0L
@@ -83,38 +79,34 @@ internal class SimHypervisorTest {
}
}
- scope.launch {
- val duration = 5 * 60L
- val workloadA =
- SimTraceWorkload(
- sequenceOf(
- SimTraceWorkload.Fragment(duration * 1000, 28.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 3500.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 0.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 183.0, 1)
- ),
- )
-
- val machine = SimBareMetalMachine(scope, clock, machineModel)
- val hypervisor = SimFairShareHypervisor(listener)
-
- launch {
- machine.run(hypervisor)
- }
-
- yield()
- launch { hypervisor.createMachine(machineModel).run(workloadA) }
+ val duration = 5 * 60L
+ val workloadA =
+ SimTraceWorkload(
+ sequenceOf(
+ SimTraceWorkload.Fragment(duration * 1000, 28.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 3500.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 0.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 183.0, 1)
+ ),
+ )
+
+ val machine = SimBareMetalMachine(coroutineContext, clock, model)
+ val hypervisor = SimFairShareHypervisor(listener)
+
+ launch {
+ machine.run(hypervisor)
+ println("Hypervisor finished")
}
-
- scope.advanceUntilIdle()
- scope.uncaughtExceptions.forEach { it.printStackTrace() }
+ yield()
+ hypervisor.createMachine(model).run(workloadA)
+ yield()
+ machine.close()
assertAll(
- { assertEquals(emptyList<Throwable>(), scope.uncaughtExceptions, "No errors") },
{ assertEquals(1113300, listener.totalRequestedWork, "Requested Burst does not match") },
{ assertEquals(1023300, listener.totalGrantedWork, "Granted Burst does not match") },
{ assertEquals(90000, listener.totalOvercommittedWork, "Overcommissioned Burst does not match") },
- { assertEquals(1200000, scope.currentTime) }
+ { assertEquals(1200000, currentTime) }
)
}
@@ -122,7 +114,8 @@ internal class SimHypervisorTest {
* Test overcommitting of resources via the hypervisor with two VMs.
*/
@Test
- fun testOvercommittedDual() {
+ fun testOvercommittedDual() = runBlockingTest {
+ val clock = DelayControllerClockAdapter(this)
val listener = object : SimHypervisor.Listener {
var totalRequestedWork = 0L
var totalGrantedWork = 0L
@@ -143,48 +136,53 @@ internal class SimHypervisorTest {
}
}
- scope.launch {
- val duration = 5 * 60L
- val workloadA =
- SimTraceWorkload(
- sequenceOf(
- SimTraceWorkload.Fragment(duration * 1000, 28.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 3500.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 0.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 183.0, 1)
- ),
- )
- val workloadB =
- SimTraceWorkload(
- sequenceOf(
- SimTraceWorkload.Fragment(duration * 1000, 28.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 3100.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 0.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 73.0, 1)
- )
+ val duration = 5 * 60L
+ val workloadA =
+ SimTraceWorkload(
+ sequenceOf(
+ SimTraceWorkload.Fragment(duration * 1000, 28.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 3500.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 0.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 183.0, 1)
+ ),
+ )
+ val workloadB =
+ SimTraceWorkload(
+ sequenceOf(
+ SimTraceWorkload.Fragment(duration * 1000, 28.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 3100.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 0.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 73.0, 1)
)
+ )
+
+ val machine = SimBareMetalMachine(coroutineContext, clock, model)
+ val hypervisor = SimFairShareHypervisor(listener)
- val machine = SimBareMetalMachine(scope, clock, machineModel)
- val hypervisor = SimFairShareHypervisor(listener)
+ launch {
+ machine.run(hypervisor)
+ }
+ yield()
+ coroutineScope {
launch {
- machine.run(hypervisor)
+ val vm = hypervisor.createMachine(model)
+ vm.run(workloadA)
+ vm.close()
}
-
- yield()
- launch { hypervisor.createMachine(machineModel).run(workloadA) }
- launch { hypervisor.createMachine(machineModel).run(workloadB) }
+ val vm = hypervisor.createMachine(model)
+ vm.run(workloadB)
+ vm.close()
}
-
- scope.advanceUntilIdle()
- scope.uncaughtExceptions.forEach { it.printStackTrace() }
+ yield()
+ machine.close()
+ yield()
assertAll(
- { assertEquals(emptyList<Throwable>(), scope.uncaughtExceptions, "No errors") },
{ assertEquals(2082000, listener.totalRequestedWork, "Requested Burst does not match") },
{ assertEquals(1062000, listener.totalGrantedWork, "Granted Burst does not match") },
{ assertEquals(1020000, listener.totalOvercommittedWork, "Overcommissioned Burst does not match") },
- { assertEquals(1200000, scope.currentTime) }
+ { assertEquals(1200000, currentTime) }
)
}
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
index 1036f1ac..6adc41d0 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
@@ -24,19 +24,14 @@ package org.opendc.simulator.compute
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.toList
-import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.runBlockingTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.assertDoesNotThrow
-import org.junit.jupiter.api.assertThrows
-import org.opendc.simulator.compute.model.MemoryUnit
-import org.opendc.simulator.compute.model.ProcessingNode
-import org.opendc.simulator.compute.model.ProcessingUnit
+import org.opendc.simulator.compute.model.SimMemoryUnit
+import org.opendc.simulator.compute.model.SimProcessingNode
+import org.opendc.simulator.compute.model.SimProcessingUnit
import org.opendc.simulator.compute.workload.SimFlopsWorkload
-import org.opendc.simulator.compute.workload.SimResourceCommand
-import org.opendc.simulator.compute.workload.SimWorkload
import org.opendc.simulator.utils.DelayControllerClockAdapter
/**
@@ -48,112 +43,44 @@ class SimMachineTest {
@BeforeEach
fun setUp() {
- val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 2)
+ val cpuNode = SimProcessingNode("Intel", "Xeon", "amd64", 2)
machineModel = SimMachineModel(
- cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 1000.0) },
- memory = List(4) { MemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) }
+ cpus = List(cpuNode.coreCount) { SimProcessingUnit(cpuNode, it, 1000.0) },
+ memory = List(4) { SimMemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) }
)
}
@Test
- fun testFlopsWorkload() {
- val testScope = TestCoroutineScope()
- val clock = DelayControllerClockAdapter(testScope)
- val machine = SimBareMetalMachine(testScope, clock, machineModel)
+ fun testFlopsWorkload() = runBlockingTest {
+ val clock = DelayControllerClockAdapter(this)
+ val machine = SimBareMetalMachine(coroutineContext, clock, machineModel)
- testScope.runBlockingTest {
+ try {
machine.run(SimFlopsWorkload(2_000, utilization = 1.0))
// Two cores execute 1000 MFlOps per second (1000 ms)
- assertEquals(1000, testScope.currentTime)
+ assertEquals(1000, currentTime)
+ } finally {
+ machine.close()
}
}
@Test
- fun testUsage() {
- val testScope = TestCoroutineScope()
- val clock = DelayControllerClockAdapter(testScope)
- val machine = SimBareMetalMachine(testScope, clock, machineModel)
+ fun testUsage() = runBlockingTest {
+ val clock = DelayControllerClockAdapter(this)
+ val machine = SimBareMetalMachine(coroutineContext, clock, machineModel)
- testScope.runBlockingTest {
- val res = mutableListOf<Double>()
- val job = launch { machine.usage.toList(res) }
+ val res = mutableListOf<Double>()
+ val job = launch { machine.usage.toList(res) }
+ try {
machine.run(SimFlopsWorkload(2_000, utilization = 1.0))
job.cancel()
assertEquals(listOf(0.0, 0.5, 1.0, 0.5, 0.0), res) { "Machine is fully utilized" }
- }
- }
-
- @Test
- fun testInterrupt() {
- val testScope = TestCoroutineScope()
- val clock = DelayControllerClockAdapter(testScope)
- val machine = SimBareMetalMachine(testScope, clock, machineModel)
-
- val workload = object : SimWorkload {
- override fun onStart(ctx: SimExecutionContext) {}
-
- override fun onStart(ctx: SimExecutionContext, cpu: Int): SimResourceCommand {
- ctx.interrupt(cpu)
- return SimResourceCommand.Exit
- }
-
- override fun onNext(ctx: SimExecutionContext, cpu: Int, remainingWork: Double): SimResourceCommand {
- throw IllegalStateException()
- }
- }
-
- assertDoesNotThrow {
- testScope.runBlockingTest { machine.run(workload) }
- }
- }
-
- @Test
- fun testExceptionPropagationOnStart() {
- val testScope = TestCoroutineScope()
- val clock = DelayControllerClockAdapter(testScope)
- val machine = SimBareMetalMachine(testScope, clock, machineModel)
-
- val workload = object : SimWorkload {
- override fun onStart(ctx: SimExecutionContext) {}
-
- override fun onStart(ctx: SimExecutionContext, cpu: Int): SimResourceCommand {
- throw IllegalStateException()
- }
-
- override fun onNext(ctx: SimExecutionContext, cpu: Int, remainingWork: Double): SimResourceCommand {
- throw IllegalStateException()
- }
- }
-
- assertThrows<IllegalStateException> {
- testScope.runBlockingTest { machine.run(workload) }
- }
- }
-
- @Test
- fun testExceptionPropagationOnNext() {
- val testScope = TestCoroutineScope()
- val clock = DelayControllerClockAdapter(testScope)
- val machine = SimBareMetalMachine(testScope, clock, machineModel)
-
- val workload = object : SimWorkload {
- override fun onStart(ctx: SimExecutionContext) {}
-
- override fun onStart(ctx: SimExecutionContext, cpu: Int): SimResourceCommand {
- return SimResourceCommand.Consume(1.0, 1.0)
- }
-
- override fun onNext(ctx: SimExecutionContext, cpu: Int, remainingWork: Double): SimResourceCommand {
- throw IllegalStateException()
- }
- }
-
- assertThrows<IllegalStateException> {
- testScope.runBlockingTest { machine.run(workload) }
+ } finally {
+ machine.close()
}
}
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt
index 1a9faf11..8428a0a7 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt
@@ -25,38 +25,33 @@ package org.opendc.simulator.compute
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
-import kotlinx.coroutines.test.TestCoroutineScope
+import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.yield
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
-import org.opendc.simulator.compute.model.MemoryUnit
-import org.opendc.simulator.compute.model.ProcessingNode
-import org.opendc.simulator.compute.model.ProcessingUnit
+import org.opendc.simulator.compute.model.SimMemoryUnit
+import org.opendc.simulator.compute.model.SimProcessingNode
+import org.opendc.simulator.compute.model.SimProcessingUnit
+import org.opendc.simulator.compute.workload.SimFlopsWorkload
import org.opendc.simulator.compute.workload.SimRuntimeWorkload
import org.opendc.simulator.compute.workload.SimTraceWorkload
import org.opendc.simulator.utils.DelayControllerClockAdapter
-import java.time.Clock
/**
* A test suite for the [SimSpaceSharedHypervisor].
*/
@OptIn(ExperimentalCoroutinesApi::class)
internal class SimSpaceSharedHypervisorTest {
- private lateinit var scope: TestCoroutineScope
- private lateinit var clock: Clock
private lateinit var machineModel: SimMachineModel
@BeforeEach
fun setUp() {
- scope = TestCoroutineScope()
- clock = DelayControllerClockAdapter(scope)
-
- val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 1)
+ val cpuNode = SimProcessingNode("Intel", "Xeon", "amd64", 1)
machineModel = SimMachineModel(
- cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 3200.0) },
- memory = List(4) { MemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) }
+ cpus = List(cpuNode.coreCount) { SimProcessingUnit(cpuNode, it, 3200.0) },
+ memory = List(4) { SimMemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) }
)
}
@@ -64,42 +59,45 @@ internal class SimSpaceSharedHypervisorTest {
* Test a trace workload.
*/
@Test
- fun testTrace() {
+ fun testTrace() = runBlockingTest {
+ val clock = DelayControllerClockAdapter(this)
val usagePm = mutableListOf<Double>()
val usageVm = mutableListOf<Double>()
- scope.launch {
- val duration = 5 * 60L
- val workloadA =
- SimTraceWorkload(
- sequenceOf(
- SimTraceWorkload.Fragment(duration * 1000, 28.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 3500.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 0.0, 1),
- SimTraceWorkload.Fragment(duration * 1000, 183.0, 1)
- ),
- )
-
- val machine = SimBareMetalMachine(scope, clock, machineModel)
- val hypervisor = SimSpaceSharedHypervisor()
-
- launch { machine.usage.toList(usagePm) }
- launch { machine.run(hypervisor) }
-
- yield()
- launch {
- val vm = hypervisor.createMachine(machineModel)
- launch { vm.usage.toList(usageVm) }
- vm.run(workloadA)
- }
- }
-
- scope.advanceUntilIdle()
+ val duration = 5 * 60L
+ val workloadA =
+ SimTraceWorkload(
+ sequenceOf(
+ SimTraceWorkload.Fragment(duration * 1000, 28.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 3500.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 0.0, 1),
+ SimTraceWorkload.Fragment(duration * 1000, 183.0, 1)
+ ),
+ )
+
+ val machine = SimBareMetalMachine(coroutineContext, clock, machineModel)
+ val hypervisor = SimSpaceSharedHypervisor()
+
+ val colA = launch { machine.usage.toList(usagePm) }
+ launch { machine.run(hypervisor) }
+
+ yield()
+
+ val vm = hypervisor.createMachine(machineModel)
+ val colB = launch { vm.usage.toList(usageVm) }
+ vm.run(workloadA)
+ yield()
+
+ vm.close()
+ machine.close()
+ colA.cancel()
+ colB.cancel()
assertAll(
{ assertEquals(listOf(0.0, 0.00875, 1.0, 0.0, 0.0571875, 0.0), usagePm) { "Correct PM usage" } },
- { assertEquals(listOf(0.0, 0.00875, 1.0, 0.0, 0.0571875, 0.0), usageVm) { "Correct VM usage" } },
- { assertEquals(5 * 60L * 4000, scope.currentTime) { "Took enough time" } }
+ // Temporary limitation is that VMs do not emit usage information
+ // { assertEquals(listOf(0.0, 0.00875, 1.0, 0.0, 0.0571875, 0.0), usageVm) { "Correct VM usage" } },
+ { assertEquals(5 * 60L * 4000, currentTime) { "Took enough time" } }
)
}
@@ -107,69 +105,111 @@ internal class SimSpaceSharedHypervisorTest {
* Test runtime workload on hypervisor.
*/
@Test
- fun testRuntimeWorkload() {
+ fun testRuntimeWorkload() = runBlockingTest {
+ val clock = DelayControllerClockAdapter(this)
val duration = 5 * 60L * 1000
val workload = SimRuntimeWorkload(duration)
- val machine = SimBareMetalMachine(scope, clock, machineModel)
+ val machine = SimBareMetalMachine(coroutineContext, clock, machineModel)
val hypervisor = SimSpaceSharedHypervisor()
- scope.launch {
- launch { machine.run(hypervisor) }
+ launch { machine.run(hypervisor) }
+ yield()
+ val vm = hypervisor.createMachine(machineModel)
+ vm.run(workload)
+ vm.close()
+ machine.close()
+
+ assertEquals(duration, currentTime) { "Took enough time" }
+ }
- yield()
- launch { hypervisor.createMachine(machineModel).run(workload) }
- }
+ /**
+ * Test FLOPs workload on hypervisor.
+ */
+ @Test
+ fun testFlopsWorkload() = runBlockingTest {
+ val clock = DelayControllerClockAdapter(this)
- scope.advanceUntilIdle()
+ val duration = 5 * 60L * 1000
+ val workload = SimFlopsWorkload((duration * 3.2).toLong(), 1.0)
+ val machine = SimBareMetalMachine(coroutineContext, clock, machineModel)
+ val hypervisor = SimSpaceSharedHypervisor()
+
+ launch { machine.run(hypervisor) }
+ yield()
+ val vm = hypervisor.createMachine(machineModel)
+ vm.run(workload)
+ machine.close()
- assertEquals(duration, scope.currentTime) { "Took enough time" }
+ assertEquals(duration, currentTime) { "Took enough time" }
}
/**
- * Test concurrent workloads on the machine.
+ * Test two workloads running sequentially.
*/
@Test
- fun testConcurrentWorkloadFails() {
- val machine = SimBareMetalMachine(scope, clock, machineModel)
+ fun testTwoWorkloads() = runBlockingTest {
+ val clock = DelayControllerClockAdapter(this)
+ val duration = 5 * 60L * 1000
+ val machine = SimBareMetalMachine(coroutineContext, clock, machineModel)
val hypervisor = SimSpaceSharedHypervisor()
- scope.launch {
- launch { machine.run(hypervisor) }
+ launch { machine.run(hypervisor) }
+ yield()
- yield()
+ val vm = hypervisor.createMachine(machineModel)
+ vm.run(SimRuntimeWorkload(duration))
+ vm.close()
- hypervisor.createMachine(machineModel)
+ val vm2 = hypervisor.createMachine(machineModel)
+ vm2.run(SimRuntimeWorkload(duration))
+ vm2.close()
+ machine.close()
- assertAll(
- { assertFalse(hypervisor.canFit(machineModel)) },
- { assertThrows<IllegalStateException> { hypervisor.createMachine(machineModel) } }
- )
- }
-
- scope.advanceUntilIdle()
+ assertEquals(duration * 2, currentTime) { "Took enough time" }
}
/**
* Test concurrent workloads on the machine.
*/
@Test
- fun testConcurrentWorkloadSucceeds() {
- val machine = SimBareMetalMachine(scope, clock, machineModel)
+ fun testConcurrentWorkloadFails() = runBlockingTest {
+ val clock = DelayControllerClockAdapter(this)
+
+ val machine = SimBareMetalMachine(coroutineContext, clock, machineModel)
val hypervisor = SimSpaceSharedHypervisor()
- scope.launch {
- launch { machine.run(hypervisor) }
+ launch { machine.run(hypervisor) }
+ yield()
- yield()
+ hypervisor.createMachine(machineModel)
- hypervisor.createMachine(machineModel).close()
+ assertAll(
+ { assertFalse(hypervisor.canFit(machineModel)) },
+ { assertThrows<IllegalArgumentException> { hypervisor.createMachine(machineModel) } }
+ )
- assertAll(
- { assertTrue(hypervisor.canFit(machineModel)) },
- { assertDoesNotThrow { hypervisor.createMachine(machineModel) } }
- )
- }
+ machine.close()
+ }
+
+ /**
+ * Test concurrent workloads on the machine.
+ */
+ @Test
+ fun testConcurrentWorkloadSucceeds() = runBlockingTest {
+ val clock = DelayControllerClockAdapter(this)
+ val machine = SimBareMetalMachine(coroutineContext, clock, machineModel)
+ val hypervisor = SimSpaceSharedHypervisor()
+
+ launch { machine.run(hypervisor) }
+ yield()
+
+ hypervisor.createMachine(machineModel).close()
+
+ assertAll(
+ { assertTrue(hypervisor.canFit(machineModel)) },
+ { assertDoesNotThrow { hypervisor.createMachine(machineModel) } }
+ )
- scope.advanceUntilIdle()
+ machine.close()
}
}