Skip to content

Commit

Permalink
improve test and coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Schrottner <[email protected]>
  • Loading branch information
aepfli committed Feb 7, 2025
1 parent 057cf1b commit 2137928
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void prebuild() {
resolverType = fromValueProvider(System::getenv);
}

if (StringUtils.isEmpty(offlineFlagSourcePath)) {
if (StringUtils.isBlank(offlineFlagSourcePath)) {
offlineFlagSourcePath = fallBackToEnvOrDefault(Config.OFFLINE_SOURCE_PATH, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public GrpcResolver(
Evaluation.EventStreamRequest.getDefaultInstance(),
new EventStreamObserver(
(flags) -> {
if (cache != null) {
flags.forEach(cache::remove);
if (this.cache != null) {
flags.forEach(this.cache::remove);
}
onProviderEvent.accept(new FlagdProviderEvent(
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, flags));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps")
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")
@IncludeTags("file")
@ExcludeTags({"unixsocket", "targetURI", "reconnect", "customCert", "events"})
@ExcludeTags({"unixsocket", "targetURI", "reconnect", "customCert"})
@Testcontainers
public class RunFileTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.IncludeTags;
import org.junit.platform.suite.api.SelectDirectories;
import org.junit.platform.suite.api.SelectFile;
import org.junit.platform.suite.api.Suite;
import org.testcontainers.junit.jupiter.Testcontainers;

Expand All @@ -23,7 +24,7 @@
@IncludeEngines("cucumber")
@SelectDirectories("test-harness/gherkin")
// if you want to run just one feature file, use the following line instead of @SelectDirectories
// @SelectFile("test-harness/gherkin/rpc-caching.feature")
//@SelectFile("test-harness/gherkin/rpc-caching.feature")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps")
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import static io.restassured.RestAssured.when;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import dev.openfeature.contrib.providers.flagd.Config;
import dev.openfeature.contrib.providers.flagd.FlagdProvider;
import dev.openfeature.contrib.providers.flagd.e2e.FlagdContainer;
Expand All @@ -21,7 +19,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.parallel.Isolated;
Expand All @@ -47,7 +44,7 @@ public static void beforeAll() throws IOException {
sharedTempDir = Files.createDirectories(
Paths.get("tmp/" + RandomStringUtils.randomAlphanumeric(8).toLowerCase() + "/"));
container = new FlagdContainer()
.withFileSystemBind(sharedTempDir.toAbsolutePath().toString(), "/tmp", BindMode.READ_WRITE);
.withFileSystemBind(sharedTempDir.toAbsolutePath().toString(), "/flags", BindMode.READ_WRITE);
}

@AfterAll
Expand Down Expand Up @@ -78,15 +75,7 @@ public void setupProvider(String providerType) throws IOException, InterruptedEx
String flagdConfig = "default";
state.builder.deadline(1000).keepAlive(0).retryGracePeriod(2);
boolean wait = true;
File flags = new File("test-harness/flags");
ObjectMapper objectMapper = new ObjectMapper();
Object merged = new Object();
for (File listFile : Objects.requireNonNull(flags.listFiles())) {
ObjectReader updater = objectMapper.readerForUpdating(merged);
merged = updater.readValue(listFile, Object.class);
}
Path offlinePath = Files.createTempFile("flags", ".json");
objectMapper.writeValue(offlinePath.toFile(), merged);

switch (providerType) {
case "unavailable":
this.state.providerType = ProviderType.SOCKET;
Expand Down Expand Up @@ -123,7 +112,7 @@ public void setupProvider(String providerType) throws IOException, InterruptedEx

state.builder
.port(UNAVAILABLE_PORT)
.offlineFlagSourcePath(offlinePath.toAbsolutePath().toString());
.offlineFlagSourcePath(sharedTempDir.resolve("allFlags.json").toAbsolutePath().toString());
} else {
state.builder.port(container.getPort(State.resolverType));
}
Expand All @@ -134,7 +123,7 @@ public void setupProvider(String providerType) throws IOException, InterruptedEx
.statusCode(200);

// giving flagd a little time to start
Thread.sleep(100);
Thread.sleep(30);
FeatureProvider provider =
new FlagdProvider(state.builder.resolverType(State.resolverType).build());

Expand Down Expand Up @@ -163,10 +152,9 @@ public void the_connection_is_lost_for(int seconds) throws InterruptedException

@When("the flag was modified")
public void the_flag_was_modded() throws InterruptedException {

when().post("http://" + container.getLaunchpadUrl() + "/change").then().statusCode(200);

// we might be too fast in the execution
Thread.sleep(100);
Thread.sleep(1000);
}
}

0 comments on commit 2137928

Please sign in to comment.