mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(codepipeline): fall back when the source poll interval is not positive (#4361)
floci.services.codepipeline.source-poll-interval-ms reached scheduleWithFixedDelay unchecked. That call rejects a non-positive delay, and it happens from @PostConstruct, so setting the key to 0 or a negative value threw IllegalArgumentException while CodePipelineService was being constructed and left the service unavailable rather than merely mis-scheduled. resolveSourcePollInterval now keeps a positive value and otherwise warns and falls back to the 500ms default, matching resolveInterval in SwfTimeoutSweeper, which guards the same hazard for the same reason: a misconfigured interval is not worth failing every other service for. The new test drives 0, -1 and Long.MIN_VALUE through the startup path with a proxied EmulatorConfig, so it needs no Quarkus application of its own. Bypassing the guard turns it red with IllegalArgumentException. Also corrects the awaitSourcePollCycles javadoc added in #4236. It claimed the helper blocks until the poller has had that many chances to run, which a wall-clock sleep does not guarantee: the poller runs on a fixed delay and each pass takes time of its own, so completed cycles are a floor in practice. The reason the wait scales with the configured interval is unchanged.
This commit is contained in:
1 parent
3e6c7a3472
commit
5913812b53
3 files changed
+78
-6
No files matched your search
+15
-1
@@ -103,7 +103,21 @@ public class CodePipelineService {
|
||||
LambdaService lambdaService, S3Service s3Service,
|
||||
EmulatorConfig config) {
|
||||
this(storageFactory, mapper, codeBuildService, codeDeployService, lambdaService, s3Service,
|
||||
config.services().codepipeline().sourcePollIntervalMs());
|
||||
resolveSourcePollInterval(config.services().codepipeline().sourcePollIntervalMs()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A zero or negative interval would make {@code scheduleWithFixedDelay} throw from the startup
|
||||
* observer and stop the whole emulator becoming ready. A misconfigured value is not worth
|
||||
* failing every other service for, so it falls back with a warning.
|
||||
*/
|
||||
private static long resolveSourcePollInterval(long configured) {
|
||||
if (configured > 0) {
|
||||
return configured;
|
||||
}
|
||||
LOG.warnv("Ignoring CodePipeline source poll interval {0}ms: must be a positive number of "
|
||||
+ "milliseconds, falling back to {1}ms", configured, DEFAULT_SOURCE_POLL_INTERVAL_MS);
|
||||
return DEFAULT_SOURCE_POLL_INTERVAL_MS;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
+10
-5
@@ -40,11 +40,16 @@ class CodePipelineIntegrationTest {
|
||||
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.
|
||||
* Sleeps for {@code cycles} times the configured source poll interval. The assertions that
|
||||
* follow these waits check that no execution, or no additional execution, was started, and they
|
||||
* are only meaningful if the poller actually ran and declined, so the wait scales with the
|
||||
* interval instead of hard-coding milliseconds that stop covering enough cycles when the
|
||||
* interval changes.
|
||||
*
|
||||
* <p>This is wall clock, not a handshake with the scheduler. The poller runs on a fixed delay,
|
||||
* so its period is the interval plus however long a pass takes, and fewer than {@code cycles}
|
||||
* passes may complete within the sleep. Several cycles are requested to leave margin for that,
|
||||
* not to guarantee a number of completed passes.
|
||||
*/
|
||||
private void awaitSourcePollCycles(int cycles) throws InterruptedException {
|
||||
Thread.sleep(config.services().codepipeline().sourcePollIntervalMs() * cycles);
|
||||
|
||||
+53
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.codepipeline;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -16,6 +17,9 @@ import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Object;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -23,6 +27,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -48,6 +53,54 @@ class CodePipelineServiceTest {
|
||||
mock(LambdaService.class),
|
||||
mock(S3Service.class));
|
||||
|
||||
/**
|
||||
* The configured interval reaches {@code scheduleWithFixedDelay}, which rejects a non-positive
|
||||
* delay. That schedule happens in {@code @PostConstruct}, so an IllegalArgumentException there
|
||||
* would leave CodePipeline unavailable rather than merely mis-scheduled.
|
||||
*/
|
||||
@Test
|
||||
void nonPositiveConfiguredPollInterval_doesNotPreventStartup() {
|
||||
for (long interval : new long[] {0L, -1L, Long.MIN_VALUE}) {
|
||||
CodePipelineService configured = new CodePipelineService(
|
||||
new InMemoryStorageFactory(),
|
||||
mapper,
|
||||
mock(CodeBuildService.class),
|
||||
mock(CodeDeployService.class),
|
||||
mock(LambdaService.class),
|
||||
mock(S3Service.class),
|
||||
configWithPollInterval(interval));
|
||||
try {
|
||||
assertDoesNotThrow(configured::resumePersistedExecutions,
|
||||
"interval " + interval + " must not abort startup");
|
||||
} finally {
|
||||
configured.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimal {@link EmulatorConfig} view: the constructor reads only the source poll interval, so
|
||||
* a proxy answering that avoids standing up the Quarkus config container.
|
||||
*/
|
||||
private static EmulatorConfig configWithPollInterval(long intervalMs) {
|
||||
Map<String, Object> answers = Map.of("sourcePollIntervalMs", intervalMs);
|
||||
|
||||
InvocationHandler handler = new InvocationHandler() {
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) {
|
||||
Object answer = answers.get(method.getName());
|
||||
if (answer != null) {
|
||||
return answer;
|
||||
}
|
||||
// services() and codepipeline() return further config views; proxy those too.
|
||||
return Proxy.newProxyInstance(method.getReturnType().getClassLoader(),
|
||||
new Class<?>[] {method.getReturnType()}, this);
|
||||
}
|
||||
};
|
||||
return (EmulatorConfig) Proxy.newProxyInstance(EmulatorConfig.class.getClassLoader(),
|
||||
new Class<?>[] {EmulatorConfig.class}, handler);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPipelineTreatsMissingStoredVersionAsVersionOne() throws Exception {
|
||||
CapturingStorageFactory storageFactory = new CapturingStorageFactory();
|
||||
|
||||
Reference in new issue
Block a user