mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-01 19:18:05 +00:00
fix: clear incident ID when testCase result is success (#14755)
This commit is contained in:
parent
c90a86b8ad
commit
aa92db3176
@ -3708,14 +3708,6 @@ public interface CollectionDAO {
|
|||||||
return "data_quality_data_time_series";
|
return "data_quality_data_time_series";
|
||||||
}
|
}
|
||||||
|
|
||||||
@SqlUpdate(
|
|
||||||
value =
|
|
||||||
"UPDATE data_quality_data_time_series SET incidentId = NULL "
|
|
||||||
+ "WHERE entityFQNHash = :testCaseFQNHash and incidentId = :incidentStateId")
|
|
||||||
void cleanTestCaseIncident(
|
|
||||||
@BindFQN("testCaseFQNHash") String testCaseFQNHash,
|
|
||||||
@Bind("incidentStateId") String incidentStateId);
|
|
||||||
|
|
||||||
@ConnectionAwareSqlUpdate(
|
@ConnectionAwareSqlUpdate(
|
||||||
value =
|
value =
|
||||||
"INSERT INTO data_quality_data_time_series(entityFQNHash, extension, jsonSchema, json, incidentId) "
|
"INSERT INTO data_quality_data_time_series(entityFQNHash, extension, jsonSchema, json, incidentId) "
|
||||||
|
|||||||
@ -11,12 +11,12 @@ import static org.openmetadata.service.Entity.getEntityReferenceByName;
|
|||||||
import static org.openmetadata.service.util.RestUtil.ENTITY_NO_CHANGE;
|
import static org.openmetadata.service.util.RestUtil.ENTITY_NO_CHANGE;
|
||||||
import static org.openmetadata.service.util.RestUtil.LOGICAL_TEST_CASES_ADDED;
|
import static org.openmetadata.service.util.RestUtil.LOGICAL_TEST_CASES_ADDED;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.json.JsonPatch;
|
import javax.json.JsonPatch;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@ -258,6 +258,8 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
|
|||||||
String updatedBy, UriInfo uriInfo, String fqn, TestCaseResult testCaseResult) {
|
String updatedBy, UriInfo uriInfo, String fqn, TestCaseResult testCaseResult) {
|
||||||
// Validate the request content
|
// Validate the request content
|
||||||
TestCase testCase = findByName(fqn, Include.NON_DELETED);
|
TestCase testCase = findByName(fqn, Include.NON_DELETED);
|
||||||
|
ArrayList<String> fields = new ArrayList<>();
|
||||||
|
fields.add(TEST_SUITE_FIELD);
|
||||||
|
|
||||||
// set the test case resolution status reference if test failed, by either
|
// set the test case resolution status reference if test failed, by either
|
||||||
// creating a new incident or returning the stateId of an unresolved incident
|
// creating a new incident or returning the stateId of an unresolved incident
|
||||||
@ -269,6 +271,12 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
|
|||||||
// plotting the UI
|
// plotting the UI
|
||||||
// even after the incident has been closed.
|
// even after the incident has been closed.
|
||||||
testCaseResult.setIncidentId(incidentStateId);
|
testCaseResult.setIncidentId(incidentStateId);
|
||||||
|
// if the test case failed, we'll add the incidentId field to update the testCase entity on ln
|
||||||
|
// 293
|
||||||
|
fields.add(INCIDENTS_FIELD);
|
||||||
|
} else {
|
||||||
|
// If the test case passed, we'll remove the incidentId from the test case
|
||||||
|
testCase.setIncidentId(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We add the incidentStateId in the DQ table to quickly link Test Case <> Incident
|
// We add the incidentStateId in the DQ table to quickly link Test Case <> Incident
|
||||||
@ -282,8 +290,7 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
|
|||||||
JsonUtils.pojoToJson(testCaseResult),
|
JsonUtils.pojoToJson(testCaseResult),
|
||||||
incidentStateId != null ? incidentStateId.toString() : null);
|
incidentStateId != null ? incidentStateId.toString() : null);
|
||||||
|
|
||||||
setFieldsInternal(
|
setFieldsInternal(testCase, new EntityUtil.Fields(allowedFields, ImmutableSet.copyOf(fields)));
|
||||||
testCase, new EntityUtil.Fields(allowedFields, Set.of(TEST_SUITE_FIELD, INCIDENTS_FIELD)));
|
|
||||||
setTestSuiteSummary(
|
setTestSuiteSummary(
|
||||||
testCase, testCaseResult.getTimestamp(), testCaseResult.getTestCaseStatus(), false);
|
testCase, testCaseResult.getTimestamp(), testCaseResult.getTestCaseStatus(), false);
|
||||||
setTestCaseResult(testCase, testCaseResult, false);
|
setTestCaseResult(testCase, testCaseResult, false);
|
||||||
|
|||||||
@ -1118,8 +1118,7 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
|
|||||||
UUID incidentId = result.getIncidentId();
|
UUID incidentId = result.getIncidentId();
|
||||||
assertNotNull(result.getIncidentId());
|
assertNotNull(result.getIncidentId());
|
||||||
|
|
||||||
// Resolving the status triggers resolving the task, which triggers removing the ongoing
|
// Resolving the status
|
||||||
// incident from the test case
|
|
||||||
CreateTestCaseResolutionStatus createResolvedStatus =
|
CreateTestCaseResolutionStatus createResolvedStatus =
|
||||||
new CreateTestCaseResolutionStatus()
|
new CreateTestCaseResolutionStatus()
|
||||||
.withTestCaseReference(testCaseEntity.getFullyQualifiedName())
|
.withTestCaseReference(testCaseEntity.getFullyQualifiedName())
|
||||||
@ -1145,8 +1144,52 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
|
|||||||
ADMIN_AUTH_HEADERS);
|
ADMIN_AUTH_HEADERS);
|
||||||
|
|
||||||
result = getTestCase(testCaseEntity.getFullyQualifiedName(), ADMIN_AUTH_HEADERS);
|
result = getTestCase(testCaseEntity.getFullyQualifiedName(), ADMIN_AUTH_HEADERS);
|
||||||
|
UUID newIncidentId = result.getIncidentId();
|
||||||
|
|
||||||
assertNotNull(result.getIncidentId());
|
assertNotNull(result.getIncidentId());
|
||||||
assertNotEquals(incidentId, result.getIncidentId());
|
assertNotEquals(incidentId, result.getIncidentId());
|
||||||
|
|
||||||
|
// Add a new testCase Result with status Success. This should clear the incidentId
|
||||||
|
// from the testCase and the testCaseResult should not have an incidentId.
|
||||||
|
putTestCaseResult(
|
||||||
|
testCaseEntity.getFullyQualifiedName(),
|
||||||
|
new TestCaseResult()
|
||||||
|
.withResult("result")
|
||||||
|
.withTestCaseStatus(TestCaseStatus.Success)
|
||||||
|
.withTimestamp(TestUtils.dateToTimestamp("2024-01-03")),
|
||||||
|
ADMIN_AUTH_HEADERS);
|
||||||
|
|
||||||
|
result = getTestCase(testCaseEntity.getFullyQualifiedName(), ADMIN_AUTH_HEADERS);
|
||||||
|
List<TestCaseResult> testCaseResults =
|
||||||
|
getTestCaseResults(
|
||||||
|
testCaseEntity.getFullyQualifiedName(),
|
||||||
|
TestUtils.dateToTimestamp("2024-01-03"),
|
||||||
|
TestUtils.dateToTimestamp("2024-01-03"),
|
||||||
|
ADMIN_AUTH_HEADERS)
|
||||||
|
.getData();
|
||||||
|
assertNull(testCaseResults.get(0).getIncidentId());
|
||||||
|
assertNull(result.getIncidentId());
|
||||||
|
|
||||||
|
// Add a new testCase Result with status Failure at an older date.
|
||||||
|
// The incidentId should be the one from "2024-01-02" but the testCase incidentId should be null
|
||||||
|
// as it should reflect the latest testCaseResult
|
||||||
|
putTestCaseResult(
|
||||||
|
testCaseEntity.getFullyQualifiedName(),
|
||||||
|
new TestCaseResult()
|
||||||
|
.withResult("result")
|
||||||
|
.withTestCaseStatus(TestCaseStatus.Failed)
|
||||||
|
.withTimestamp(TestUtils.dateToTimestamp("2023-12-31")),
|
||||||
|
ADMIN_AUTH_HEADERS);
|
||||||
|
result = getTestCase(testCaseEntity.getFullyQualifiedName(), ADMIN_AUTH_HEADERS);
|
||||||
|
testCaseResults =
|
||||||
|
getTestCaseResults(
|
||||||
|
testCaseEntity.getFullyQualifiedName(),
|
||||||
|
TestUtils.dateToTimestamp("2023-12-31"),
|
||||||
|
TestUtils.dateToTimestamp("2023-12-31"),
|
||||||
|
ADMIN_AUTH_HEADERS)
|
||||||
|
.getData();
|
||||||
|
assertEquals(newIncidentId, testCaseResults.get(0).getIncidentId());
|
||||||
|
assertNull(result.getIncidentId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user