Light, fluffy, and always free - The AWS Local Emulator alternative
test(lambda): close every fixture executor (#6741)
Andre Kuraite8ba4b27e91c
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaExecutorServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaExecutorServiceTest.javaindex 52e86c127f..d5fdbdbe2c 100644--- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaExecutorServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaExecutorServiceTest.java@@ -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;@BeforeEachvoid 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;+ }+@Testvoid 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 {@Testvoid 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 {@Testvoid 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 {@Testvoid 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;}