Skip to content

Commit

Permalink
test(flagd): use newest testbed launchpad
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Schrottner <[email protected]>
  • Loading branch information
aepfli committed Jan 28, 2025
1 parent b4fe2f4 commit c84c0de
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[submodule "providers/flagd/test-harness"]
path = providers/flagd/test-harness
url = https://github.com/open-feature/test-harness.git
branch = v1.1.1
branch = v1.3.2
[submodule "providers/flagd/spec"]
path = providers/flagd/spec
url = https://github.com/open-feature/spec.git
11 changes: 5 additions & 6 deletions providers/flagd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>toxiproxy</artifactId>
<version>1.20.4</version>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
<!-- uncomment for logoutput during test runs -->

<dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.16</version>
Expand Down Expand Up @@ -254,7 +253,7 @@
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.25.5:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.68.2:exe:${os.detected.classifier}</pluginArtifact>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.69.1:exe:${os.detected.classifier}</pluginArtifact>
<protoSourceRoot>${project.basedir}/schemas/protobuf/</protoSourceRoot>
</configuration>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ void observeEventStream(final BlockingQueue<QueuePayload> writeTo, final AtomicB
metadataException = e;
}

log.info("stream");
while (!shutdown.get()) {
final GrpcResponseModel response = streamReceiver.take();
if (response.isComplete()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.openfeature.contrib.providers.flagd.e2e;
package dev.openfeature.contrib.providers.flagd;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
Expand All @@ -18,5 +18,5 @@
@IncludeEngines("cucumber")
@SelectFile("test-harness/gherkin/config.feature")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps")
public class RunConfigCucumberTest {}
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps.config")
public class ConfigCucumberTest {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dev.openfeature.contrib.providers.flagd.e2e;

import dev.openfeature.contrib.providers.flagd.Config;
import java.io.File;
import java.nio.file.Files;
import java.util.List;
import org.apache.logging.log4j.util.Strings;
import org.jetbrains.annotations.NotNull;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
Expand All @@ -28,16 +28,25 @@ public class FlagdContainer extends GenericContainer<FlagdContainer> {
private String feature;

public FlagdContainer() {
this("");
super(generateContainerName());
this.feature = feature;
this.addExposedPorts(8013, 8014, 8015, 8080);
}

public FlagdContainer(String feature) {
super(generateContainerName(feature));
this.withReuse(true);
this.feature = feature;
if (!"socket".equals(this.feature)) this.addExposedPorts(8013, 8014, 8015, 8016);
public int getPort(Config.Resolver resolver) {
switch (resolver) {
case RPC:
return getMappedPort(8013);
case IN_PROCESS:
return getMappedPort(8015);
default:
return 0;
}
}

public String getLaunchpadUrl() {
return this.getHost() + ":" + this.getMappedPort(8080);
}
/**
* @return a {@link org.testcontainers.containers.GenericContainer} instance of envoy container using
* flagd sync service as backend expose on port 9211
Expand All @@ -52,11 +61,8 @@ public static GenericContainer envoy() {
.withNetworkAliases("envoy");
}

public static @NotNull String generateContainerName(String feature) {
public static @NotNull String generateContainerName() {
String container = "ghcr.io/open-feature/flagd-testbed";
if (!Strings.isBlank(feature)) {
container += "-" + feature;
}
container += ":v" + version;
return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import dev.openfeature.contrib.providers.flagd.e2e.State;

abstract class AbstractSteps {
State state;
public abstract class AbstractSteps {
protected State state;

public AbstractSteps(State state) {
protected AbstractSteps(State state) {
this.state = state;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* This class modifies the internals of the environment variables map with reflection. Warning: If
* your {@link SecurityManager} does not allow modifications, it fails.
*/
class EnvironmentVariableUtils {
public class EnvironmentVariableUtils {

private EnvironmentVariableUtils() {
// private constructor to prevent instantiation of utility class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ public void a_stale_event_handler(String eventType) {

@When("a {} event was fired")
public void eventWasFired(String eventType) throws InterruptedException {
eventHandlerShouldBeExecutedWithin(eventType, 10000);
// we might be too fast in the execution
Thread.sleep(500);
eventHandlerShouldBeExecutedWithin(eventType, 8000);
}

@Then("the {} event handler should have been executed")
public void eventHandlerShouldBeExecuted(String eventType) {
eventHandlerShouldBeExecutedWithin(eventType, 30000);
eventHandlerShouldBeExecutedWithin(eventType, 10000);
}

@Then("the {} event handler should have been executed within {int}ms")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package dev.openfeature.contrib.providers.flagd.e2e.steps;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

import dev.openfeature.contrib.providers.flagd.e2e.State;
import dev.openfeature.sdk.FlagEvaluationDetails;
Expand Down Expand Up @@ -70,15 +68,9 @@ public void the_variant_should_be(String variant) {
}

@Then("the flag should be part of the event payload")
@Then("the flag was modified")
public void the_flag_was_modified() {
await().atMost(5000, MILLISECONDS).until(() -> state.events.stream()
.anyMatch(event -> event.type.equals("change")
&& event.details.getFlagsChanged().contains(state.flag.name)));
state.lastEvent = state.events.stream()
.filter(event -> event.type.equals("change")
&& event.details.getFlagsChanged().contains(state.flag.name))
.findFirst();
Event event = state.lastEvent.orElseThrow(AssertionError::new);
assertThat(event.details.getFlagsChanged()).contains(state.flag.name);
}

public class Flag {
Expand Down
Loading

0 comments on commit c84c0de

Please sign in to comment.