mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 09:22:49 -05:00
test(eventbridge): verify retries without callback timing assumptions (#6526)
This commit is contained in:
1 parent
3aa8149d08
commit
3e3ba5ba63
2 files changed
+10
-12
No files matched your search
+4
-9
@@ -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);
|
||||
}
|
||||
|
||||
+6
-3
@@ -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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user