2019-02-26 08:44:17 +00:00
|
|
|
/*
|
|
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
|
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
package dan200.computercraft.core.computer;
|
|
|
|
|
2019-03-01 23:48:32 +00:00
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
import static java.time.Duration.ofSeconds;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
2019-02-26 08:44:17 +00:00
|
|
|
|
|
|
|
public class ComputerTest
|
|
|
|
{
|
2019-03-01 23:48:32 +00:00
|
|
|
@Test
|
2019-02-26 08:44:17 +00:00
|
|
|
public void testTimeout()
|
|
|
|
{
|
2019-03-01 23:48:32 +00:00
|
|
|
assertTimeoutPreemptively( ofSeconds( 20 ), () -> {
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ComputerBootstrap.run( "print('Hello') while true do end" );
|
|
|
|
}
|
|
|
|
catch( AssertionError e )
|
|
|
|
{
|
|
|
|
if( e.getMessage().equals( "test.lua:1: Too long without yielding" ) ) return;
|
|
|
|
throw e;
|
|
|
|
}
|
2019-02-26 08:44:17 +00:00
|
|
|
|
2019-03-01 23:48:32 +00:00
|
|
|
Assertions.fail( "Expected computer to timeout" );
|
|
|
|
} );
|
2019-02-26 08:44:17 +00:00
|
|
|
}
|
|
|
|
}
|