Light, fluffy, and always free - The AWS Local Emulator alternative
test(eventbridge): verify retries without callback timing assumptions (#6526)
Andre Kurait3e3ba5ba63c8
diff --git a/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeApiDestinationDeliveryIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeApiDestinationDeliveryIntegrationTest.javaindex be6569130f..c3ab5c2be3 100644--- a/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeApiDestinationDeliveryIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeApiDestinationDeliveryIntegrationTest.java@@ -14,9 +14,7 @@ import java.io.OutputStream;import java.net.InetSocketAddress;import java.nio.charset.StandardCharsets;import java.time.Duration;-import java.time.Instant;import java.util.List;-import java.util.concurrent.CopyOnWriteArrayList;import java.util.concurrent.CountDownLatch;import java.util.concurrent.TimeUnit;import java.util.concurrent.atomic.AtomicInteger;@@ -27,7 +25,6 @@ import static org.hamcrest.Matchers.equalTo;import static org.hamcrest.Matchers.nullValue;import static org.junit.jupiter.api.Assertions.assertEquals;import static org.junit.jupiter.api.Assertions.assertFalse;-import static org.junit.jupiter.api.Assertions.assertNotEquals;import static org.junit.jupiter.api.Assertions.assertTrue;@QuarkusTest@@ -219,13 +216,13 @@ class EventBridgeApiDestinationDeliveryIntegrationTest {}@Test- void aDestinationOverItsRateLimitIsThrottledAndRetriedLater() throws Exception {+ void eventsToARateLimitedDestinationAreEventuallyDelivered() throws Exception {CountDownLatch delivered = new CountDownLatch(2);- List<Long> secondsOfDelivery = new CopyOnWriteArrayList<>();+ AtomicInteger requests = new AtomicInteger();HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);server.createContext("/hook", exchange -> {exchange.getRequestBody().readAllBytes();- secondsOfDelivery.add(Instant.now().getEpochSecond());+ requests.incrementAndGet();reply(exchange, "{}");delivered.countDown();});@@ -260,9 +257,7 @@ class EventBridgeApiDestinationDeliveryIntegrationTest {.then().statusCode(200);assertTrue(awaitAdvancingClock(delivered), "both events should be delivered eventually");- assertEquals(2, secondsOfDelivery.size());- assertNotEquals(secondsOfDelivery.get(0), secondsOfDelivery.get(1),- "a limit of one request per second must spread the deliveries over different seconds");+ assertEquals(2, requests.get());} finally {server.stop(0);}diff --git a/src/test/java/io/github/hectorvent/floci/services/eventbridge/TargetDispatcherTest.java b/src/test/java/io/github/hectorvent/floci/services/eventbridge/TargetDispatcherTest.javaindex 2d5250737d..370b5ef1b5 100644--- a/src/test/java/io/github/hectorvent/floci/services/eventbridge/TargetDispatcherTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/eventbridge/TargetDispatcherTest.java@@ -61,10 +61,13 @@ class TargetDispatcherTest {dispatcher = new TargetDispatcher(invoker, sqsService, BASE_URL, clock, null);}- @Test- void transientRefusalIsRetriedAfterBackoffUntilAccepted() {+ @ParameterizedTest+ @ValueSource(ints = {429, 503})+ void transientRefusalIsRetriedAfterBackoffUntilAccepted(int httpStatus) {when(sqsService.sendMessage(TARGET_URL, EVENT, 0, null, null, REGION))- .thenThrow(unavailable())+ .thenThrow(httpStatus == 429+ ? new AwsException("ThrottlingException", "Request limit reached.", 429)+ : unavailable()).thenReturn(null);Target target = sqsTarget(null, DLQ_ARN);