Skip to content

Commit

Permalink
Make JUnit TestTimedOutExceptions actual timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
rien committed Mar 27, 2024
1 parent 195932a commit 98339be
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 3 deletions.
4 changes: 4 additions & 0 deletions integration-tests/timeout/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"filename": "Sleepy.java",
"natural_language": "en"
}
14 changes: 14 additions & 0 deletions integration-tests/timeout/evaluation/SleepyTest.java
Original file line number Diff line number Diff line change
@@ -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();
}

}
9 changes: 9 additions & 0 deletions integration-tests/timeout/evaluation/TestSuite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import org.junit.runners.Suite;
import org.junit.runner.RunWith;

@RunWith(Suite.class)
@Suite.SuiteClasses({
SleepyTest.class,
})
public class TestSuite {}
59 changes: 59 additions & 0 deletions integration-tests/timeout/result.json
Original file line number Diff line number Diff line change
@@ -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"
}
11 changes: 11 additions & 0 deletions integration-tests/timeout/submission.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
11 changes: 8 additions & 3 deletions src/dodona/junit/JSONListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -159,7 +164,7 @@ private String getDescription(final Description desc) {
.orElseGet(() -> getTestDescription(desc)
.orElse(desc.getDisplayName()));
}

/**
* Parse a @I18nTabTitle annotation.
*
Expand All @@ -174,7 +179,7 @@ private Optional<String> getI18nTabTitle(final Description desc) {
.map(bundle::getString)
);
}

/**
* Parse a @I18nTestDescription annotation.
*
Expand Down

0 comments on commit 98339be

Please sign in to comment.