Skip to content

Commit

Permalink
Emit SDK_READY_FROM_CACHE alongside SDK_READY, if not previously emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Dec 5, 2024
1 parent 55d3cbb commit 06ce624
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit 06ce624

Please sign in to comment.