Skip to content

armgit / floci

Public Imported from GitHub
0

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

test(codepipeline): make the S3 source poll interval configurable so the negative tests wait less (#4236)

Priamo Germosen70df2241899e
diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md
index b743ad3a93..5e88eb590d 100644
--- a/docs/configuration/environment-variables.md
+++ b/docs/configuration/environment-variables.md
@@ -549,6 +549,7 @@ See [Web Console](../ui/index.md) for running the console and swapping in a thir
| `FLOCI_SERVICES_CODEBUILD_ENABLED` | `true` | Enable the CodeBuild service |
| `FLOCI_SERVICES_CODEBUILD_DOCKER_NETWORK` | _(none)_ | Docker network for CodeBuild build containers |
| `FLOCI_SERVICES_CODEDEPLOY_ENABLED` | `true` | Enable the CodeDeploy service |
+| `FLOCI_SERVICES_CODEPIPELINE_SOURCE_POLL_INTERVAL_MS` | `500` | How often (ms) the CodePipeline S3 source poller checks a configured `S3Bucket`/`S3ObjectKey` for a new object revision |
| `FLOCI_SERVICES_NETWORKFIREWALL_ENABLED` | `true` | Enable the AWS Network Firewall service |
| `FLOCI_SERVICES_SERVICEQUOTAS_ENABLED` | `true` | Enable the Service Quotas service |
| `FLOCI_SERVICES_RAM_ENABLED` | `true` | Enable the AWS RAM service |
diff --git a/docs/services/codepipeline.md b/docs/services/codepipeline.md
index cde89209de..25e7edf581 100644
--- a/docs/services/codepipeline.md
+++ b/docs/services/codepipeline.md
@@ -78,6 +78,7 @@ as `Approved` or `Rejected`, limits `result.summary` to 512 characters, returns
| `FLOCI_SERVICES_CODEPIPELINE_ENABLED` | `true` | Enables the CodePipeline API |
| `FLOCI_STORAGE_SERVICES_CODEPIPELINE_MODE` | global mode | Overrides CodePipeline storage mode |
| `FLOCI_STORAGE_SERVICES_CODEPIPELINE_FLUSH_INTERVAL_MS` | `5000` | Hybrid storage flush interval |
+| `FLOCI_SERVICES_CODEPIPELINE_SOURCE_POLL_INTERVAL_MS` | `500` | How often (ms) S3 sources are polled for a new object revision |
## Example
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index 7f4771682c..024a85cec1 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -1232,6 +1232,10 @@ public interface EmulatorConfig {
interface CodePipelineServiceConfig {
@WithDefault("true")
boolean enabled();
+
+ /** How often, in milliseconds, S3 sources are polled for a new object revision. */
+ @WithDefault("500")
+ long sourcePollIntervalMs();
}
interface SsmServiceConfig {
diff --git a/src/main/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineService.java b/src/main/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineService.java
index c3b5139a6e..d84ba1a52a 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineService.java
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
@@ -57,7 +58,6 @@ public class CodePipelineService {
private static final String DEFAULT_PIPELINE_TYPE = "V1";
private static final int MAX_ACTIVE_EXECUTIONS = 50;
private static final long POLL_INTERVAL_MS = 100L;
- private static final long SOURCE_POLL_INTERVAL_MS = 500L;
private static final String SOURCE_POLL_TYPE = "source-poll";
private static final String MISSING_SOURCE_REVISION = "missing";
@@ -81,12 +81,36 @@ public class CodePipelineService {
// An execution's status turns Failed as soon as one action fails, while its runner is still waiting
// on sibling actions. Retries check this set so they never overlap a runner that has not finished.
private final Set<String> activeRuns = ConcurrentHashMap.newKeySet();
+ private final long sourcePollIntervalMs;
+
+ /** Matches the {@code source-poll-interval-ms} default in application.yml. */
+ private static final long DEFAULT_SOURCE_POLL_INTERVAL_MS = 500L;
+
+ /**
+ * Package-private constructor for the tests that build the service without CDI. The source
+ * poll interval falls back to the configured default.
+ */
+ CodePipelineService(StorageFactory storageFactory, ObjectMapper mapper,
+ CodeBuildService codeBuildService, CodeDeployService codeDeployService,
+ LambdaService lambdaService, S3Service s3Service) {
+ this(storageFactory, mapper, codeBuildService, codeDeployService, lambdaService, s3Service,
+ DEFAULT_SOURCE_POLL_INTERVAL_MS);
+ }
@Inject
- @SuppressWarnings("unchecked")
public CodePipelineService(StorageFactory storageFactory, ObjectMapper mapper,
CodeBuildService codeBuildService, CodeDeployService codeDeployService,
- LambdaService lambdaService, S3Service s3Service) {
+ LambdaService lambdaService, S3Service s3Service,
+ EmulatorConfig config) {
+ this(storageFactory, mapper, codeBuildService, codeDeployService, lambdaService, s3Service,
+ config.services().codepipeline().sourcePollIntervalMs());
+ }
+
+ @SuppressWarnings("unchecked")
+ private CodePipelineService(StorageFactory storageFactory, ObjectMapper mapper,
+ CodeBuildService codeBuildService, CodeDeployService codeDeployService,
+ LambdaService lambdaService, S3Service s3Service,
+ long sourcePollIntervalMs) {
this.pipelineStore = storageFactory.create(
"codepipeline", "codepipeline-pipelines.json", new TypeReference<Map<String, CodePipelinePipeline>>() {});
this.executionStore = storageFactory.create(
@@ -98,6 +122,7 @@ public class CodePipelineService {
this.codeDeployService = codeDeployService;
this.lambdaService = lambdaService;
this.s3Service = s3Service;
+ this.sourcePollIntervalMs = sourcePollIntervalMs;
}
public JsonNode handle(String action, JsonNode request, String region, String account) {
@@ -174,7 +199,7 @@ public class CodePipelineService {
}
initializePersistedSourcePollingBaselines();
sourcePoller.scheduleWithFixedDelay(
- this::pollS3SourcesSafely, SOURCE_POLL_INTERVAL_MS, SOURCE_POLL_INTERVAL_MS, TimeUnit.MILLISECONDS);
+ this::pollS3SourcesSafely, sourcePollIntervalMs, sourcePollIntervalMs, TimeUnit.MILLISECONDS);
}
private void initializePersistedSourcePollingBaselines() {
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 358836537d..502e38a0c0 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -686,6 +686,7 @@ floci:
enabled: true
codepipeline:
enabled: true
+ source-poll-interval-ms: 500
autoscaling:
enabled: true
applicationautoscaling:
diff --git a/src/test/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineIntegrationTest.java
index 63435ff68a..50703e1790 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineIntegrationTest.java
@@ -1,9 +1,11 @@
package io.github.hectorvent.floci.services.codepipeline;
+import io.github.hectorvent.floci.config.EmulatorConfig;
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;
@@ -34,6 +36,20 @@ class CodePipelineIntegrationTest {
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
private static final String TARGET = "CodePipeline_20150709.";
+ @Inject
+ EmulatorConfig config;
+
+ /**
+ * Blocks until the S3 source poller has had {@code cycles} chances to run. The assertions that
+ * follow these waits are all negative ("no execution was started"), so what matters is that the
+ * poller really did get its turns and declined, not that a fixed number of milliseconds passed.
+ * Deriving the wait from the configured interval keeps that guarantee whatever the interval is
+ * set to.
+ */
+ private void awaitSourcePollCycles(int cycles) throws InterruptedException {
+ Thread.sleep(config.services().codepipeline().sourcePollIntervalMs() * cycles);
+ }
+
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
@@ -394,7 +410,7 @@ class CodePipelineIntegrationTest {
"""))
.then().statusCode(200);
- Thread.sleep(1200);
+ awaitSourcePollCycles(5);
post("ListPipelineExecutions", """
{"pipelineName": "%s"}
""".formatted(pipelineName))
@@ -423,7 +439,7 @@ class CodePipelineIntegrationTest {
.statusCode(200)
.body(equalTo("changed artifact"));
- Thread.sleep(1200);
+ awaitSourcePollCycles(5);
post("ListPipelineExecutions", """
{"pipelineName": "%s"}
""".formatted(pipelineName))
@@ -480,7 +496,7 @@ class CodePipelineIntegrationTest {
"""))
.then().statusCode(200);
- Thread.sleep(700);
+ awaitSourcePollCycles(3);
post("ListPipelineExecutions", """
{"pipelineName": "%s"}
""".formatted(pipelineName))
@@ -551,7 +567,7 @@ class CodePipelineIntegrationTest {
.then().statusCode(200);
putObject("codepipeline-poll-disabled-source", "source.zip", "changed artifact");
- Thread.sleep(1200);
+ awaitSourcePollCycles(5);
post("ListPipelineExecutions", """
{"pipelineName": "%s"}
diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml
index aab3a1871b..deafb99b22 100644
--- a/src/test/resources/application.yml
+++ b/src/test/resources/application.yml
@@ -366,6 +366,7 @@ floci:
enabled: true
codepipeline:
enabled: true
+ source-poll-interval-ms: 100 # a shorter cycle so the "did not trigger" tests wait less
autoscaling:
enabled: true
applicationautoscaling: