Skip to content

Commit

Permalink
Review comments related to unit test and ClientContextImpl volatility.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanderson-ld committed Mar 25, 2024
1 parent 4150e05 commit 2b93d4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class LDClient implements LDClientInterface, Closeable {
// A map of each LDClient (one per environment), or null if `init` hasn't been called yet.
// Will only be set once, during initialization, and the map is considered immutable.
static volatile Map<String, LDClient> instances = null;
private static ClientContextImpl clientContextImpl;
private volatile ClientContextImpl clientContextImpl;
private static IContextModifier autoEnvContextModifier;
private static IContextModifier anonymousKeyContextModifier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@ public void listenerIsNotCalledAfterUnregistering() throws InterruptedException
AwaitableFlagListener allFlagsListener = new AwaitableFlagListener();

manager.registerListener(flag.getKey(), listener);
manager.unregisterListener(flag.getKey(), listener);
manager.registerAllFlagsListener(allFlagsListener);
manager.unregisterAllFlagsListener(allFlagsListener);

manager.upsert(LDContext.builder("aKey").build(), flag);
manager.upsert(INITIAL_CONTEXT, flag);
assertEquals(flag.getKey(), listener.expectUpdate(5, TimeUnit.SECONDS));
assertEquals(flag.getKey(), allFlagsListener.expectUpdate(5, TimeUnit.SECONDS));

manager.unregisterListener(flag.getKey(), listener);
manager.unregisterAllFlagsListener(allFlagsListener);

manager.upsert(INITIAL_CONTEXT, flag);
// Unfortunately we are testing that an asynchronous method is *not* called, we just have to
// wait a bit to be sure.
listener.expectNoUpdates(100, TimeUnit.MILLISECONDS);
Expand Down

0 comments on commit 2b93d4d

Please sign in to comment.