From 581a01f048cde05358cf2c92810337ce2f97ddf2 Mon Sep 17 00:00:00 2001 From: Zaafar Date: Thu, 8 Apr 2021 12:14:46 -0400 Subject: [PATCH] added a unit test to expose the bug. --- Tests/EventBasedCoroutineTests.cs | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Tests/EventBasedCoroutineTests.cs b/Tests/EventBasedCoroutineTests.cs index 456f9c9..150c62c 100644 --- a/Tests/EventBasedCoroutineTests.cs +++ b/Tests/EventBasedCoroutineTests.cs @@ -301,5 +301,40 @@ namespace Tests { Assert.AreEqual(cr.Name, "Bird", "Incorrect name of the coroutine."); } + [Test] + public void TestNestedCoroutineWithMoveToTime() + { + var frequentEvent = new Event(); + var onceInAWhileEvent = new Event(); + + IEnumerator FrequentCoroutine() { + int i = 0; + while (true) { + yield return new Wait(frequentEvent); + if (i % 2 == 0) { + CoroutineHandler.RaiseEvent(onceInAWhileEvent); + } + + i++; + } + } + + IEnumerator OnceInAWhileCoroutine() { + while (true) { + yield return new Wait(onceInAWhileEvent); + for (int i = 0; i < 5; i++) { + yield return new Wait(0d); + } + } + } + + CoroutineHandler.Start(FrequentCoroutine()); + CoroutineHandler.Start(OnceInAWhileCoroutine()); + + CoroutineHandler.RaiseEvent(frequentEvent); + CoroutineHandler.RaiseEvent(frequentEvent); + CoroutineHandler.RaiseEvent(frequentEvent); + CoroutineHandler.RaiseEvent(frequentEvent); + } } } \ No newline at end of file