From 8708048b6ee882cc52580c35bd361387226ff45f Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sun, 2 Jul 2023 11:46:03 +0100 Subject: [PATCH] Try to make turtle_test.peripheral_change more robust Replace the arbitrary sleep with a thenWaitUntil. --- .../computercraft/gametest/Turtle_Test.kt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Turtle_Test.kt b/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Turtle_Test.kt index 454e5273d..42d0da4ec 100644 --- a/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Turtle_Test.kt +++ b/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Turtle_Test.kt @@ -39,6 +39,7 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import java.util.* +import java.util.concurrent.CopyOnWriteArrayList import kotlin.time.Duration.Companion.milliseconds class Turtle_Test { @@ -488,7 +489,7 @@ fun No_ghost_peripheral(helper: GameTestHelper) = helper.sequence { fun Peripheral_change(helper: GameTestHelper) = helper.sequence { val testInfo = (helper as GameTestHelperAccessor).testInfo as GameTestInfoAccessor - val events = mutableListOf>() + val events = CopyOnWriteArrayList>() var running = false thenStartComputer("listen") { running = true @@ -507,15 +508,13 @@ fun Peripheral_change(helper: GameTestHelper) = helper.sequence { turtle.back().await().assertArrayEquals(true, message = "Moved turtle forward") TestHooks.LOG.info("[{}] Finished turtle at {}", testInfo, testInfo.`computercraft$getTick`()) } - thenIdle(4) // Should happen immediately, but computers might be slow. - thenExecute { - assertEquals( - listOf( - "peripheral_detach" to "right", - "peripheral" to "right", - ), - events, + thenWaitUntil { + val expected = listOf( + "peripheral_detach" to "right", + "peripheral" to "right", ) + + if (events != expected) helper.fail("Expected $expected, but received $events") } }