Skip to content

Commit 958bfd5

Browse files
committed
flaky tests attempt, changing it to stop flagd all the time, without stopping the container
Signed-off-by: Simon Schrottner <[email protected]>
1 parent 7fb193e commit 958bfd5

File tree

4 files changed

+16
-36
lines changed

4 files changed

+16
-36
lines changed

providers/flagd/spec

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/common/ChannelMonitor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ public static void monitorChannelState(
4747
log.debug("onConnectionLost is null");
4848
}
4949
}
50-
// Re-register the state monitor to watch for the next state transition.
51-
monitorChannelState(currentState, channel, onConnectionReady, onConnectionLost);
50+
if (currentState != ConnectivityState.SHUTDOWN) {
51+
// Re-register the state monitor to watch for the next state transition.
52+
monitorChannelState(currentState, channel, onConnectionReady, onConnectionLost);
53+
}
5254
});
5355
}
5456

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/EventSteps.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public EventSteps(State state) {
2525
@Given("a {} event handler")
2626
public void a_stale_event_handler(String eventType) {
2727
state.client.on(mapEventType(eventType), eventDetails -> {
28-
log.info("event tracked for {} at {} ms ", eventType, System.currentTimeMillis()%100_000);
28+
log.info("event tracked for {} at {} ms ", eventType, System.currentTimeMillis() % 100_000);
2929
state.events.add(new Event(eventType, eventDetails));
3030
});
3131
}
@@ -58,9 +58,8 @@ public void eventHandlerShouldBeExecuted(String eventType) {
5858
@Then("the {} event handler should have been executed within {int}ms")
5959
public void eventHandlerShouldBeExecutedWithin(String eventType, int ms) {
6060
log.info("waiting for eventtype: {}", eventType);
61-
await().atMost(ms, MILLISECONDS)
62-
.pollInterval(10, MILLISECONDS)
63-
.until(() -> state.events.stream().anyMatch(event -> event.type.equals(eventType)));
61+
await().atMost(ms, MILLISECONDS).pollInterval(10, MILLISECONDS).until(() -> state.events.stream()
62+
.anyMatch(event -> event.type.equals(eventType)));
6463
state.lastEvent = state.events.stream()
6564
.filter(event -> event.type.equals(eventType))
6665
.findFirst();

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/ProviderSteps.java

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import lombok.extern.slf4j.Slf4j;
2626
import org.apache.commons.lang3.RandomStringUtils;
2727
import org.junit.jupiter.api.parallel.Isolated;
28-
import org.junit.platform.suite.api.BeforeSuite;
2928
import org.testcontainers.containers.BindMode;
3029
import org.testcontainers.shaded.org.apache.commons.io.FileUtils;
3130

@@ -42,7 +41,6 @@ public ProviderSteps(State state) {
4241
super(state);
4342
}
4443

45-
/*
4644
@BeforeAll
4745
public static void beforeAll() throws IOException {
4846
State.resolverType = Config.Resolver.RPC;
@@ -68,31 +66,9 @@ public void before() throws IOException {
6866
@After
6967
public void tearDown() {
7068
OpenFeatureAPI.getInstance().shutdown();
71-
}
72-
*/
73-
74-
@BeforeAll
75-
public static void beforeAll() {
76-
State.resolverType = Config.Resolver.RPC;
77-
}
78-
79-
@Before
80-
public void before() throws IOException {
81-
state.events.clear();
82-
sharedTempDir = Files.createDirectories(
83-
Paths.get("tmp/" + RandomStringUtils.randomAlphanumeric(8).toLowerCase() + "/"));
84-
container = new FlagdContainer()
85-
.withFileSystemBind(sharedTempDir.toAbsolutePath().toString(), "/tmp", BindMode.READ_WRITE);
86-
if (!container.isRunning()) {
87-
container.start();
88-
}
89-
}
90-
91-
@After
92-
public void tearDown() throws IOException {
93-
OpenFeatureAPI.getInstance().shutdown();
94-
container.stop();
95-
FileUtils.deleteDirectory(sharedTempDir.toFile());
69+
when().post("http://" + container.getLaunchpadUrl() + "/stop")
70+
.then()
71+
.statusCode(200);
9672
}
9773

9874
@Given("a {} flagd provider")
@@ -169,8 +145,11 @@ public void setupProvider(String providerType) throws IOException, InterruptedEx
169145

170146
@When("the connection is lost for {int}s")
171147
public void the_connection_is_lost_for(int seconds) throws InterruptedException {
172-
log.info("Timeout and wait for {} seconds starting at {} ms, should resume at {} ms", seconds,
173-
System.currentTimeMillis() % 100_000, System.currentTimeMillis() % 100_000 + seconds * 1000L);
148+
log.info(
149+
"Timeout and wait for {} seconds starting at {} ms, should resume at {} ms",
150+
seconds,
151+
System.currentTimeMillis() % 100_000,
152+
System.currentTimeMillis() % 100_000 + seconds * 1000L);
174153

175154
when().post("http://" + container.getLaunchpadUrl() + "/restart?seconds={seconds}", seconds)
176155
.then()

0 commit comments

Comments
 (0)