-
Notifications
You must be signed in to change notification settings - Fork 109
Filter blank failedWhere Queries from mutator #1482
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
agusaldasoro
wants to merge
8
commits into
master
Choose a base branch
from
agusaldasoro-patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+173
−1
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7e195b0
Filter blank failedWhere Queries from mutator
agusaldasoro e57e3cc
Merge branch 'master' into agusaldasoro-patch-1
agusaldasoro a812193
Merge branch 'master' into agusaldasoro-patch-1
agusaldasoro 0637537
Add tests
agusaldasoro b5f0ffa
Move the fix to the correct function
agusaldasoro 2608797
Merge branch 'master' into agusaldasoro-patch-1
agusaldasoro 29d7fe7
Add integration test
agusaldasoro 27e24db
Merge branch 'master' into agusaldasoro-patch-1
agusaldasoro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
core/src/test/kotlin/org/evomaster/core/search/FitnessValueSqlIntegrationTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package org.evomaster.core.search | ||
|
|
||
| import org.evomaster.client.java.sql.DbInfoExtractor | ||
| import org.evomaster.client.java.sql.SqlScriptRunner | ||
| import org.evomaster.client.java.sql.internal.SqlHandler | ||
| import org.evomaster.client.java.controller.api.dto.database.execution.SqlExecutionLogDto | ||
| import org.evomaster.core.sql.DatabaseExecution | ||
| import org.evomaster.core.sql.schema.TableId | ||
| import org.junit.jupiter.api.AfterAll | ||
| import org.junit.jupiter.api.BeforeAll | ||
| import org.junit.jupiter.api.BeforeEach | ||
| import org.junit.jupiter.api.Test | ||
| import org.junit.jupiter.api.Assertions.* | ||
| import java.sql.Connection | ||
| import java.sql.DriverManager | ||
|
|
||
| class FitnessValueSqlIntegrationTest { | ||
|
|
||
| companion object { | ||
|
|
||
| private lateinit var connection: Connection | ||
|
|
||
| @BeforeAll | ||
| @JvmStatic | ||
| fun initClass() { | ||
| connection = DriverManager.getConnection("jdbc:h2:mem:db_test", "sa", "") | ||
| } | ||
|
|
||
| @AfterAll | ||
| @JvmStatic | ||
| fun clean() { | ||
| connection.close() | ||
| } | ||
| } | ||
|
|
||
| @BeforeEach | ||
| fun initTest() { | ||
| SqlScriptRunner.execCommand(connection, "DROP ALL OBJECTS;") | ||
| SqlScriptRunner.execCommand(connection, """ | ||
| CREATE TABLE Person ( | ||
| person_id INT PRIMARY KEY, | ||
| age INT | ||
| ); | ||
| """) | ||
| } | ||
|
|
||
| private fun runSelect(sqlCommand: String): DatabaseExecution { | ||
| val schema = DbInfoExtractor.extract(connection) | ||
| val tableIds = schema.tables.map { t -> TableId(t.id.name) }.toSet() | ||
|
|
||
| val handler = SqlHandler(null) | ||
| handler.setConnection(connection) | ||
| handler.setSchema(schema) | ||
|
|
||
| handler.handle(SqlExecutionLogDto(sqlCommand, false, 0L)) | ||
| handler.getSqlDistances(null, true) | ||
|
|
||
| return DatabaseExecution.fromDto(handler.getExecutionDto(), tableIds) | ||
| } | ||
|
|
||
| @Test | ||
| fun testSelectWithFailedWhereIsCollected() { | ||
| // Empty table: WHERE clause will fail (no rows match) | ||
| val sqlCommand = "SELECT * FROM Person WHERE age = 30" | ||
|
|
||
| val fv = FitnessValue(1.0) | ||
| fv.setDatabaseExecution(0, runSelect(sqlCommand)) | ||
| fv.aggregateDatabaseData() | ||
|
|
||
| val queries = fv.getViewOfAggregatedFailedWhereQueries() | ||
| assertEquals(1, queries.size) | ||
| assertTrue(queries.contains(sqlCommand)) | ||
| } | ||
|
|
||
| @Test | ||
| fun testSelectWithSuccessfulWhereIsNotCollected() { | ||
| // Insert a row so the WHERE clause succeeds | ||
| SqlScriptRunner.execCommand(connection, "INSERT INTO Person VALUES (1, 30)") | ||
| val sqlCommand = "SELECT * FROM Person WHERE age = 30" | ||
|
|
||
| val fv = FitnessValue(1.0) | ||
| fv.setDatabaseExecution(0, runSelect(sqlCommand)) | ||
| fv.aggregateDatabaseData() | ||
|
|
||
| val queries = fv.getViewOfAggregatedFailedWhereQueries() | ||
| assertTrue(queries.isEmpty()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this definition of
aggregatedFailedWhereQueriescorrect? i mean, also the previous version. insideDatabaseExecutionwe keep track of all SQL commands done in a test. some havefailedWhere, some do not. but here it seems like you mark everything underexecutionInfoasfailedWhere, isn't it? this would work if and only if all queries hadfailedWhere, isn't it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to be on safe side, can you add some tests to check this scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't that be covered by line 169
.filter { it.failedWhere.isNotEmpty() }?I added a test also to check both conditions failed where present and absent