diff --git a/src/androidTest/java/tests/integration/rollout/RolloutCacheManagerIntegrationTest.java b/src/androidTest/java/tests/integration/rollout/RolloutCacheManagerIntegrationTest.java index 8aa1b84a9..2efb3d933 100644 --- a/src/androidTest/java/tests/integration/rollout/RolloutCacheManagerIntegrationTest.java +++ b/src/androidTest/java/tests/integration/rollout/RolloutCacheManagerIntegrationTest.java @@ -142,6 +142,23 @@ public void repeatedInitWithClearOnInitSetToTrueDoesNotClearIfMinDaysHasNotElaps .getByName("rolloutCacheLastClearTimestamp").getLongValue()); } + @Test + public void sdkReadyFromCacheIsEmittedOnFreshInit() throws InterruptedException { + SplitFactory splitFactory = getSplitFactory(RolloutCacheConfiguration.builder().build()); + + CountDownLatch latch1 = new CountDownLatch(1); + CountDownLatch latch2 = new CountDownLatch(1); + splitFactory.client().on(SplitEvent.SDK_READY_FROM_CACHE, TestingHelper.testTask(latch1)); + splitFactory.client("two").on(SplitEvent.SDK_READY_FROM_CACHE, TestingHelper.testTask(latch2)); + mRequestCountdownLatch.countDown(); + + boolean await1 = latch1.await(10, TimeUnit.SECONDS); + boolean await2 = latch2.await(10, TimeUnit.SECONDS); + + assertTrue(await1); + assertTrue(await2); + } + private void test(long timestampDaysAgo, RolloutCacheConfiguration.Builder configBuilder) throws InterruptedException { // Preload DB with update timestamp of 1 day ago long oldTimestamp = timestampDaysAgo; diff --git a/src/main/java/io/split/android/client/events/SplitEventsManager.java b/src/main/java/io/split/android/client/events/SplitEventsManager.java index f6150157e..c443aa8e2 100644 --- a/src/main/java/io/split/android/client/events/SplitEventsManager.java +++ b/src/main/java/io/split/android/client/events/SplitEventsManager.java @@ -191,6 +191,9 @@ private void triggerSdkReadyIfNeeded() { if ((wasTriggered(SplitInternalEvent.MY_SEGMENTS_UPDATED) || wasTriggered(SplitInternalEvent.MY_SEGMENTS_FETCHED) || wasTriggered(SplitInternalEvent.MY_LARGE_SEGMENTS_UPDATED)) && (wasTriggered(SplitInternalEvent.SPLITS_UPDATED) || wasTriggered(SplitInternalEvent.SPLITS_FETCHED)) && !isTriggered(SplitEvent.SDK_READY)) { + if (!isTriggered(SplitEvent.SDK_READY_FROM_CACHE)) { + trigger(SplitEvent.SDK_READY_FROM_CACHE); + } trigger(SplitEvent.SDK_READY); } } diff --git a/src/test/java/io/split/android/client/events/EventsManagerTest.java b/src/test/java/io/split/android/client/events/EventsManagerTest.java index c9cca29c6..1f896825d 100644 --- a/src/test/java/io/split/android/client/events/EventsManagerTest.java +++ b/src/test/java/io/split/android/client/events/EventsManagerTest.java @@ -51,6 +51,7 @@ public void eventOnReady() { execute(shouldStop, intervalExecutionTime, maxExecutionTime, eventManager, SplitEvent.SDK_READY); assertTrue(eventManager.eventAlreadyTriggered(SplitEvent.SDK_READY)); + assertTrue(eventManager.eventAlreadyTriggered(SplitEvent.SDK_READY_FROM_CACHE)); assertFalse(eventManager.eventAlreadyTriggered(SplitEvent.SDK_READY_TIMED_OUT)); }