From 8b53d07898841b328897c60427e6df9f8c71546e Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 24 Oct 2017 17:40:07 +0200 Subject: 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 --- .../src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt | 51 +++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'opendc-omega/src/test') 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, Process { + override val initialState = Unit + suspend override fun Context.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, Process { + override val initialState = Unit + suspend override fun Context.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() + } } -- cgit v1.2.3