1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-09-29 15:30:48 +00:00

Try to remove some flakiness in tests

- Make assertions a little more relaxed
 - Increase timeouts of computer tests (again :D:).
 - Log where we're up to in computer tests, to make tracking stalls a
   little easier
This commit is contained in:
Jonathan Coates 2022-05-23 10:26:18 +01:00
parent 431e4c9419
commit 24ed0ca723
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
4 changed files with 15 additions and 4 deletions

View File

@ -85,7 +85,7 @@ public class ComputerThreadTest
assertEquals( budget, TimeUnit.MILLISECONDS.toNanos( 25 ), "Budget should be 25ms" ); assertEquals( budget, TimeUnit.MILLISECONDS.toNanos( 25 ), "Budget should be 25ms" );
long delay = ConcurrentHelpers.waitUntil( timeout::isPaused ); long delay = ConcurrentHelpers.waitUntil( timeout::isPaused );
assertThat( "Paused within 25ms", delay * 1e-9, closeTo( 0.03, 0.015 ) ); assertThat( "Paused within 25ms", delay * 1e-9, closeTo( 0.03, 0.02 ) );
computer.shutdown(); computer.shutdown();
return MachineResult.OK; return MachineResult.OK;

View File

@ -23,9 +23,11 @@ object Times {
* Custom timeouts for various test types. * Custom timeouts for various test types.
*/ */
object Timeouts { object Timeouts {
const val COMPUTER_TIMEOUT: Int = 200 private const val SECOND: Int = 20
const val CLIENT_TIMEOUT: Int = 400 const val COMPUTER_TIMEOUT: Int = SECOND * 15
const val CLIENT_TIMEOUT: Int = SECOND * 20
} }
/** /**

View File

@ -6,6 +6,7 @@
package dan200.computercraft.ingame.mod; package dan200.computercraft.ingame.mod;
import com.google.common.io.MoreFiles; import com.google.common.io.MoreFiles;
import com.google.common.io.RecursiveDeleteOption;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;
@ -55,7 +56,7 @@ public final class Copier extends SimpleFileVisitor<Path>
public static void replicate( Path from, Path to, Predicate<Path> check ) throws IOException public static void replicate( Path from, Path to, Predicate<Path> check ) throws IOException
{ {
if( Files.exists( to ) ) MoreFiles.deleteRecursively( to ); if( Files.exists( to ) ) MoreFiles.deleteRecursively( to, RecursiveDeleteOption.ALLOW_INSECURE );
Files.walkFileTree( from, new Copier( from, to, check ) ); Files.walkFileTree( from, new Copier( from, to, check ) );
} }
} }

View File

@ -4,6 +4,14 @@ if label == nil then return test.fail("Label a computer to use it.") end
local fn, err = loadfile("tests/" .. label .. ".lua", nil, _ENV) local fn, err = loadfile("tests/" .. label .. ".lua", nil, _ENV)
if not fn then return test.fail(err) end if not fn then return test.fail(err) end
local source = "@" .. label .. ".lua"
debug.sethook(function()
local i = debug.getinfo(2, "lS")
if i.source == source and i.currentline then
test.log("At line " .. i.currentline)
end
end, "l")
local ok, err = pcall(fn) local ok, err = pcall(fn)
if not ok then return test.fail(err) end if not ok then return test.fail(err) end