diff --git a/core/src/main/kotlin/org/evomaster/core/problem/api/service/ApiWsStructureMutator.kt b/core/src/main/kotlin/org/evomaster/core/problem/api/service/ApiWsStructureMutator.kt index e2085301bf..fefc12a420 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/api/service/ApiWsStructureMutator.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/api/service/ApiWsStructureMutator.kt @@ -277,6 +277,7 @@ abstract class ApiWsStructureMutator : StructureMutator() { val oldSqlActions = mutableListOf().plus(ind.seeInitializingActions()) val failedWhereQueries = evaluatedIndividual.fitness.getViewOfAggregatedFailedWhereQueries() + .filter { it.isNotBlank() } val addedSqlInsertions = handleFailedWhereSQL(ind, fw, failedWhereQueries, mutatedGenes, sampler) ind.repairInitializationActions(randomness) diff --git a/core/src/test/kotlin/org/evomaster/core/search/FitnessValueTest.kt b/core/src/test/kotlin/org/evomaster/core/search/FitnessValueTest.kt index b7ce647f0f..d518524071 100644 --- a/core/src/test/kotlin/org/evomaster/core/search/FitnessValueTest.kt +++ b/core/src/test/kotlin/org/evomaster/core/search/FitnessValueTest.kt @@ -5,6 +5,8 @@ import org.evomaster.client.java.controller.api.dto.BootTimeInfoDto import org.evomaster.client.java.controller.api.dto.TargetInfoDto import org.evomaster.client.java.instrumentation.shared.ObjectiveNaming import org.evomaster.core.search.service.IdMapper +import org.evomaster.core.sql.DatabaseExecution +import org.evomaster.core.sql.SqlExecutionInfo import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test @@ -123,4 +125,37 @@ class FitnessValueTest { assertEquals(3, linesInfo.searchTime) } + @Test + fun testAggregatedFailedWhereQueriesExcludesBlankEntries() { + val fv = FitnessValue(1.0) + + val execution = DatabaseExecution( + queriedData = emptyMap(), + updatedData = emptyMap(), + insertedData = emptyMap(), + failedWhere = emptyMap(), + deletedData = emptyList(), + numberOfSqlCommands = 3, + sqlParseFailureCount = 0, + executionInfo = listOf( + SqlExecutionInfo("SELECT * FROM foo WHERE id = 1", false, 10L), + SqlExecutionInfo("", false, 5L), + SqlExecutionInfo(" ", false, 5L), + SqlExecutionInfo("SELECT * FROM bar WHERE name = 'x'", false, 8L) + ) + ) + fv.setDatabaseExecution(0, execution) + fv.aggregateDatabaseData() + + val allQueries = fv.getViewOfAggregatedFailedWhereQueries() + assertEquals(4, allQueries.size) + + // Simulate the filter applied in ApiWsStructureMutator before sending queries to the solver + val nonBlankQueries = allQueries.filter { it.isNotBlank() } + assertEquals(2, nonBlankQueries.size) + assertTrue(nonBlankQueries.none { it.isBlank() }) + assertTrue(nonBlankQueries.contains("SELECT * FROM foo WHERE id = 1")) + assertTrue(nonBlankQueries.contains("SELECT * FROM bar WHERE name = 'x'")) + } + } \ No newline at end of file