Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

test(apigatewayv2): delete the WebSocket tests' Lambda functions concurrently in cleanup (#4075)

Priamo Germosenf50431c6d642
diff --git a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketAwsHttpIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketAwsHttpIntegrationTest.java
index 1c5ee21c07..744efd48d1 100644
--- a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketAwsHttpIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketAwsHttpIntegrationTest.java
@@ -504,7 +504,7 @@ class WebSocketAwsHttpIntegrationTest {
@Test
@Order(999)
- void cleanup() {
+ void cleanup() throws Exception {
if (awsApiId != null) {
given().when().delete("/v2/apis/" + awsApiId);
}
@@ -518,10 +518,8 @@ class WebSocketAwsHttpIntegrationTest {
given().when().delete("/v2/apis/" + stageVarHttpApiId);
}
- for (String fn : new String[]{awsFnName, awsConnectFnName, httpProxyConnectFnName,
- httpConnectFnName, stageVarHttpFnName}) {
- given().when().delete("/2015-03-31/functions/" + fn);
- }
+ WebSocketTestSupport.deleteFunctions(awsFnName, awsConnectFnName, httpProxyConnectFnName,
+ httpConnectFnName, stageVarHttpFnName);
}
// ──────────────────────────── Helpers ────────────────────────────
diff --git a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketConnectionLifecycleTest.java b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketConnectionLifecycleTest.java
index 5f90d25a7e..7cc4d35401 100644
--- a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketConnectionLifecycleTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketConnectionLifecycleTest.java
@@ -448,7 +448,7 @@ class WebSocketConnectionLifecycleTest {
@Test
@Order(999)
- void cleanup() {
+ void cleanup() throws Exception {
// Delete routes if they still exist
if (connectRouteId != null) {
given().when().delete("/v2/apis/" + wsApiId + "/routes/" + connectRouteId)
@@ -468,10 +468,8 @@ class WebSocketConnectionLifecycleTest {
}
// Delete Lambda functions
- given().when().delete("/2015-03-31/functions/" + allowFunctionName);
- given().when().delete("/2015-03-31/functions/" + denyFunctionName);
- given().when().delete("/2015-03-31/functions/" + errorFunctionName);
- given().when().delete("/2015-03-31/functions/" + disconnectFunctionName);
+ WebSocketTestSupport.deleteFunctions(allowFunctionName, denyFunctionName, errorFunctionName,
+ disconnectFunctionName);
}
// ──────────────────────────── Helpers ────────────────────────────
diff --git a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketLambdaAuthorizerTest.java b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketLambdaAuthorizerTest.java
index b4abcbe78c..08a078d185 100644
--- a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketLambdaAuthorizerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketLambdaAuthorizerTest.java
@@ -511,19 +511,15 @@ class WebSocketLambdaAuthorizerTest {
@Test
@Order(999)
- void cleanup() {
+ void cleanup() throws Exception {
if (connectRouteId != null) {
given().when().delete("/v2/apis/" + wsApiId + "/routes/" + connectRouteId);
}
if (wsApiId != null) {
given().when().delete("/v2/apis/" + wsApiId);
}
- given().when().delete("/2015-03-31/functions/" + allowAuthFnName);
- given().when().delete("/2015-03-31/functions/" + denyAuthFnName);
- given().when().delete("/2015-03-31/functions/" + errorAuthFnName);
- given().when().delete("/2015-03-31/functions/" + contextAuthFnName);
- given().when().delete("/2015-03-31/functions/" + echoAuthFnName);
- given().when().delete("/2015-03-31/functions/" + connectFnName);
+ WebSocketTestSupport.deleteFunctions(allowAuthFnName, denyAuthFnName, errorAuthFnName,
+ contextAuthFnName, echoAuthFnName, connectFnName);
}
// ──────────────────────────── Helpers ────────────────────────────
diff --git a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketTestSupport.java b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketTestSupport.java
index 569ac1454b..5791fa2c49 100644
--- a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketTestSupport.java
+++ b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/WebSocketTestSupport.java
@@ -4,14 +4,21 @@ import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.WebSocket;
+import java.util.ArrayList;
import java.util.Base64;
+import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
+import static io.restassured.RestAssured.given;
+
/**
* Shared test utilities for WebSocket integration tests.
* Eliminates duplication of MessageCapture, MultiMessageCapture, createLambdaZip,
@@ -37,6 +44,28 @@ public final class WebSocketTestSupport {
return Base64.getEncoder().encodeToString(baos.toByteArray());
}
+ // ──────────────────────────── Lambda cleanup ────────────────────────────
+
+ /**
+ * Deletes the given Lambda functions concurrently. Deleting a function that has a warm
+ * container stops that container, which takes about a second, so deleting several one after
+ * another dominates a test class's cleanup.
+ */
+ public static void deleteFunctions(String... functionNames) throws Exception {
+ ExecutorService executor = Executors.newFixedThreadPool(functionNames.length);
+ try {
+ List<Future<?>> deletions = new ArrayList<>();
+ for (String functionName : functionNames) {
+ deletions.add(executor.submit(() -> given().when().delete("/2015-03-31/functions/" + functionName)));
+ }
+ for (Future<?> deletion : deletions) {
+ deletion.get();
+ }
+ } finally {
+ executor.shutdown();
+ }
+ }
+
// ──────────────────────────── WebSocket URL construction ────────────────────────────
/**