diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2017-10-24 17:40:07 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2017-10-24 18:06:25 +0200 |
| commit | 8b53d07898841b328897c60427e6df9f8c71546e (patch) | |
| tree | 0d8a2b5e399954e7b6138a321752af60cdcf8f60 /opendc-omega/src/test | |
| parent | dad4487fddaccf44240f5d62fa83830f7bbf8a5d (diff) | |
bug(#15): Fix message passing to stopped processes
This change fixes a bug where sending a message to a stopped process
(gracefully or forced) would crash the simulation kernel with an
UninitializedPropertyAccessException.
This was caused by the fact that these processes still existed in the
registry, which caused the kernel to lookup a non-existent continuation
of a process.
This change will make the kernel remove stopped processes from the
registry, so they cannot be found anymore.
Closes #15
Diffstat (limited to 'opendc-omega/src/test')
| -rw-r--r-- | opendc-omega/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/opendc-omega/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt b/opendc-omega/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt index fdc7b033..cb2ce643 100644 --- a/opendc-omega/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt +++ b/opendc-omega/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt @@ -24,8 +24,11 @@ package nl.atlarge.opendc +import nl.atlarge.opendc.kernel.Context +import nl.atlarge.opendc.kernel.Process import nl.atlarge.opendc.kernel.omega.OmegaKernel import nl.atlarge.opendc.topology.AdjacencyList +import nl.atlarge.opendc.topology.Entity import nl.atlarge.opendc.topology.machine.Machine import org.junit.jupiter.api.Test @@ -44,7 +47,7 @@ internal class SmokeTest { val builder = AdjacencyList.builder() repeat(n) { val root = Machine() - val topology = AdjacencyList.builder().construct { + val topology = builder.construct { add(root) val other = Machine() @@ -63,4 +66,50 @@ internal class SmokeTest { simulation.run() } } + + class NullProcess : Entity<Unit>, Process<NullProcess> { + override val initialState = Unit + suspend override fun Context<NullProcess>.run() {} + } + + /** + * Test if the kernel allows sending messages to [Process] instances that have already stopped. + */ + @Test + fun `sending message to process that has gracefully stopped`() { + + val builder = AdjacencyList.builder() + val process = NullProcess() + val topology = builder.construct { + add(process) + } + + val simulation = OmegaKernel.create(topology) + simulation.schedule(0, process) + simulation.run() + } + + class CrashProcess : Entity<Unit>, Process<NullProcess> { + override val initialState = Unit + suspend override fun Context<NullProcess>.run() { + TODO() + } + } + + /** + * Test if the kernel allows sending messages to [Process] instances that have crashed. + */ + @Test + fun `sending message to process that has crashed`() { + + val builder = AdjacencyList.builder() + val process = CrashProcess() + val topology = builder.construct { + add(process) + } + + val simulation = OmegaKernel.create(topology) + simulation.schedule(0, process) + simulation.run() + } } |
