-
Notifications
You must be signed in to change notification settings - Fork 74
perf(flagd): run all 3 e2e resolver modes concurrently via @TestFactory #1753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
aepfli
wants to merge
9
commits into
feat/speed-up-flagd-e2e-tests
Choose a base branch
from
feat/parameterized-e2e-suite
base: feat/speed-up-flagd-e2e-tests
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cca921a
perf(flagd): parallelize e2e scenarios via container pool
aepfli 41f983c
perf(flagd): enable parallel Cucumber execution with resource locks
aepfli 551159a
ci: point test-harness submodule to feat/add-env-var-tag branch
aepfli f9e647c
chore(flagd): reduce e2e test output verbosity
aepfli 32940e9
perf(flagd): scale e2e parallelism dynamically with available CPUs
aepfli 6b334f5
fix(flagd): cap container pool size to avoid Docker overload
aepfli 1dcb453
perf(flagd): run e2e resolver modes in parallel via @TestFactory
aepfli 9cefe73
test(flagd): exclude @targetURI from inProcess parallel run
aepfli b6a61c2
fix(flagd): address Gemini code review feedback
aepfli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...iders/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/ContainerEntry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package dev.openfeature.contrib.providers.flagd.e2e; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.time.Duration; | ||
| import org.apache.commons.io.FileUtils; | ||
| import org.apache.commons.lang3.RandomStringUtils; | ||
| import org.testcontainers.containers.ComposeContainer; | ||
| import org.testcontainers.containers.wait.strategy.Wait; | ||
|
|
||
| /** A single pre-warmed Docker Compose stack (flagd + envoy) and its associated temp directory. */ | ||
| public class ContainerEntry { | ||
|
|
||
| public static final int FORBIDDEN_PORT = 9212; | ||
|
|
||
| public final ComposeContainer container; | ||
| public final Path tempDir; | ||
|
|
||
| private ContainerEntry(ComposeContainer container, Path tempDir) { | ||
| this.container = container; | ||
| this.tempDir = tempDir; | ||
| } | ||
|
|
||
| /** Start a new container entry. Blocks until all services are ready. */ | ||
| public static ContainerEntry start() throws IOException { | ||
| Path tempDir = Files.createDirectories( | ||
| Paths.get("tmp/" + RandomStringUtils.randomAlphanumeric(8).toLowerCase() + "/")); | ||
|
|
||
| ComposeContainer container = new ComposeContainer(new File("test-harness/docker-compose.yaml")) | ||
| .withEnv("FLAGS_DIR", tempDir.toAbsolutePath().toString()) | ||
| .withExposedService("flagd", 8013, Wait.forListeningPort()) | ||
| .withExposedService("flagd", 8015, Wait.forListeningPort()) | ||
| .withExposedService("flagd", 8080, Wait.forListeningPort()) | ||
| .withExposedService("envoy", 9211, Wait.forListeningPort()) | ||
| .withExposedService("envoy", FORBIDDEN_PORT, Wait.forListeningPort()) | ||
| .withStartupTimeout(Duration.ofSeconds(45)); | ||
| container.start(); | ||
|
|
||
| return new ContainerEntry(container, tempDir); | ||
| } | ||
|
|
||
| /** Stop the container and clean up the temp directory. */ | ||
| public void stop() throws IOException { | ||
| container.stop(); | ||
| FileUtils.deleteDirectory(tempDir.toFile()); | ||
| } | ||
| } |
129 changes: 129 additions & 0 deletions
129
providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/ContainerPool.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package dev.openfeature.contrib.providers.flagd.e2e; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.BlockingQueue; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.LinkedBlockingQueue; | ||
| import java.util.concurrent.Semaphore; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| /** | ||
| * A pool of pre-warmed {@link ContainerEntry} instances. | ||
| * | ||
| * <p>All containers are started in parallel on the first {@link #acquire()} call, paying the | ||
| * Docker Compose startup cost only once per JVM. Scenarios borrow a container via | ||
| * {@link #acquire()} and return it via {@link #release(ContainerEntry)} after teardown. | ||
| * | ||
| * <p>Cleanup is handled automatically via a JVM shutdown hook — no explicit lifecycle calls are | ||
| * needed from test classes. This means multiple test classes (e.g. several {@code @Suite} runners | ||
| * or {@code @TestFactory} methods) share the same pool across the entire JVM lifetime without | ||
| * redundant container startups. | ||
| * | ||
| * <p>Pool size is controlled by the system property {@code flagd.e2e.pool.size} | ||
| * (default: min(availableProcessors, 4)). | ||
| */ | ||
| @Slf4j | ||
| public class ContainerPool { | ||
|
|
||
| private static final int POOL_SIZE = Integer.getInteger( | ||
| "flagd.e2e.pool.size", Math.min(Runtime.getRuntime().availableProcessors(), 4)); | ||
|
|
||
| private static final BlockingQueue<ContainerEntry> pool = new LinkedBlockingQueue<>(); | ||
| private static final List<ContainerEntry> all = new ArrayList<>(); | ||
| private static final AtomicBoolean initialized = new AtomicBoolean(false); | ||
|
|
||
| /** | ||
| * JVM-wide semaphore that serializes disruptive container operations (stop/restart) across all | ||
| * parallel Cucumber engines. Only one scenario at a time may bring a container down, preventing | ||
| * cascading initialization timeouts in sibling scenarios that are waiting for a container slot. | ||
| */ | ||
| private static final Semaphore restartSlot = new Semaphore(1); | ||
|
|
||
| static { | ||
| Runtime.getRuntime().addShutdownHook(new Thread(ContainerPool::stopAll, "container-pool-shutdown")); | ||
| } | ||
|
|
||
| /** | ||
| * Borrow a container from the pool, blocking until one becomes available. | ||
| * Initializes the pool on the first call. The caller MUST call | ||
| * {@link #release(ContainerEntry)} when done. | ||
| */ | ||
| public static ContainerEntry acquire() throws Exception { | ||
| ensureInitialized(); | ||
| return pool.take(); | ||
| } | ||
|
|
||
| /** Return a container to the pool so the next scenario can use it. */ | ||
| public static void release(ContainerEntry entry) { | ||
| pool.add(entry); | ||
| } | ||
|
|
||
| /** | ||
| * Acquires the JVM-wide restart slot before stopping or restarting a container. | ||
| * Must be paired with {@link #releaseRestartSlot()} in the scenario {@code @After} hook. | ||
| */ | ||
| public static void acquireRestartSlot() throws InterruptedException { | ||
| log.debug("Acquiring restart slot..."); | ||
| restartSlot.acquire(); | ||
| log.debug("Restart slot acquired."); | ||
| } | ||
|
|
||
| /** Releases the JVM-wide restart slot acquired by {@link #acquireRestartSlot()}. */ | ||
| public static void releaseRestartSlot() { | ||
| restartSlot.release(); | ||
| log.debug("Restart slot released."); | ||
| } | ||
|
|
||
| private static synchronized void ensureInitialized() throws Exception { | ||
| if (!initialized.compareAndSet(false, true)) { | ||
| return; | ||
| } | ||
| log.info("Starting container pool of size {}...", POOL_SIZE); | ||
| ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE); | ||
| try { | ||
| List<Future<ContainerEntry>> futures = new ArrayList<>(); | ||
| for (int i = 0; i < POOL_SIZE; i++) { | ||
| futures.add(executor.submit(ContainerEntry::start)); | ||
| } | ||
| for (Future<ContainerEntry> future : futures) { | ||
| ContainerEntry entry = future.get(); | ||
| pool.add(entry); | ||
| all.add(entry); | ||
| } | ||
| } catch (Exception e) { | ||
| all.forEach(entry -> { | ||
| try { | ||
| entry.stop(); | ||
| } catch (IOException suppressed) { | ||
| e.addSuppressed(suppressed); | ||
| } | ||
| }); | ||
| pool.clear(); | ||
| all.clear(); | ||
| initialized.set(false); | ||
| throw e; | ||
| } finally { | ||
| executor.shutdown(); | ||
| } | ||
| log.info("Container pool ready ({} containers).", POOL_SIZE); | ||
| } | ||
|
|
||
| private static void stopAll() { | ||
| if (all.isEmpty()) return; | ||
| log.info("Shutdown hook — stopping all containers."); | ||
| all.forEach(entry -> { | ||
| try { | ||
| entry.stop(); | ||
| } catch (IOException e) { | ||
| log.warn("Error stopping container entry", e); | ||
| } | ||
| }); | ||
| pool.clear(); | ||
| all.clear(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...agd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/CucumberResultListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package dev.openfeature.contrib.providers.flagd.e2e; | ||
|
|
||
| import java.util.LinkedHashMap; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.junit.platform.engine.TestExecutionResult; | ||
| import org.junit.platform.engine.reporting.ReportEntry; | ||
| import org.junit.platform.launcher.TestExecutionListener; | ||
| import org.junit.platform.launcher.TestIdentifier; | ||
| import org.junit.platform.launcher.TestPlan; | ||
|
|
||
| /** | ||
| * Captures the full lifecycle of a JUnit Platform test execution, tracking start, finish, and skip | ||
| * events for every node in the test plan (both containers and tests). Results are later replayed as | ||
| * JUnit Jupiter {@link org.junit.jupiter.api.DynamicTest} instances to expose the Cucumber scenario | ||
| * tree in IDEs. | ||
| */ | ||
| @Slf4j | ||
| class CucumberResultListener implements TestExecutionListener { | ||
|
|
||
| private final Set<String> started = new LinkedHashSet<>(); | ||
| private final Map<String, TestExecutionResult> results = new LinkedHashMap<>(); | ||
| private final Map<String, String> skipped = new LinkedHashMap<>(); | ||
|
|
||
| @Override | ||
| public void testPlanExecutionStarted(TestPlan testPlan) { | ||
| log.debug("Cucumber execution started"); | ||
| } | ||
|
|
||
| @Override | ||
| public void testPlanExecutionFinished(TestPlan testPlan) { | ||
| log.debug( | ||
| "Cucumber execution finished — started={}, finished={}, skipped={}", | ||
| started.size(), | ||
| results.size(), | ||
| skipped.size()); | ||
| } | ||
|
|
||
| @Override | ||
| public void executionStarted(TestIdentifier id) { | ||
| log.debug(" START {}", id.getDisplayName()); | ||
| started.add(id.getUniqueId()); | ||
| } | ||
|
|
||
| @Override | ||
| public void executionFinished(TestIdentifier id, TestExecutionResult result) { | ||
| results.put(id.getUniqueId(), result); | ||
| if (result.getStatus() == TestExecutionResult.Status.FAILED) { | ||
| log.debug( | ||
| " FAIL {} — {}", | ||
| id.getDisplayName(), | ||
| result.getThrowable().map(Throwable::getMessage).orElse("(no message)")); | ||
| } else { | ||
| log.debug(" {} {}", result.getStatus(), id.getDisplayName()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void executionSkipped(TestIdentifier id, String reason) { | ||
| skipped.put(id.getUniqueId(), reason); | ||
| log.debug(" SKIP {} — {}", id.getDisplayName(), reason); | ||
| } | ||
|
|
||
| @Override | ||
| public void dynamicTestRegistered(TestIdentifier id) { | ||
| log.debug(" DYN {}", id.getDisplayName()); | ||
| } | ||
|
|
||
| @Override | ||
| public void reportingEntryPublished(TestIdentifier id, ReportEntry entry) { | ||
| log.debug(" REPORT {} — {}", id.getDisplayName(), entry); | ||
| } | ||
|
|
||
| /** Whether the node with the given unique ID had {@code executionStarted} called. */ | ||
| boolean wasStarted(String uniqueId) { | ||
| return started.contains(uniqueId); | ||
| } | ||
|
|
||
| /** Whether the node was skipped before starting. */ | ||
| boolean wasSkipped(String uniqueId) { | ||
| return skipped.containsKey(uniqueId); | ||
| } | ||
|
|
||
| /** The skip reason for a skipped node, or {@code null} if not skipped. */ | ||
| String getSkipReason(String uniqueId) { | ||
| return skipped.get(uniqueId); | ||
| } | ||
|
|
||
| /** Whether a finished result was recorded for the given node. */ | ||
| boolean hasResult(String uniqueId) { | ||
| return results.containsKey(uniqueId); | ||
| } | ||
|
|
||
| /** | ||
| * The recorded {@link TestExecutionResult}, or {@code null} if the node never finished. | ||
| * Use {@link #hasResult} to distinguish "finished with success" from "never finished". | ||
| */ | ||
| TestExecutionResult getResult(String uniqueId) { | ||
| return results.get(uniqueId); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.