From 282ec38acd6efc379f2b260d21a359ca76684843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Galland?= Date: Tue, 24 Mar 2020 19:05:51 +0100 Subject: [PATCH] [sre][tests] Reimplementing the test for issue #977 with the newt testing API. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Galland --- .../tests/runtime/bugs/bug977/Bug977Test.sarl | 19 ++++++++++++++++--- .../bugs/bug977/mocks/AbstractAgent.sarl | 17 +++++++---------- .../bugs/bug977/mocks/HelloChildAgent.sarl | 16 ++++++++++------ .../mocks/SharedGuardEvaluationAgent0.sarl | 9 +++++++++ .../mocks/SharedGuardEvaluationAgent1.sarl | 9 ++++++++- 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/Bug977Test.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/Bug977Test.sarl index 5fd892ea03..8b1f9d9521 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/Bug977Test.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/Bug977Test.sarl @@ -26,12 +26,15 @@ import io.sarl.sre.test.framework.^extension.SreRunExtension import io.sarl.sre.tests.runtime.bugs.bug977.mocks.HelloChildAgent import io.sarl.sre.tests.runtime.bugs.bug977.mocks.SharedGuardEvaluationAgent0 import io.sarl.sre.tests.runtime.bugs.bug977.mocks.SharedGuardEvaluationAgent1 +import io.sarl.sre.tests.runtime.internal.mocks.Bye import io.sarl.tests.api.extensions.ContextInitExtension import io.sarl.tests.api.extensions.JavaVersionCheckExtension +import java.util.UUID import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.RepeatedTest import org.junit.jupiter.api.RepetitionInfo import org.junit.jupiter.api.Tag +import org.junit.jupiter.api.Test import org.junit.jupiter.api.^extension.ExtendWith import static extension io.sarl.tests.api.tools.TestAssertions.* @@ -56,12 +59,22 @@ import static extension io.sarl.tests.api.tools.TestAssertions.* @Tag("run") class Bug977Test { - @RepeatedTest(10) + //@RepeatedTest(10) + @Test @DisplayName("Inheritance of event handlers and functions") def runInheritanceBehaviorExampleCode(extension rc : SreRunContext) : void { - typeof(HelloChildAgent).runSre + var kern = setupTheSreKernel(null, null) - val all = getResults(bootAgentId) + val id0 = UUID::randomUUID + waitForAgentSpawned(id0) [ + kern.startAgentWithID(typeof(HelloChildAgent), id0, buildAgentInitializationParameters(1, null)) + ] + + rootContext.defaultSpace.emit(UUID::randomUUID, new Bye) + + waitForTheKernel(-1)//STANDARD_TIMEOUT) + + val all = getResults(id0) all.assertContains( // Execute: on Initialize diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/AbstractAgent.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/AbstractAgent.sarl index 5de05a1696..d9b65cfc32 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/AbstractAgent.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/AbstractAgent.sarl @@ -25,33 +25,30 @@ import io.sarl.core.Destroy import io.sarl.core.Initialize import io.sarl.sre.test.framework.skills.TestingCapacity import io.sarl.sre.test.framework.skills.TestingSkill +import java.util.concurrent.atomic.AtomicInteger abstract agent AbstractAgent { - protected var i : int = 0 + protected var i = new AtomicInteger(0) uses TestingCapacity - def ensureSkill(e : Initialize) : void { - setSkill(new TestingSkill(e)) - } - on Initialize { - occurrence.ensureSkill + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("1") } on Initialize [i < 0] { - occurrence.ensureSkill + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("-1-") - i++ + i.incrementAndGet } /* A disjoint condition from the previous */ on Initialize [i >= 0] { - occurrence.ensureSkill + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("2") - i-- + i.decrementAndGet } def sayGoodBye : void { diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/HelloChildAgent.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/HelloChildAgent.sarl index 26e984fd13..e401f6cced 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/HelloChildAgent.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/HelloChildAgent.sarl @@ -24,28 +24,28 @@ package io.sarl.sre.tests.runtime.bugs.bug977.mocks import io.sarl.core.Destroy import io.sarl.core.Initialize import io.sarl.core.Lifecycle -import io.sarl.core.Schedules import io.sarl.sre.test.framework.skills.TestingCapacity +import io.sarl.sre.test.framework.skills.TestingSkill +import io.sarl.sre.tests.runtime.internal.mocks.Bye agent HelloChildAgent extends AbstractAgent { - uses Lifecycle, Schedules + uses Lifecycle uses TestingCapacity on Initialize { - occurrence.ensureSkill + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("3") - in(1000)[killMe] } on Initialize { - occurrence.ensureSkill + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("4") } on Initialize [i >= 0] { - occurrence.ensureSkill + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("5") } @@ -57,5 +57,9 @@ agent HelloChildAgent extends AbstractAgent { on Destroy { sayGoodBye } + + on Bye { + killMe + } } diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/SharedGuardEvaluationAgent0.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/SharedGuardEvaluationAgent0.sarl index 7acd363dcd..c55ac5c5ff 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/SharedGuardEvaluationAgent0.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/SharedGuardEvaluationAgent0.sarl @@ -24,6 +24,7 @@ package io.sarl.sre.tests.runtime.bugs.bug977.mocks import io.sarl.core.Initialize import io.sarl.sre.test.framework.skills.TestingCapacity import java.util.concurrent.atomic.AtomicInteger +import io.sarl.sre.test.framework.skills.TestingSkill agent SharedGuardEvaluationAgent0 { @@ -32,34 +33,42 @@ agent SharedGuardEvaluationAgent0 { uses TestingCapacity on Initialize { + setSkillIfAbsent(new TestingSkill(occurrence)) killMeSoon } on Initialize { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("a") } on Initialize [i.get < 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("b") } on Initialize [i.get <= 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("c") } on Initialize [i.get == 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("d") } on Initialize [i.get != 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("e") } on Initialize [i.get >= 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("f") } on Initialize [i.get > 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("g") } diff --git a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/SharedGuardEvaluationAgent1.sarl b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/SharedGuardEvaluationAgent1.sarl index 2a048bad02..694d54acb2 100644 --- a/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/SharedGuardEvaluationAgent1.sarl +++ b/sre/io.janusproject/io.janusproject.tests/src/test/sarl/io/sarl/sre/tests/runtime/bugs/bug977/mocks/SharedGuardEvaluationAgent1.sarl @@ -33,41 +33,48 @@ agent SharedGuardEvaluationAgent1 { uses TestingCapacity on Initialize { - setSkill(new TestingSkill(occurrence)) + setSkillIfAbsent(new TestingSkill(occurrence)) killMeSoon } on Initialize { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("a") i.set(10) } on Initialize [i.get < 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("b") i.set(10) } on Initialize [i.get <= 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("c") i.set(10) } on Initialize [i.get == 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("d") i.set(10) } on Initialize [i.get != 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("e") i.set(10) } on Initialize [i.get >= 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("f") i.set(10) } on Initialize [i.get > 3] { + setSkillIfAbsent(new TestingSkill(occurrence)) addResult("g") i.set(10) }