Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Timeout does not work when the test prints infinite output to stdout #2127

Closed
1 task
SolalPirelli opened this issue Dec 13, 2019 · 1 comment
Closed
1 task

Comments

@SolalPirelli
Copy link

I'm using JUnit to grade coding exams. Students get points for each passing test, so it's important to me that failures from a single test are isolated - I don't want students' mistakes in one part of the code to affect other tests and cause them to lose more points than they should. Such mistakes sometimes include infinite loops in their code, meaning I need timeouts. And sometimes mistakes include printing text to stdout within an infinite loop...

Steps to reproduce

Run the following test:

import org.junit.jupiter.api.*;
import java.util.concurrent.*;

class Example {
    @Test
    @Timeout(value = 2, unit = TimeUnit.SECONDS)
    void test() throws InterruptedException {
        while(true) System.out.println("Hello");
    }
}

The test hangs, despite the timeout.

Context

  • Used versions (Jupiter/Vintage/Platform): Jupiter
  • Build Tool/IDE: Gradle

On Ubuntu 18.04.3, using Gradle 6.0.1 (latest as of this report) and the following build.gradle:

plugins {
    id 'java'
}

repositories {
    jcenter()
}

dependencies {
    // JUnit 5 "Jupiter"
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
}

test {
    useJUnitPlatform()
}

I run tests with ./gradlew build.

Note that replacing the while(true) loop above with Thread.sleep(60 * 1000) causes the test to fail with a TimeoutException, as expected.

Deliverables

  • Make @Timeout work even when the test prints infinite output to stdout
@marcphilipp
Copy link
Member

Duplicate of #2087

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants