mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
test(emr): await cluster cleanup before fixture teardown (#7714)
Preserve workload assertions while awaiting terminal cluster state and released storage/bootstrap ownership. Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
1 parent
ba9a9c8155
commit
244cdaa2d2
3 files changed
+31
-4
No files matched your search
@@ -43,6 +43,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import static io.floci.aws.testing.EmrRequests.awaitStep;
|
||||
import static io.floci.aws.testing.EmrRequests.emr;
|
||||
import static io.floci.aws.testing.EmrRequests.terminateClusterAndAwaitCleanup;
|
||||
import static io.floci.aws.testing.EmrServerlessRequests.awaitJobRun;
|
||||
import static io.floci.aws.testing.EmrServerlessRequests.createSparkApplication;
|
||||
import static io.floci.aws.testing.EmrServerlessRequests.deleteApplication;
|
||||
@@ -90,6 +91,9 @@ class EmrDockerRunnerDockerIntegrationTest {
|
||||
@Inject
|
||||
EmulatorConfig config;
|
||||
|
||||
@Inject
|
||||
EmrService emrService;
|
||||
|
||||
private S3Client s3;
|
||||
private String bucket;
|
||||
private String clusterId;
|
||||
@@ -308,8 +312,7 @@ class EmrDockerRunnerDockerIntegrationTest {
|
||||
+ "\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,\"InstanceGroups\":[{\"Name\":\"primary\","
|
||||
+ "\"InstanceRole\":\"MASTER\",\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1}]}}")
|
||||
.then().statusCode(200).extract().jsonPath().getString("JobFlowId");
|
||||
cleanup.register(() -> emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + clusterId + "\"]}")
|
||||
.then().statusCode(200));
|
||||
cleanup.register(() -> terminateClusterAndAwaitCleanup(clusterId, emrService));
|
||||
}
|
||||
|
||||
/** Adds one step to the cluster and returns the state it ended in. */
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.floci.aws.testing.S3TestClients;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.response.Response;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -33,6 +34,7 @@ import java.util.zip.GZIPInputStream;
|
||||
|
||||
import static io.floci.aws.testing.EmrRequests.awaitStep;
|
||||
import static io.floci.aws.testing.EmrRequests.emr;
|
||||
import static io.floci.aws.testing.EmrRequests.terminateClusterAndAwaitCleanup;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
@@ -56,6 +58,9 @@ class EmrHiveStepsDockerIntegrationTest {
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
@Inject
|
||||
EmrService emrService;
|
||||
|
||||
private S3Client s3;
|
||||
private String bucket;
|
||||
private String clusterId;
|
||||
@@ -216,8 +221,7 @@ class EmrHiveStepsDockerIntegrationTest {
|
||||
.put("InstanceCount", 1);
|
||||
clusterId = emr("RunJobFlow", request.toString()).then().statusCode(200).extract().jsonPath()
|
||||
.getString("JobFlowId");
|
||||
cleanup.register(() -> emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + clusterId + "\"]}")
|
||||
.then().statusCode(200));
|
||||
cleanup.register(() -> terminateClusterAndAwaitCleanup(clusterId, emrService));
|
||||
}
|
||||
|
||||
/** Runs the AWS CLI's Hive step with {@code args} and returns the state it ended in. */
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.floci.aws.testing;
|
||||
|
||||
import io.floci.aws.services.emr.EmrService;
|
||||
import io.floci.aws.services.emr.model.EmrCluster;
|
||||
import io.restassured.response.Response;
|
||||
|
||||
import java.time.Duration;
|
||||
@@ -12,7 +14,9 @@ import static org.awaitility.Awaitility.await;
|
||||
public final class EmrRequests {
|
||||
|
||||
private static final Set<String> UNFINISHED_STEP_STATES = Set.of("PENDING", "RUNNING");
|
||||
private static final Set<String> TERMINATED_CLUSTER_STATES = Set.of("TERMINATED", "TERMINATED_WITH_ERRORS");
|
||||
private static final Duration STEP_TIMEOUT = Duration.ofMinutes(5);
|
||||
private static final Duration CLEANUP_TIMEOUT = Duration.ofSeconds(30);
|
||||
private static final Duration POLL_INTERVAL = Duration.ofMillis(500);
|
||||
|
||||
private EmrRequests() {}
|
||||
@@ -47,4 +51,20 @@ public final class EmrRequests {
|
||||
response -> !UNFINISHED_STEP_STATES.contains(
|
||||
response.jsonPath().getString("Step.Status.State")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends a test's default-account/default-region cluster and waits for its owned storage and bootstrap image
|
||||
* to be released. TerminateJobFlows accepts the request before that background cleanup has completed.
|
||||
*/
|
||||
public static void terminateClusterAndAwaitCleanup(String clusterId, EmrService service) {
|
||||
emr("TerminateJobFlows", "{\"JobFlowIds\":[\"" + clusterId + "\"]}").then().statusCode(200);
|
||||
await("cluster " + clusterId + " to terminate and release its storage and bootstrap image")
|
||||
.atMost(CLEANUP_TIMEOUT)
|
||||
.pollInterval(POLL_INTERVAL)
|
||||
.until(() -> {
|
||||
EmrCluster cluster = service.describeCluster(clusterId);
|
||||
return TERMINATED_CLUSTER_STATES.contains(cluster.getState())
|
||||
&& !cluster.isStorageCreated() && cluster.getBootstrapImage() == null;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user