diff --git a/integration-tests/timeout/config.json b/integration-tests/timeout/config.json new file mode 100644 index 0000000..0a8280d --- /dev/null +++ b/integration-tests/timeout/config.json @@ -0,0 +1,4 @@ +{ + "filename": "Sleepy.java", + "natural_language": "en" +} diff --git a/integration-tests/timeout/evaluation/SleepyTest.java b/integration-tests/timeout/evaluation/SleepyTest.java new file mode 100644 index 0000000..b230f95 --- /dev/null +++ b/integration-tests/timeout/evaluation/SleepyTest.java @@ -0,0 +1,14 @@ +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class SleepyTest { + + @Test(timeout = 1) + public void test() throws Exception { + new Sleepy().sleep(); + fail(); + } + +} diff --git a/integration-tests/timeout/evaluation/TestSuite.java b/integration-tests/timeout/evaluation/TestSuite.java new file mode 100644 index 0000000..6c7c2b2 --- /dev/null +++ b/integration-tests/timeout/evaluation/TestSuite.java @@ -0,0 +1,9 @@ + +import org.junit.runners.Suite; +import org.junit.runner.RunWith; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + SleepyTest.class, +}) +public class TestSuite {} diff --git a/integration-tests/timeout/result.json b/integration-tests/timeout/result.json new file mode 100644 index 0000000..cc7f57d --- /dev/null +++ b/integration-tests/timeout/result.json @@ -0,0 +1,59 @@ +{ + "command": "start-judgement" +} +{ + "command": "start-tab", + "hidden": true, + "title": "Compiler" +} +{ + "command": "close-tab" +} +{ + "command": "start-tab", + "hidden": false, + "permission": "student", + "title": "Test" +} +{ + "command": "start-context", + "description": { + "description": "test(SleepyTest)", + "format": "code" + } +} +{ + "command": "start-testcase", + "description": { + "description": "org.junit.runners.model.TestTimedOutException: test timed out after 1 milliseconds", + "format": "code" + } +} +{ + "command": "escalate-status", + "status": { + "enum": "time limit exceeded", + "human": "Tijdslimiet overschreden" + } +} +{ + "command": "append-message", + "message": { + "description": "Caused by org.junit.runners.model.TestTimedOutException: test timed out after 1 milliseconds", + "format": "code" + } +} +{ + "accepted": false, + "command": "close-testcase" +} +{ + "accepted": false, + "command": "close-context" +} +{ + "command": "close-tab" +} +{ + "command": "close-judgement" +} diff --git a/integration-tests/timeout/submission.java b/integration-tests/timeout/submission.java new file mode 100644 index 0000000..f4d24fa --- /dev/null +++ b/integration-tests/timeout/submission.java @@ -0,0 +1,11 @@ +import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; +import java.util.stream.Collectors; + +public class Sleepy { + + public void sleep() throws InterruptedException { + TimeUnit.DAYS.sleep(Long.MAX_VALUE); + } + +} diff --git a/src/dodona/junit/JSONListener.java b/src/dodona/junit/JSONListener.java index dd03478..26951d3 100644 --- a/src/dodona/junit/JSONListener.java +++ b/src/dodona/junit/JSONListener.java @@ -19,6 +19,7 @@ import org.junit.runner.Result; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunListener; +import org.junit.runners.model.TestTimedOutException; import java.io.InputStream; import java.io.PrintStream; @@ -118,7 +119,11 @@ public void aftertest(Failure failure) { Throwable deepest = thrown; while(deepest.getCause() != null) deepest = deepest.getCause(); write(new StartTestcase(Message.code(deepest.toString()))); - write(new EscalateStatus(Status.RUNTIME_ERROR, "Uitvoeringsfout")); + if (thrown instanceof TestTimedOutException) { + write(new EscalateStatus(Status.TIME_LIMIT_EXCEEDED, "Tijdslimiet overschreden")); + } else { + write(new EscalateStatus(Status.RUNTIME_ERROR, "Uitvoeringsfout")); + } while(thrown != null) { StringBuilder message = new StringBuilder(); message.append("Caused by " + thrown); @@ -159,7 +164,7 @@ private String getDescription(final Description desc) { .orElseGet(() -> getTestDescription(desc) .orElse(desc.getDisplayName())); } - + /** * Parse a @I18nTabTitle annotation. * @@ -174,7 +179,7 @@ private Optional getI18nTabTitle(final Description desc) { .map(bundle::getString) ); } - + /** * Parse a @I18nTestDescription annotation. *