fix(alerting/I-1): retry endpoint resets attempts to 0 instead of incrementing

AlertNotificationRepository gains resetForRetry(UUID, Instant) which sets
attempts=0, status=PENDING, next_attempt_at=now, and clears claim/response
fields. AlertNotificationController calls resetForRetry instead of
scheduleRetry so a manual retry always starts from a clean slate.

AlertNotificationControllerIT adds retryResetsAttemptsToZero to verify
attempts==0 and status==PENDING after three prior markFailed calls.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-20 08:25:59 +02:00
parent d74079da63
commit 424894a3e2
4 changed files with 47 additions and 4 deletions

View File

@@ -113,6 +113,35 @@ class AlertNotificationControllerIT extends AbstractPostgresIT {
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@Test
void retryResetsAttemptsToZero() throws Exception {
// Verify Fix I-1: retry endpoint resets attempts to 0, not attempts+1
AlertInstance instance = seedInstance();
AlertNotification notification = seedNotification(instance.id());
// Mark as failed with attempts at max (simulate exhausted retries)
notificationRepo.markFailed(notification.id(), 500, "server error");
notificationRepo.markFailed(notification.id(), 500, "server error");
notificationRepo.markFailed(notification.id(), 500, "server error");
// Verify attempts > 0 before retry
AlertNotification before = notificationRepo.findById(notification.id()).orElseThrow();
assertThat(before.attempts()).isGreaterThan(0);
// Operator retries
ResponseEntity<String> resp = restTemplate.exchange(
"/api/v1/alerts/notifications/" + notification.id() + "/retry",
HttpMethod.POST,
new HttpEntity<>(securityHelper.authHeaders(operatorJwt)),
String.class);
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
// After retry: attempts must be 0 and status PENDING (not attempts+1)
AlertNotification after = notificationRepo.findById(notification.id()).orElseThrow();
assertThat(after.attempts()).as("retry must reset attempts to 0").isEqualTo(0);
assertThat(after.status()).isEqualTo(NotificationStatus.PENDING);
}
@Test
void viewerCannotRetry() throws Exception {
AlertInstance instance = seedInstance();