Skip to content

Hanging tests duplicates are not minimized #2130

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

Open
alisevych opened this issue Apr 11, 2023 · 1 comment
Open

Hanging tests duplicates are not minimized #2130

alisevych opened this issue Apr 11, 2023 · 1 comment
Labels
comp-minimizer Issue is related to Minimization phase ctg-bug Issue is a bug

Comments

@alisevych
Copy link
Member

Description

Hanging tests duplicates are not minimized.
There are two identical tests: one generated by Fuzzing, one by Symbolic engine (when default or some custom mode is used).

To Reproduce

  1. Open/create a project in IntelliJ Idea
  2. Install one of the latest plugins built from main
  3. In Settings -> Tools -> UnitTestBot set Fuzzing + Symbolic generation mode
  4. Check Hanging test timeout (1000 ms by default)
  5. Generate tests for the following code:
    public void sleep() throws InterruptedException {
        Thread.sleep(5000);
    }

Expected behavior

One test on timeout should be present in the resulting test class.

Actual behavior

There are two identical tests in the test class.

Visual proofs (screenshots, logs, images)

    ///region SYMBOLIC EXECUTION: TIMEOUTS for method sleep()

    /**
     * @utbot.classUnderTest {@link TimeoutTest}
     * @utbot.methodUnderTest {@link TimeoutTest#sleep()}
     * @utbot.invokes {@link Thread#sleep(long)}
     */
    @Test
    @DisplayName("sleep:  -> TimeoutExceeded")
    @org.junit.jupiter.api.Timeout(value = 1000L, unit = TimeUnit.MILLISECONDS)
    public void testSleep_ThreadSleep() throws InterruptedException {
        TimeoutTest timeoutTest = new TimeoutTest();
        
        /* This execution may take longer than the 1000 ms timeout
         and therefore fail due to exceeding the timeout. */
        assertTimeoutPreemptively(Duration.ofMillis(1000L), () -> timeoutTest.sleep());
    }
    ///endregion

    ///region FUZZER: TIMEOUTS for method sleep()

    /**
     * @utbot.classUnderTest {@link TimeoutTest}
     * @utbot.methodUnderTest {@link TimeoutTest#sleep()}
     */
    @Test
    @DisplayName("sleep: ")
    @org.junit.jupiter.api.Timeout(value = 1000L, unit = TimeUnit.MILLISECONDS)
    public void testSleep() throws InterruptedException {
        TimeoutTest timeoutTest = new TimeoutTest();
        
        /* This execution may take longer than the 1000 ms timeout
         and therefore fail due to exceeding the timeout. */
        assertTimeoutPreemptively(Duration.ofMillis(1000L), () -> timeoutTest.sleep());
    }
    ///endregion

Environment

IntelliJ IDEA 2022.3 / 2023.1

@alisevych alisevych added ctg-bug Issue is a bug comp-minimizer Issue is related to Minimization phase labels Apr 11, 2023
@tyuldashev
Copy link
Collaborator

Another illustration of timed out tests minimization:

  • Generate tests by fuzzer for org.utbot.examples.exceptions.ExceptionExamples#hangForSeconds method
  • There are dozens (~30-40) of similar tests. Some of them completely the same, for instance for corner cases:
    @Test
    @DisplayName("hangForSeconds: seconds = max")
    @org.junit.jupiter.api.Timeout(value = 1000L, unit = TimeUnit.MILLISECONDS)
    public void testHangForSecondsWithCornerCase4() throws InterruptedException {
        ExceptionExamples exceptionExamples = new ExceptionExamples();
        
        /* This execution may take longer than the 1000 ms timeout
         and therefore fail due to exceeding the timeout. */
        assertTimeoutPreemptively(Duration.ofMillis(1000L), () -> exceptionExamples.hangForSeconds(Integer.MAX_VALUE));
    }

    @Test
    @DisplayName("hangForSeconds: seconds = max")
    @org.junit.jupiter.api.Timeout(value = 1000L, unit = TimeUnit.MILLISECONDS)
    public void testHangForSecondsWithCornerCase5() throws InterruptedException {
        ExceptionExamples exceptionExamples = new ExceptionExamples();
        
        /* This execution may take longer than the 1000 ms timeout
         and therefore fail due to exceeding the timeout. */
        assertTimeoutPreemptively(Duration.ofMillis(1000L), () -> exceptionExamples.hangForSeconds(Integer.MAX_VALUE));
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-minimizer Issue is related to Minimization phase ctg-bug Issue is a bug
Projects
Status: Todo
Development

No branches or pull requests

2 participants