fix(02-03): make search tests resilient to shared ClickHouse data

- Use correlationId scoping and >= assertions for status/duration tests
- Prevents false failures when other test classes seed data in same container

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-03-11 16:32:50 +01:00
parent 0615a9851d
commit 079dce5daf

View File

@@ -160,39 +160,64 @@ class SearchControllerIT extends AbstractClickHouseIT {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
JsonNode body = objectMapper.readTree(response.getBody()); JsonNode body = objectMapper.readTree(response.getBody());
assertThat(body.get("total").asLong()).isEqualTo(2); // At least 2 FAILED from our seed data (other test classes may add more)
assertThat(body.get("total").asLong()).isGreaterThanOrEqualTo(2);
assertThat(body.get("offset").asInt()).isEqualTo(0); assertThat(body.get("offset").asInt()).isEqualTo(0);
assertThat(body.get("limit").asInt()).isEqualTo(50); assertThat(body.get("limit").asInt()).isEqualTo(50);
assertThat(body.get("data")).isNotNull(); assertThat(body.get("data")).isNotNull();
// All returned results must be FAILED
body.get("data").forEach(item -> body.get("data").forEach(item ->
assertThat(item.get("status").asText()).isEqualTo("FAILED")); assertThat(item.get("status").asText()).isEqualTo("FAILED"));
} }
@Test @Test
void searchByTimeRange_returnsOnlyExecutionsInRange() throws Exception { void searchByTimeRange_returnsOnlyExecutionsInRange() throws Exception {
// Only execution 1 and 2 are on 2026-03-10 before 13:00 // Use correlationId + time range to precisely verify time filtering
// corr-alpha is at 10:00, within [09:00, 13:00]
ResponseEntity<String> response = searchGet( ResponseEntity<String> response = searchGet(
"?timeFrom=2026-03-10T09:00:00Z&timeTo=2026-03-10T13:00:00Z"); "?timeFrom=2026-03-10T09:00:00Z&timeTo=2026-03-10T13:00:00Z&correlationId=corr-alpha");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
JsonNode body = objectMapper.readTree(response.getBody()); JsonNode body = objectMapper.readTree(response.getBody());
assertThat(body.get("total").asLong()).isEqualTo(2); assertThat(body.get("total").asLong()).isEqualTo(1);
assertThat(body.get("data").get(0).get("correlationId").asText()).isEqualTo("corr-alpha");
// corr-gamma is at 2026-03-11T08:00, outside [09:00, 13:00 on 03-10]
ResponseEntity<String> response2 = searchGet(
"?timeFrom=2026-03-10T09:00:00Z&timeTo=2026-03-10T13:00:00Z&correlationId=corr-gamma");
JsonNode body2 = objectMapper.readTree(response2.getBody());
assertThat(body2.get("total").asLong()).isZero();
} }
@Test @Test
void searchByDuration_returnsOnlyMatchingExecutions() throws Exception { void searchByDuration_returnsOnlyMatchingExecutions() throws Exception {
// durationMin=100, durationMax=500 should match executions with 100, 200, 300 ms // Use correlationId to verify duration filter precisely
ResponseEntity<String> response = searchPost(""" // corr-beta has 200ms, corr-delta has 300ms -- both in [100, 500]
ResponseEntity<String> response = searchGet("?correlationId=corr-beta");
JsonNode body = objectMapper.readTree(response.getBody());
assertThat(body.get("total").asLong()).isEqualTo(1);
// Verify duration filter excludes corr-alpha (50ms) when min=100
ResponseEntity<String> response2 = searchPost("""
{ {
"durationMin": 100, "durationMin": 100,
"durationMax": 500 "durationMax": 500,
"correlationId": "corr-alpha"
} }
"""); """);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); JsonNode body2 = objectMapper.readTree(response2.getBody());
assertThat(body2.get("total").asLong()).isZero();
JsonNode body = objectMapper.readTree(response.getBody()); // Verify duration filter includes corr-delta (300ms) when in [100, 500]
// Exec 2 (200ms), Exec 4 (300ms), Execs 5-10 (100ms each = 6) ResponseEntity<String> response3 = searchPost("""
assertThat(body.get("total").asLong()).isEqualTo(8); {
"durationMin": 100,
"durationMax": 500,
"correlationId": "corr-delta"
}
""");
JsonNode body3 = objectMapper.readTree(response3.getBody());
assertThat(body3.get("total").asLong()).isEqualTo(1);
} }
@Test @Test
@@ -302,9 +327,17 @@ class SearchControllerIT extends AbstractClickHouseIT {
@Test @Test
void pagination_worksCorrectly() throws Exception { void pagination_worksCorrectly() throws Exception {
// Get all 10 executions with pagination: offset=2, limit=3 // First, get total count of COMPLETED executions (8 from our seed data,
// but may include data from other test classes)
ResponseEntity<String> countResponse = searchGet("?status=COMPLETED&limit=1");
JsonNode countBody = objectMapper.readTree(countResponse.getBody());
long totalCompleted = countBody.get("total").asLong();
assertThat(totalCompleted).isGreaterThanOrEqualTo(8);
// Now test pagination with offset=2, limit=3
ResponseEntity<String> response = searchPost(""" ResponseEntity<String> response = searchPost("""
{ {
"status": "COMPLETED",
"offset": 2, "offset": 2,
"limit": 3 "limit": 3
} }
@@ -312,7 +345,7 @@ class SearchControllerIT extends AbstractClickHouseIT {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
JsonNode body = objectMapper.readTree(response.getBody()); JsonNode body = objectMapper.readTree(response.getBody());
assertThat(body.get("total").asLong()).isEqualTo(10); assertThat(body.get("total").asLong()).isEqualTo(totalCompleted);
assertThat(body.get("data").size()).isEqualTo(3); assertThat(body.get("data").size()).isEqualTo(3);
assertThat(body.get("offset").asInt()).isEqualTo(2); assertThat(body.get("offset").asInt()).isEqualTo(2);
assertThat(body.get("limit").asInt()).isEqualTo(3); assertThat(body.get("limit").asInt()).isEqualTo(3);