mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(eventbridge): retry target dispatch scope failures (#7201)
This commit is contained in:
1 parent
39a5a60edc
commit
1aa1ac6005
2 files changed
+125
-36
No files matched your search
+71
@@ -428,6 +428,77 @@ class TargetDispatcherTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void failureToEstablishRuleAccountScopeIsRetried() {
|
||||
Target target = sqsTarget(null, DLQ_ARN);
|
||||
AtomicReference<Boolean> failFirstScope = new AtomicReference<>(true);
|
||||
try (MockedStatic<RequestScopes> scopes =
|
||||
mockStatic(RequestScopes.class, withSettings().mockMaker(MockMakers.INLINE))) {
|
||||
scopes.when(() -> RequestScopes.runAs(eq("123456789012"), any(Runnable.class)))
|
||||
.thenAnswer(invocation -> {
|
||||
if (failFirstScope.getAndSet(false)) {
|
||||
throw new IllegalStateException("Request scope is not active");
|
||||
}
|
||||
invocation.<Runnable>getArgument(1).run();
|
||||
return null;
|
||||
});
|
||||
|
||||
dispatcher.dispatch("arn:aws:events:us-east-1:123456789012:rule/orders", target, EVENT, REGION,
|
||||
() -> List.of(target));
|
||||
verify(sqsService, never()).sendMessage(TARGET_URL, EVENT, 0, null, null, REGION);
|
||||
|
||||
tickAt(T0.plusSeconds(1));
|
||||
|
||||
scopes.verify(() -> RequestScopes.runAs(eq("123456789012"), any(Runnable.class)), times(2));
|
||||
verify(sqsService, times(1)).sendMessage(TARGET_URL, EVENT, 0, null, null, REGION);
|
||||
verifyNoDeadLetter();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedFailureToEstablishRuleAccountScopeIsDeadLetteredAtAttemptLimit() {
|
||||
Target target = sqsTarget(new Target.RetryPolicy(1, 3600), DLQ_ARN);
|
||||
try (MockedStatic<RequestScopes> scopes =
|
||||
mockStatic(RequestScopes.class, withSettings().mockMaker(MockMakers.INLINE))) {
|
||||
scopes.when(() -> RequestScopes.runAs(eq("123456789012"), any(Runnable.class)))
|
||||
.thenThrow(new IllegalStateException("Request scope is not active"));
|
||||
|
||||
dispatcher.dispatch("arn:aws:events:us-east-1:123456789012:rule/orders", target, EVENT, REGION,
|
||||
() -> List.of(target));
|
||||
verify(sqsService, never()).sendMessage(TARGET_URL, EVENT, 0, null, null, REGION);
|
||||
verifyNoDeadLetter();
|
||||
|
||||
tickAt(T0.plusSeconds(1));
|
||||
|
||||
scopes.verify(() -> RequestScopes.runAs(eq("123456789012"), any(Runnable.class)), times(2));
|
||||
Map<String, MessageAttributeValue> attributes = deadLetterAttributes();
|
||||
assertAttribute(attributes, "EXHAUSTED_RETRY_CONDITION", "MaximumRetryAttempts");
|
||||
assertAttribute(attributes, "RETRY_ATTEMPTS", "1");
|
||||
assertAttribute(attributes, "ERROR_CODE", "INTERNAL_ERROR");
|
||||
verify(sqsService, never()).sendMessage(eq(TARGET_URL), eq(EVENT), eq(0), isNull(), isNull(), eq(REGION));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedFailureToEstablishRuleAccountScopeStopsAtEventAgeLimit() {
|
||||
Target target = sqsTarget(new Target.RetryPolicy(5, 2), DLQ_ARN);
|
||||
try (MockedStatic<RequestScopes> scopes =
|
||||
mockStatic(RequestScopes.class, withSettings().mockMaker(MockMakers.INLINE))) {
|
||||
scopes.when(() -> RequestScopes.runAs(eq("123456789012"), any(Runnable.class)))
|
||||
.thenThrow(new IllegalStateException("Request scope is not active"));
|
||||
|
||||
dispatcher.dispatch("arn:aws:events:us-east-1:123456789012:rule/orders", target, EVENT, REGION,
|
||||
() -> List.of(target));
|
||||
tickAt(T0.plusSeconds(1));
|
||||
tickAt(T0.plusSeconds(2));
|
||||
|
||||
scopes.verify(() -> RequestScopes.runAs(eq("123456789012"), any(Runnable.class)), times(3));
|
||||
Map<String, MessageAttributeValue> attributes = deadLetterAttributes();
|
||||
assertAttribute(attributes, "EXHAUSTED_RETRY_CONDITION", "MaximumEventAgeInSeconds");
|
||||
assertAttribute(attributes, "RETRY_ATTEMPTS", "1");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void retryEstablishesRuleAccountScope() {
|
||||
Target target = sqsTarget(null, null);
|
||||
|
||||
Reference in new issue
Block a user