-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add e2e test for reconnect (#596)
Signed-off-by: Todd Baert <[email protected]>
- Loading branch information
Showing
12 changed files
with
260 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
23 changes: 23 additions & 0 deletions
23
...a/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdInProcessReconnectCucumberTest.java
This file contains 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,23 @@ | ||
package dev.openfeature.contrib.providers.flagd.e2e; | ||
|
||
import org.junit.jupiter.api.Order; | ||
import org.junit.platform.suite.api.ConfigurationParameter; | ||
import org.junit.platform.suite.api.IncludeEngines; | ||
import org.junit.platform.suite.api.SelectClasspathResource; | ||
import org.junit.platform.suite.api.Suite; | ||
|
||
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME; | ||
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME; | ||
|
||
/** | ||
* Class for running the reconnection tests for the in-process provider | ||
*/ | ||
@Order(value = Integer.MAX_VALUE) | ||
@Suite | ||
@IncludeEngines("cucumber") | ||
@SelectClasspathResource("features/flagd-reconnect.feature") | ||
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty") | ||
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.reconnect.process,dev.openfeature.contrib.providers.flagd.e2e.reconnect.steps") | ||
public class RunFlagdInProcessReconnectCucumberTest { | ||
|
||
} |
This file contains 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
24 changes: 24 additions & 0 deletions
24
...st/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdRpcReconnectCucumberTest.java
This file contains 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,24 @@ | ||
package dev.openfeature.contrib.providers.flagd.e2e; | ||
|
||
import org.apache.logging.log4j.core.config.Order; | ||
import org.junit.platform.suite.api.ConfigurationParameter; | ||
import org.junit.platform.suite.api.IncludeEngines; | ||
import org.junit.platform.suite.api.SelectClasspathResource; | ||
import org.junit.platform.suite.api.Suite; | ||
|
||
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME; | ||
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME; | ||
|
||
/** | ||
* Class for running the reconnection tests for the RPC provider | ||
*/ | ||
@Order(value = Integer.MAX_VALUE) | ||
@Suite | ||
@IncludeEngines("cucumber") | ||
@SelectClasspathResource("features/flagd-reconnect.feature") | ||
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty") | ||
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.reconnect.rpc,dev.openfeature.contrib.providers.flagd.e2e.reconnect.steps") | ||
public class RunFlagdRpcReconnectCucumberTest { | ||
|
||
} | ||
|
29 changes: 29 additions & 0 deletions
29
...va/dev/openfeature/contrib/providers/flagd/e2e/reconnect/process/FlagdInProcessSetup.java
This file contains 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,29 @@ | ||
package dev.openfeature.contrib.providers.flagd.e2e.reconnect.process; | ||
|
||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.parallel.Isolated; | ||
|
||
import dev.openfeature.contrib.providers.flagd.Config; | ||
import dev.openfeature.contrib.providers.flagd.FlagdOptions; | ||
import dev.openfeature.contrib.providers.flagd.FlagdProvider; | ||
import dev.openfeature.contrib.providers.flagd.e2e.reconnect.steps.StepDefinitions; | ||
import dev.openfeature.sdk.FeatureProvider; | ||
import io.cucumber.java.BeforeAll; | ||
|
||
@Isolated() | ||
@Order(value = Integer.MAX_VALUE) | ||
public class FlagdInProcessSetup { | ||
|
||
private static FeatureProvider provider; | ||
|
||
@BeforeAll() | ||
public static void setup() throws InterruptedException { | ||
FlagdInProcessSetup.provider = new FlagdProvider(FlagdOptions.builder() | ||
.resolverType(Config.Evaluator.IN_PROCESS) | ||
.deadline(3000) | ||
.host("localhost") | ||
.port(9091) | ||
.build()); | ||
StepDefinitions.setProvider(provider); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...rc/test/java/dev/openfeature/contrib/providers/flagd/e2e/reconnect/rpc/FlagdRpcSetup.java
This file contains 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,31 @@ | ||
package dev.openfeature.contrib.providers.flagd.e2e.reconnect.rpc; | ||
|
||
import dev.openfeature.contrib.providers.flagd.resolver.grpc.cache.CacheType; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.parallel.Isolated; | ||
|
||
import dev.openfeature.contrib.providers.flagd.Config; | ||
import dev.openfeature.contrib.providers.flagd.FlagdOptions; | ||
import dev.openfeature.contrib.providers.flagd.FlagdProvider; | ||
import dev.openfeature.contrib.providers.flagd.e2e.reconnect.steps.StepDefinitions; | ||
import dev.openfeature.sdk.FeatureProvider; | ||
import io.cucumber.java.BeforeAll; | ||
|
||
@Isolated() | ||
@Order(value = Integer.MAX_VALUE) | ||
public class FlagdRpcSetup { | ||
|
||
private static FeatureProvider provider; | ||
|
||
@BeforeAll() | ||
public static void setup() { | ||
FlagdRpcSetup.provider = new FlagdProvider(FlagdOptions.builder() | ||
.resolverType(Config.Evaluator.RPC) | ||
.port(8014) | ||
// set a generous deadline, to prevent timeouts in actions | ||
.deadline(3000) | ||
.cacheType(CacheType.DISABLED.getValue()) | ||
.build()); | ||
StepDefinitions.setProvider(provider); | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...est/java/dev/openfeature/contrib/providers/flagd/e2e/reconnect/steps/StepDefinitions.java
This file contains 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,106 @@ | ||
package dev.openfeature.contrib.providers.flagd.e2e.reconnect.steps; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.time.Duration; | ||
import java.util.function.Consumer; | ||
|
||
import org.awaitility.Awaitility; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.parallel.Isolated; | ||
|
||
import dev.openfeature.sdk.Client; | ||
import dev.openfeature.sdk.EventDetails; | ||
import dev.openfeature.sdk.FeatureProvider; | ||
import dev.openfeature.sdk.OpenFeatureAPI; | ||
import io.cucumber.java.AfterAll; | ||
import io.cucumber.java.en.Given; | ||
import io.cucumber.java.en.Then; | ||
import io.cucumber.java.en.When; | ||
|
||
/** | ||
* Test suite for testing flagd provider reconnect functionality. | ||
* The associated container run a flagd instance which restarts every 5s. | ||
*/ | ||
@Isolated() | ||
@Order(value = Integer.MAX_VALUE) | ||
public class StepDefinitions { | ||
|
||
private static Client client; | ||
private static FeatureProvider provider; | ||
|
||
private int readyHandlerRunCount = 0; | ||
private int errorHandlerRunCount = 0; | ||
|
||
private Consumer<EventDetails> readyHandler = (EventDetails) -> { | ||
readyHandlerRunCount++; | ||
}; | ||
private Consumer<EventDetails> errorHandler = (EventDetails) -> { | ||
errorHandlerRunCount++; | ||
}; | ||
|
||
/** | ||
* Injects the client to use for this test. | ||
* Tests run one at a time, but just in case, a lock is used to make sure the | ||
* client is not updated mid-test. | ||
* | ||
* @param client client to inject into test. | ||
*/ | ||
public static void setProvider(FeatureProvider provider) { | ||
StepDefinitions.provider = provider; | ||
} | ||
|
||
public StepDefinitions() { | ||
StepDefinitions.client = OpenFeatureAPI.getInstance().getClient("unstable"); | ||
OpenFeatureAPI.getInstance().setProviderAndWait("unstable", provider); | ||
} | ||
|
||
@Given("a flagd provider is set") | ||
public static void setup() { | ||
// done in constructor | ||
} | ||
|
||
@AfterAll() | ||
public static void cleanUp() throws InterruptedException { | ||
StepDefinitions.provider.shutdown(); | ||
StepDefinitions.provider = null; | ||
StepDefinitions.client = null; | ||
} | ||
|
||
@When("a PROVIDER_READY handler and a PROVIDER_ERROR handler are added") | ||
public void a_provider_ready_handler_and_a_provider_error_handler_are_added() { | ||
client.onProviderReady(this.readyHandler); | ||
client.onProviderError(this.errorHandler); | ||
} | ||
|
||
@Then("the PROVIDER_READY handler must run when the provider connects") | ||
public void the_provider_ready_handler_must_run_when_the_provider_connects() { | ||
// no errors expected yet | ||
assertEquals(0, errorHandlerRunCount); | ||
// wait up to 15 seconds for a connect (PROVIDER_READY event) | ||
Awaitility.await().atMost(Duration.ofSeconds(15)) | ||
.until(() -> { | ||
return this.readyHandlerRunCount == 1; | ||
}); | ||
|
||
} | ||
|
||
@Then("the PROVIDER_ERROR handler must run when the provider's connection is lost") | ||
public void the_provider_error_handler_must_run_when_the_provider_s_connection_is_lost() { | ||
// wait up to 15 seconds for a disconnect (PROVIDER_ERROR event) | ||
Awaitility.await().atMost(Duration.ofSeconds(15)) | ||
.until(() -> { | ||
return this.errorHandlerRunCount > 0; | ||
}); | ||
} | ||
|
||
@Then("when the connection is reestablished the PROVIDER_READY handler must run again") | ||
public void when_the_connection_is_reestablished_the_provider_ready_handler_must_run_again() { | ||
// wait up to 15 seconds for a reconnect (PROVIDER_READY event) | ||
Awaitility.await().atMost(Duration.ofSeconds(15)) | ||
.until(() -> { | ||
return this.readyHandlerRunCount > 1; | ||
}); | ||
} | ||
} |
Oops, something went wrong.