Skip to content

armgit / floci

Public Imported from GitHub
0

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

test(applicationautoscaling): drive alarm evaluation directly in the ECS control-loop test (#3969)

Priamo Germosen224b56bd8c40
diff --git a/src/test/java/io/github/hectorvent/floci/services/applicationautoscaling/ApplicationAutoScalingEcsControlLoopIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/applicationautoscaling/ApplicationAutoScalingEcsControlLoopIntegrationTest.java
index 4aff88ecd7..aee97de4e4 100644
--- a/src/test/java/io/github/hectorvent/floci/services/applicationautoscaling/ApplicationAutoScalingEcsControlLoopIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/applicationautoscaling/ApplicationAutoScalingEcsControlLoopIntegrationTest.java
@@ -1,9 +1,12 @@
package io.github.hectorvent.floci.services.applicationautoscaling;
+import io.github.hectorvent.floci.services.cloudwatch.metrics.AlarmEvaluator;
+import io.github.hectorvent.floci.services.cloudwatch.metrics.AlarmEvaluatorTestAccess;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
+import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -49,6 +52,9 @@ class ApplicationAutoScalingEcsControlLoopIntegrationTest {
private static final String SERVICE = "aas-loop-svc";
private static final String RESOURCE_ID = "service/" + CLUSTER + "/" + SERVICE;
+ @Inject
+ AlarmEvaluator alarmEvaluator;
+
@BeforeAll
static void configure() {
RestAssuredJsonUtils.configureAwsContentTypes();
@@ -125,15 +131,20 @@ class ApplicationAutoScalingEcsControlLoopIntegrationTest {
"{\"Namespace\":\"AWS/ECS\",\"MetricData\":" + metricData + "}", CLOUDWATCH_JSON_CONTENT_TYPE);
int maxCapacity = 10;
- await().atMost(Duration.ofSeconds(60)).untilAsserted(() ->
- call(ECS_TARGET, "DescribeServices",
- "{\"cluster\":\"" + CLUSTER + "\",\"services\":[\"" + SERVICE + "\"]}")
- .then().body("services[0].desiredCount", equalTo(maxCapacity)));
-
- await().during(Duration.ofSeconds(15)).atMost(Duration.ofSeconds(20)).untilAsserted(() ->
- call(ECS_TARGET, "DescribeServices",
- "{\"cluster\":\"" + CLUSTER + "\",\"services\":[\"" + SERVICE + "\"]}")
- .then().body("services[0].desiredCount", equalTo(maxCapacity)));
+ await().atMost(Duration.ofSeconds(30)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> {
+ AlarmEvaluatorTestAccess.evaluateNow(alarmEvaluator);
+ call(ECS_TARGET, "DescribeServices",
+ "{\"cluster\":\"" + CLUSTER + "\",\"services\":[\"" + SERVICE + "\"]}")
+ .then().body("services[0].desiredCount", equalTo(maxCapacity));
+ });
+
+ await().during(Duration.ofSeconds(3)).atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100))
+ .untilAsserted(() -> {
+ AlarmEvaluatorTestAccess.evaluateNow(alarmEvaluator);
+ call(ECS_TARGET, "DescribeServices",
+ "{\"cluster\":\"" + CLUSTER + "\",\"services\":[\"" + SERVICE + "\"]}")
+ .then().body("services[0].desiredCount", equalTo(maxCapacity));
+ });
call(AAS_TARGET, "DescribeScalingActivities", """
{ "ServiceNamespace": "ecs", "ResourceId": "%s" }
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudwatch/metrics/AlarmEvaluatorTestAccess.java b/src/test/java/io/github/hectorvent/floci/services/cloudwatch/metrics/AlarmEvaluatorTestAccess.java
new file mode 100644
index 0000000000..e85328fe01
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudwatch/metrics/AlarmEvaluatorTestAccess.java
@@ -0,0 +1,15 @@
+package io.github.hectorvent.floci.services.cloudwatch.metrics;
+
+/**
+ * Lets tests outside this package run an alarm evaluation pass on demand instead of waiting
+ * for the evaluator's scheduled tick.
+ */
+public final class AlarmEvaluatorTestAccess {
+
+ private AlarmEvaluatorTestAccess() {
+ }
+
+ public static void evaluateNow(AlarmEvaluator evaluator) {
+ evaluator.evaluateAll();
+ }
+}