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

Using futures in user code causes Fuzzer to generate tests which fail during execution #2640

Open
tyuldashev opened this issue Oct 3, 2023 · 0 comments
Assignees
Labels
comp-fuzzing Issue is related to the fuzzing ctg-bug Issue is a bug

Comments

@tyuldashev
Copy link
Collaborator

Description
When code contains usage of CompletableFuture Fuzzer may generate tests which throw unexpected exception during execution.

To Reproduce

  1. Install UnitTestBot plugin built from main in IntelliJ IDEA
  2. Open UTBot Java project
  3. Set Test method generation: Fuzzer = 100%
  4. Generate tests for examples.threads.FutureExamples#changingCollectionInFutureWithoutGet
  5. Run generated tests

Expected behavior
Tests without exception pass

Actual behavior
Half of generated tests fail.

Screenshots, logs
Code under test

    public int changingCollectionInFutureWithoutGet() {
        List<Integer> values = new ArrayList<>();

        final CompletableFuture<Void> future = CompletableFuture.runAsync(() -> values.add(42));

        return values.get(0);
    }

One of generated tests:

    @Test
    @DisplayName("changingCollectionInFutureWithoutGet:  -> return 42")
    public void testChangingCollectionInFutureWithoutGetReturns42() {
        FutureExamples futureExamples = new FutureExamples();

        int actual = futureExamples.changingCollectionInFutureWithoutGet();

        assertEquals(42, actual);
    }

Exception during execution:

java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0

	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
	at java.base/java.util.Objects.checkIndex(Objects.java:372)
	at java.base/java.util.ArrayList.get(ArrayList.java:459)
	at examples.threads.FutureExamples.changingCollectionInFutureWithoutGet(FutureExamples.java:41)
	at examples.threads.FutureExamplesTest.testChangingCollectionInFutureWithoutGetReturns42(FutureExamplesTest.java:23)

Additional context
Symbolic engine doesn't generate tests which should pass.

@tyuldashev tyuldashev added ctg-bug Issue is a bug comp-fuzzing Issue is related to the fuzzing labels Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-fuzzing Issue is related to the fuzzing ctg-bug Issue is a bug
Projects
Status: Todo
Development

No branches or pull requests

2 participants