1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 19:20:29 +00:00

Try to make turtle_test.peripheral_change more robust

Replace the arbitrary sleep with a thenWaitUntil.
This commit is contained in:
Jonathan Coates 2023-07-02 11:46:03 +01:00
parent d138d9c4a5
commit 8708048b6e
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06

View File

@ -39,6 +39,7 @@ import org.hamcrest.Matchers.instanceOf
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 @@ class Turtle_Test {
fun Peripheral_change(helper: GameTestHelper) = helper.sequence {
val testInfo = (helper as GameTestHelperAccessor).testInfo as GameTestInfoAccessor
val events = mutableListOf<Pair<String, String>>()
val events = CopyOnWriteArrayList<Pair<String, String>>()
var running = false
thenStartComputer("listen") {
running = true
@ -507,15 +508,13 @@ class Turtle_Test {
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")
}
}