test(lambda): close every fixture executor (#6741)

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-27 11:41:47 -04:00
1 parent 33e74f7728
commit e8ba4b27e9
1 file changed
+28 -19
@@ -60,13 +60,13 @@ class LambdaExecutorServiceTest {
@Mock WarmPool warmPool;
@Mock LambdaConcurrencyLimiter concurrencyLimiter;
private final List<LambdaExecutorService> retryExecutors = new ArrayList<>();
private final List<LambdaExecutorService> executors = new ArrayList<>();
private LambdaExecutorService executor;
private LambdaFunction fn;
@BeforeEach
void setUp() {
executor = new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter);
executor = registerExecutor(new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter));
fn = new LambdaFunction();
fn.setFunctionName("test-fn");
@@ -77,12 +77,17 @@ class LambdaExecutorServiceTest {
}
@AfterEach
void shutDownRetryExecutors() {
for (LambdaExecutorService retryExecutor : retryExecutors) {
retryExecutor.shutdown();
void shutDownExecutors() {
for (LambdaExecutorService owned : executors) {
owned.shutdown();
}
}
private LambdaExecutorService registerExecutor(LambdaExecutorService owned) {
executors.add(owned);
return owned;
}
@Test
void asyncInvocationPastTheChainBound_isDroppedWithoutRunningTheFunction() {
// AWS stops the next invocation in a chain of requests once the same originating event has
@@ -106,8 +111,8 @@ class LambdaExecutorServiceTest {
version.setFunctionArn(fn.getFunctionArn() + ":1");
LambdaService lambdaService = mock(LambdaService.class);
when(lambdaService.findLatest(version)).thenReturn(Optional.of(fn));
LambdaExecutorService versionExecutor = new LambdaExecutorService(warmPool, new ObjectMapper(),
new LambdaConcurrencyLimiter(), null, lambdaService);
LambdaExecutorService versionExecutor = registerExecutor(new LambdaExecutorService(warmPool, new ObjectMapper(),
new LambdaConcurrencyLimiter(), null, lambdaService));
AwsException ex = assertThrows(AwsException.class,
() -> versionExecutor.invoke(version, "{}".getBytes(), InvocationType.RequestResponse));
@@ -127,7 +132,7 @@ class LambdaExecutorServiceTest {
void asyncInvocationPassesInvokedAliasToDestinationRouter() {
AsyncInvokeDestinationRouter router = mock(AsyncInvokeDestinationRouter.class);
executor.shutdown();
executor = new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, router);
executor = registerExecutor(new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, router));
RuntimeApiServer rtas = mock(RuntimeApiServer.class);
ContainerHandle handle = new ContainerHandle("cid-alias", "test-fn", rtas, ContainerState.WARM);
when(warmPool.acquire(fn)).thenReturn(handle);
@@ -219,7 +224,8 @@ class LambdaExecutorServiceTest {
@Test
void dispatchWait_coldRuntimeGetsTheInitBudget() {
LambdaExecutorService withBudget = new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, 10);
LambdaExecutorService withBudget =
registerExecutor(new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, 10));
try {
assertEquals(10_000, withBudget.dispatchWaitMs(1, true, 50_000, 50_000));
} finally {
@@ -229,7 +235,8 @@ class LambdaExecutorServiceTest {
@Test
void dispatchWait_warmRuntimeGetsTheTimeoutPlusGraceNotTheInitBudget() {
LambdaExecutorService withBudget = new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, 10);
LambdaExecutorService withBudget =
registerExecutor(new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, 10));
try {
assertEquals(3_000, withBudget.dispatchWaitMs(1, false, 50_000, 50_000));
} finally {
@@ -239,7 +246,8 @@ class LambdaExecutorServiceTest {
@Test
void dispatchWait_lateStartedRuntimeGetsWhatIsLeftOfTheInitBudget() {
LambdaExecutorService withBudget = new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, 10);
LambdaExecutorService withBudget =
registerExecutor(new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, 10));
try {
// The launcher spent 4 of the 10 seconds after the start (extensions, log attach).
assertEquals(6_000, withBudget.dispatchWaitMs(1, true, 50_000, 54_000));
@@ -338,7 +346,7 @@ class LambdaExecutorServiceTest {
void eventInvocation_answers202AndRoutesTheResultToDestinations() throws Exception {
AsyncInvokeDestinationRouter router = mock(AsyncInvokeDestinationRouter.class);
LambdaExecutorService routingExecutor =
new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, router);
registerExecutor(new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, router));
RuntimeApiServer rtas = mock(RuntimeApiServer.class);
ContainerHandle handle = new ContainerHandle("cid-async", "test-fn", rtas, ContainerState.WARM);
@@ -375,7 +383,8 @@ class LambdaExecutorServiceTest {
when(lambdaService.isLive(fn)).thenReturn(true);
LambdaExecutorService retryExecutor =
new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, router, lambdaService);
registerExecutor(new LambdaExecutorService(warmPool, new ObjectMapper(),
concurrencyLimiter, router, lambdaService));
RuntimeApiServer rtas = mock(RuntimeApiServer.class);
ContainerHandle handle = new ContainerHandle("cid-retry", "test-fn", rtas, ContainerState.WARM);
when(warmPool.acquire(any())).thenReturn(handle);
@@ -412,7 +421,8 @@ class LambdaExecutorServiceTest {
when(lambdaService.findEventInvokeConfig(fn, null)).thenReturn(Optional.of(config));
when(lambdaService.isLive(fn)).thenReturn(true);
LambdaExecutorService retryExecutor =
new LambdaExecutorService(warmPool, new ObjectMapper(), concurrencyLimiter, router, lambdaService);
registerExecutor(new LambdaExecutorService(warmPool, new ObjectMapper(),
concurrencyLimiter, router, lambdaService));
CountDownLatch routed = new CountDownLatch(1);
doAnswer(invocation -> {
@@ -442,8 +452,8 @@ class LambdaExecutorServiceTest {
when(lambdaService.findEventInvokeConfig(fn, null)).thenReturn(Optional.of(config));
when(lambdaService.isLive(fn)).thenReturn(true);
MutableClock clock = new MutableClock();
LambdaExecutorService retryExecutor = new LambdaExecutorService(warmPool, new ObjectMapper(),
concurrencyLimiter, router, lambdaService, clock, Duration.ZERO);
LambdaExecutorService retryExecutor = registerExecutor(new LambdaExecutorService(warmPool, new ObjectMapper(),
concurrencyLimiter, router, lambdaService, clock, Duration.ZERO));
RuntimeApiServer rtas = mock(RuntimeApiServer.class);
ContainerHandle handle = new ContainerHandle("cid-age-after-failure", "test-fn", rtas, ContainerState.WARM);
@@ -690,9 +700,8 @@ class LambdaExecutorServiceTest {
private LambdaExecutorService retryingExecutor(AsyncInvokeDestinationRouter router, LambdaService lambdaService,
Duration asyncRetryDelay) {
LambdaExecutorService retryExecutor = new LambdaExecutorService(warmPool, new ObjectMapper(),
concurrencyLimiter, router, lambdaService, Clock.systemUTC(), asyncRetryDelay);
retryExecutors.add(retryExecutor);
LambdaExecutorService retryExecutor = registerExecutor(new LambdaExecutorService(warmPool, new ObjectMapper(),
concurrencyLimiter, router, lambdaService, Clock.systemUTC(), asyncRetryDelay));
return retryExecutor;
}