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

This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-09-21 21:54:19 -05:00
1 parent 7f5336e2dc
commit f50431c6d6
4 files changed
+38 -17

No files matched your search

@@ -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 ────────────────────────────
@@ -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 ────────────────────────────
@@ -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 ────────────────────────────
@@ -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 ────────────────────────────
/**