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

Fixes #16322 - Delete results on test case hard deletion #16500

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3829,6 +3829,10 @@ default String getTimeSeriesTableName() {
return "data_quality_data_time_series";
}

@SqlUpdate(
"DELETE FROM data_quality_data_time_series WHERE entityFQNHash = :testCaseFQNHash AND extension = 'testCase.testCaseResult'")
void deleteAll(@BindFQN("testCaseFQNHash") String entityFQNHash);

@ConnectionAwareSqlUpdate(
value =
"INSERT INTO data_quality_data_time_series(entityFQNHash, extension, jsonSchema, json, incidentId) "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ protected void deleteChildren(
}
}

@Transaction
@Override
protected void cleanup(TestCase entityInterface) {
super.cleanup(entityInterface);
deleteTestCaseResults(entityInterface.getFullyQualifiedName());
}

public RestUtil.PutResponse<TestCaseResult> deleteTestCaseResult(
String updatedBy, String fqn, Long timestamp) {
// Validate the request content
Expand Down Expand Up @@ -427,6 +434,11 @@ public RestUtil.PutResponse<TestCaseResult> deleteTestCaseResult(
"Failed to find testCase result for %s at %s", testCase.getName(), timestamp));
}

private void deleteTestCaseResults(String fqn) {
// Delete all the test case results
daoCollection.dataQualityDataTimeSeriesDao().deleteAll(fqn);
}

private ResultSummary getResultSummary(
TestCase testCase, Long timestamp, TestCaseStatus testCaseStatus) {
return new ResultSummary()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,40 @@ public class TestSuiteRepository extends EntityRepository<TestSuite> {

private static final String ENTITY_EXECUTION_SUMMARY_FILTER =
"""
{
"query": {
{
"query": {
"bool": {
"should": [
"must": [
{
"nested":{
"path": "testSuites",
"query": {
"term": {
"testSuites.id": "%1$s"
"bool": {
"should": [
{
"nested": {
"path": "testSuites",
"query": {
"term": {
"testSuites.id": "%1$s"
}
}
}
},
{
"term": {
"testSuite.id": "%1$s"
}
}
}
]
}
},
{
"term": {
"testSuite.id": "%1$s"
"deleted": false
}
}
]
}
}
}
}
}
""";

public TestSuiteRepository() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,10 @@ public Response delete(
schema = @Schema(type = "string"))
@PathParam("fqn")
String fqn) {
ResourceContextInterface resourceContext = TestCaseResourceContext.builder().name(fqn).build();
OperationContext operationContext =
new OperationContext(Entity.TABLE, MetadataOperation.EDIT_TESTS);
authorizer.authorize(securityContext, operationContext, resourceContext);
return deleteByName(uriInfo, securityContext, fqn, recursive, hardDelete);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,28 @@ void test_resultSummaryCascadeToAllSuites(TestInfo test)
getAndValidateTestSummary(logicalTestSuite.getId().toString());
}
deleteEntity(testCase1.getId(), ADMIN_AUTH_HEADERS);
ResultList<TestCaseResult> resultList =
getTestCaseResults(
testCase1.getFullyQualifiedName(),
TestUtils.dateToTimestamp("2021-10-01"),
TestUtils.dateToTimestamp("2021-10-30"),
ADMIN_AUTH_HEADERS);
assertNotEquals(
resultList.getData().size(), 0); // soft deletion should not delete existing results

if (supportsSearchIndex) {
getAndValidateTestSummary(testCase.getTestSuite().getId().toString());
getAndValidateTestSummary(logicalTestSuite.getId().toString());
}

deleteEntity(testCase1.getId(), true, true, ADMIN_AUTH_HEADERS); // hard delete
resultList =
getTestCaseResults(
testCase1.getFullyQualifiedName(),
TestUtils.dateToTimestamp("2021-10-01"),
TestUtils.dateToTimestamp("2021-10-30"),
ADMIN_AUTH_HEADERS);
assertEquals(resultList.getData().size(), 0); // hard deletion should delete existing results

if (supportsSearchIndex) {
getAndValidateTestSummary(testCase.getTestSuite().getId().toString());
Expand Down Expand Up @@ -1923,7 +1945,7 @@ private void validateTestSummary(TestSummary testSummary, String testSuiteId)
}
params.put("fields", "testCaseResult");
params.put("limit", "10000");
params.put("include", "all");
params.put("include", "non-deleted");

ResultList<TestCase> testCaseResultList = listEntities(params, ADMIN_AUTH_HEADERS);
testCases = testCaseResultList.getData();
Expand Down
Loading