From 2b93d4de0600b5f65f2acf1415934e9e730c33c4 Mon Sep 17 00:00:00 2001 From: Todd Anderson Date: Mon, 25 Mar 2024 14:29:24 -0500 Subject: [PATCH] Review comments related to unit test and ClientContextImpl volatility. --- .../java/com/launchdarkly/sdk/android/LDClient.java | 2 +- .../sdk/android/ContextDataManagerListenersTest.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDClient.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDClient.java index e11c7408..d07bdabe 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDClient.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDClient.java @@ -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 instances = null; - private static ClientContextImpl clientContextImpl; + private volatile ClientContextImpl clientContextImpl; private static IContextModifier autoEnvContextModifier; private static IContextModifier anonymousKeyContextModifier; diff --git a/launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/ContextDataManagerListenersTest.java b/launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/ContextDataManagerListenersTest.java index b8928681..5b176507 100644 --- a/launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/ContextDataManagerListenersTest.java +++ b/launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/ContextDataManagerListenersTest.java @@ -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);