diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/FlagdProviderSyncResourcesTest.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/FlagdProviderSyncResourcesTest.java index 6258dad37..c7d9672ef 100644 --- a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/FlagdProviderSyncResourcesTest.java +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/FlagdProviderSyncResourcesTest.java @@ -79,14 +79,14 @@ void interruptingWaitingThread_isIgnored() throws InterruptedException { @Test void callingInitialize_wakesUpWaitingThread() throws InterruptedException { final AtomicBoolean isWaiting = new AtomicBoolean(); - final AtomicBoolean successfulTest = new AtomicBoolean(); + final AtomicLong waitTime = new AtomicLong(Long.MAX_VALUE); Thread waitingThread = new Thread(() -> { long start = System.currentTimeMillis(); isWaiting.set(true); flagdProviderSyncResources.waitForInitialization(10000); long end = System.currentTimeMillis(); long duration = end - start; - successfulTest.set(duration < MAX_TIME_TOLERANCE * 2); + waitTime.set(duration); }); waitingThread.start(); @@ -100,7 +100,11 @@ void callingInitialize_wakesUpWaitingThread() throws InterruptedException { waitingThread.join(); - Assertions.assertTrue(successfulTest.get()); + Assertions.assertTrue( + waitTime.get() < MAX_TIME_TOLERANCE * 2, + () -> "Wakeup should be almost instant, but took " + waitTime.get() + + " ms, which is more than the max of" + + (MAX_TIME_TOLERANCE * 2) + " ms"); } @Timeout(2) diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/State.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/State.java index 765e741ef..2d3a227a4 100644 --- a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/State.java +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/State.java @@ -9,15 +9,14 @@ import dev.openfeature.sdk.FeatureProvider; import dev.openfeature.sdk.FlagEvaluationDetails; import dev.openfeature.sdk.MutableContext; -import java.util.LinkedList; -import java.util.List; import java.util.Optional; +import java.util.concurrent.ConcurrentLinkedQueue; public class State { public ProviderType providerType; public Client client; public FeatureProvider provider; - public List events = new LinkedList<>(); + public ConcurrentLinkedQueue events = new ConcurrentLinkedQueue<>(); public Optional lastEvent; public FlagSteps.Flag flag; public MutableContext context = new MutableContext(); diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/EventSteps.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/EventSteps.java index c31517320..6dfc46c4e 100644 --- a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/EventSteps.java +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/EventSteps.java @@ -8,7 +8,7 @@ import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; -import java.util.LinkedList; +import java.util.concurrent.ConcurrentLinkedQueue; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; @@ -19,7 +19,7 @@ public class EventSteps extends AbstractSteps { public EventSteps(State state) { super(state); - state.events = new LinkedList<>(); + state.events = new ConcurrentLinkedQueue<>(); } @Given("a {} event handler")