Fuzzer doesn’t repeat same modifications multiple times
Description (abstract example)
When using Seed.Recursive with modification X, fuzzer doesn't attempt to apply modification X more than once.
Real world (concrete) example
To cover last line of OwnerController#processFindForm method in spring-petclinic project we need to apply orderRepository.save(Owner) modification twice in order to make both ownersResults.isEmpty() and ownersResults.getTotalElements() conditions fail.
To Reproduce
Run the following unit test.
@Test
fun `fuzzer can generate value without two repeated mutations`() {
runBlocking {
var seenRepeated = false
withTimeout(1000) {
runFuzzing(
{ _, _ -> sequenceOf(Seed.Recursive<Unit, StringBuilder>(
construct = Routine.Create(emptyList()) { StringBuilder("") },
modify = sequenceOf(Routine.Call(emptyList()) { s, _ -> s.append("1") }),
empty = Routine.Empty { fail("Empty is called despite construct requiring no args") }
)) },
Description(listOf(Unit))
) { _, (s) ->
if (s.length >= 2) {
seenRepeated = true
BaseFeedback(Unit, Control.STOP)
} else BaseFeedback(Unit, Control.CONTINUE)
}
}
Assertions.assertTrue(seenRepeated) { "Unmodified empty string wasn't generated" }
}
}
Expected behavior
Test passes.
Actual behavior
Test fails.
Visual proofs (screenshots, logs, images)
Timed out waiting for 1000 ms
kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 1000 ms
(Coroutine boundary)
at org.utbot.fuzzing.FuzzingApi.fuzz(Api.kt:352)
at org.utbot.fuzzing.FuzzerSmokeTest$fuzzer can generate value without two repeated mutations$1$1.invokeSuspend(FuzzerSmokeTest.kt:291)
at org.utbot.fuzzing.FuzzerSmokeTest$fuzzer can generate value without two repeated mutations$1.invokeSuspend(FuzzerSmokeTest.kt:290)
Caused by: kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 1000 ms
at app//kotlinx.coroutines.TimeoutKt.TimeoutCancellationException(Timeout.kt:184)
at app//kotlinx.coroutines.TimeoutCoroutine.run(Timeout.kt:154)
at app//kotlinx.coroutines.EventLoopImplBase$DelayedRunnableTask.run(EventLoop.common.kt:508)
at app//kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:284)
at app//kotlinx.coroutines.DefaultExecutor.run(DefaultExecutor.kt:108)
at [email protected]/java.lang.Thread.run(Thread.java:833)
@IlyaMuravjov Seems that two and more Owners saved with the same lastName will satisfy this case too. Does Fuzzing manage to call save(Owner) several times with different Owners?
@alisevych
No, it calls save method at most once. When I said "repeat same modification" I meant calling same method multiple times (not necessarily with same arguments).
Unit test shows that fuzzer when given a Routine.Create that creates StringBuilder("") and Routine.Call that appends "1" to the StringBuilder is unable to create any StringBuilder that contains at least two characters.