Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> events = new LinkedList<>();
public ConcurrentLinkedQueue<Event> events = new ConcurrentLinkedQueue<>();
public Optional<Event> lastEvent;
public FlagSteps.Flag flag;
public MutableContext context = new MutableContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
import org.junit.jupiter.api.parallel.Isolated;
Expand All @@ -21,7 +21,7 @@ public class EventSteps extends AbstractSteps {

public EventSteps(State state) {
super(state);
state.events = new LinkedList<>();
state.events = new ConcurrentLinkedQueue<>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The events field in the State class is already initialized where it's declared. Re-initializing it here in the EventSteps constructor is redundant and can introduce flakiness. If other step definitions in the same scenario modify the events list before this constructor is called, those changes will be lost. It's best to remove this line and rely on the single initialization in the State class.

}

@Given("a {} event handler")
Expand Down