Skip to content

Commit fa75f25

Browse files
committed
fixup! feat: improve wait logic to a more elegant solution #1160
Signed-off-by: christian.lutnik <[email protected]>
1 parent 03de275 commit fa75f25

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/FlagdProvider.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private void onProviderEvent(FlagdProviderEvent flagdProviderEvent) {
239239
onReady();
240240
syncResources.setPreviousEvent(ProviderEvent.PROVIDER_READY);
241241
break;
242-
// intentional fall through, a not-ready change will trigger a ready.
242+
// intentional fall through, a not-ready change will trigger a ready.
243243
case PROVIDER_READY:
244244
onReady();
245245
syncResources.setPreviousEvent(ProviderEvent.PROVIDER_READY);
@@ -256,6 +256,8 @@ private void onProviderEvent(FlagdProviderEvent flagdProviderEvent) {
256256
log.info("Unknown event {}", flagdProviderEvent.getEvent());
257257
}
258258
}
259+
260+
log.info("give up lock on sync");
259261
}
260262

261263
private void onConfigurationChanged(FlagdProviderEvent flagdProviderEvent) {
@@ -272,12 +274,19 @@ private void onReady() {
272274
if (syncResources.initialize()) {
273275
log.info("initialized FlagdProvider");
274276
}
277+
log.info("on ready before error cancel");
275278
if (errorTask != null && !errorTask.isCancelled()) {
276279
errorTask.cancel(false);
277280
log.debug("Reconnection task cancelled as connection became READY.");
278281
}
279-
this.emitProviderReady(
280-
ProviderEventDetails.builder().message("connected to flagd").build());
282+
log.info("on ready post error cancel");
283+
284+
// todo run in external thread to prevent deadlock
285+
//new Thread(() -> {
286+
this.emitProviderReady(
287+
ProviderEventDetails.builder().message("connected to flagd").build());
288+
//}).start();
289+
281290
log.info("post onready");
282291
}
283292

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/FlagdProviderSyncResources.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public synchronized boolean initialize() {
4646
}
4747
this.initialized = true;
4848
this.notifyAll();
49-
log.info("notified all");
49+
log.info("notified all " + this.toString());
50+
5051
return true;
5152
}
5253

@@ -65,7 +66,7 @@ public synchronized boolean initialize() {
6566
* this object
6667
*/
6768
public void waitForInitialization(long deadline) {
68-
log.info("wait for init");
69+
log.info("wait for init " + this);
6970
long start = System.currentTimeMillis();
7071
long end = start + deadline;
7172
while (!initialized && !isShutDown) {
@@ -84,12 +85,14 @@ public void waitForInitialization(long deadline) {
8485
if (isShutDown) {
8586
break;
8687
}
88+
log.info("waiting for " + remaining + " at " + System.currentTimeMillis());
8789
try {
8890
this.wait(remaining);
8991
} catch (InterruptedException e) {
9092
// try again. Leave the continue to make PMD happy
9193
continue;
9294
}
95+
log.info("waiting ended at " + System.currentTimeMillis());
9396
}
9497
}
9598
if (isShutDown) {

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunConfigCucumberTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.junit.jupiter.api.Order;
77
import org.junit.platform.suite.api.ConfigurationParameter;
88
import org.junit.platform.suite.api.IncludeEngines;
9-
import org.junit.platform.suite.api.SelectFile;
9+
import org.junit.platform.suite.api.SelectDirectories;
1010
import org.junit.platform.suite.api.Suite;
1111

1212
/**
@@ -16,7 +16,8 @@
1616
@Order(value = Integer.MAX_VALUE)
1717
@Suite
1818
@IncludeEngines("cucumber")
19-
@SelectFile("test-harness/gherkin/config.feature")
19+
//@SelectFile("test-harness/gherkin/config.feature")
20+
@SelectDirectories("test-harness/gherkin")
2021
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
2122
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps")
2223
public class RunConfigCucumberTest {}

0 commit comments

Comments
 (0)