Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Dec 2, 2024
1 parent fb3d56f commit ff03a85
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void testPersistentAttributes2() throws InterruptedException {
// 3. Perform clear and verify there are no attributes on DB
client.clearAttributes();

countDownLatch.await(1, TimeUnit.SECONDS);
countDownLatch.await(7, TimeUnit.SECONDS);

Assert.assertNull(mRoomDb.attributesDao().getByUserKey(userKey));
}
Expand Down Expand Up @@ -153,7 +153,7 @@ public void testPersistentAttributesWithMultiClient2() throws InterruptedExcepti

// 2. Clear second client's attributes and check DB entry has been cleared
client2.clearAttributes();
countDownLatch.await(1, TimeUnit.SECONDS); // waiting since DB operations are async
countDownLatch.await(7, TimeUnit.SECONDS); // waiting since DB operations are async
Assert.assertNull(mRoomDb.attributesDao().getByUserKey("new_key"));

// 3. Verify evaluation with first client uses attribute
Expand All @@ -162,7 +162,7 @@ public void testPersistentAttributesWithMultiClient2() throws InterruptedExcepti
// 4. Perform clear and verify there are no attributes on DB
client.clearAttributes();

countDownLatch.await(1, TimeUnit.SECONDS);
countDownLatch.await(7, TimeUnit.SECONDS);

Assert.assertNull(mRoomDb.attributesDao().getByUserKey(matchingKey));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void onPostExecutionView(SplitClient client) {
}
});

assertTrue(latch.await(2, TimeUnit.SECONDS));
assertTrue(latch.await(5, TimeUnit.SECONDS));
mLifecycleManager.simulateOnPause();
Thread.sleep(200);
mLifecycleManager.simulateOnResume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public void setUp() throws IOException, InterruptedException {
public void unboundedLargeSegmentsUpdateTriggersSdkUpdate() throws IOException, InterruptedException {
TestSetup testSetup = getTestSetup();

boolean mySegmentsAwait = mLatches.get(MY_SEGMENTS).await(10, TimeUnit.SECONDS);
boolean splitsAwait = mLatches.get(SPLIT_CHANGES).await(10, TimeUnit.SECONDS);
boolean mySegmentsAwait = mLatches.get(MY_SEGMENTS).await(15, TimeUnit.SECONDS);
boolean splitsAwait = mLatches.get(SPLIT_CHANGES).await(15, TimeUnit.SECONDS);
String initialSegmentList = testSetup.database.myLargeSegmentDao().getByUserKey(IntegrationHelper.dummyUserKey().matchingKey()).getSegmentList();
mRandomizeMyLargeSegments.set(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public void onPostExecutionView(SplitClient client) {
}
});
insertSplitsIntoDb();
readyLatch.await(10, TimeUnit.SECONDS);
readyLatch2.await(10, TimeUnit.SECONDS);
readyLatch.await(15, TimeUnit.SECONDS);
readyLatch2.await(15, TimeUnit.SECONDS);

assertEquals(1, readyCount.get());
assertEquals(1, readyCount2.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import helper.TestableSplitConfigBuilder;
import io.split.android.client.SplitClientConfig;
import io.split.android.client.storage.db.StorageFactory;
import io.split.android.client.telemetry.model.streaming.OccupancyPriStreamingEvent;
import io.split.android.client.telemetry.model.streaming.OccupancySecStreamingEvent;
import io.split.android.client.telemetry.model.streaming.StreamingEvent;
import io.split.android.client.telemetry.model.streaming.TokenRefreshStreamingEvent;
import io.split.android.client.telemetry.storage.TelemetryStorage;
import tests.integration.streaming.OccupancyBaseTest;

public class TelemetryOccupancyTest extends OccupancyBaseTest {
Expand All @@ -35,12 +35,19 @@ public class TelemetryOccupancyTest extends OccupancyBaseTest {

@Test
public void telemetryOccupancyPriStreamingEvent() throws InterruptedException, IOException {
new CountDownLatch(1);
getSplitFactory(mTelemetryEnabledConfig);

pushOccupancy(PRIMARY_CHANNEL, 1);
sleep(2000);

List<StreamingEvent> streamingEvents = mTelemetryStorage.popStreamingEvents();
long startTime = System.currentTimeMillis();
List<StreamingEvent> streamingEvents = new ArrayList<>();
streamingEvents = mTelemetryStorage.popStreamingEvents();
while (System.currentTimeMillis() - startTime < 5000 &&
!streamingEvents.stream().anyMatch(event -> event instanceof OccupancyPriStreamingEvent)) {
Thread.sleep(100);
streamingEvents = mTelemetryStorage.popStreamingEvents();
}
assertTrue(streamingEvents.stream().anyMatch(event -> event instanceof OccupancyPriStreamingEvent));
}

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/io/split/android/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,6 @@ public void run() {
mSyncManager,
mLifecycleManager);

// Initialize default client
client();
SplitParser mSplitParser = new SplitParser(mStorageContainer.getMySegmentsStorageContainer(), mStorageContainer.getMyLargeSegmentsStorageContainer());
mManager = new SplitManagerImpl(
mStorageContainer.getSplitsStorage(),
new SplitValidatorImpl(), mSplitParser);

if (config.shouldRecordTelemetry()) {
int activeFactoriesCount = mFactoryMonitor.count(mApiKey);
mStorageContainer.getTelemetryStorage().recordActiveFactories(activeFactoriesCount);
Expand All @@ -338,6 +331,14 @@ public void run() {

// Run initializer
new Thread(initializer).start();

// Initialize default client
client();
SplitParser mSplitParser = new SplitParser(mStorageContainer.getMySegmentsStorageContainer(), mStorageContainer.getMyLargeSegmentsStorageContainer());
mManager = new SplitManagerImpl(
mStorageContainer.getSplitsStorage(),
new SplitValidatorImpl(), mSplitParser);

}

private static String getFlagsSpec(@Nullable TestingConfig testingConfig) {
Expand Down

0 comments on commit ff03a85

Please sign in to comment.