Skip to content

Commit

Permalink
WIP test
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Dec 13, 2024
1 parent 02be21e commit a79d535
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/androidTest/java/helper/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ public static boolean removeDatabaseFile(String name) {
}

public static SplitRoomDatabase getTestDatabase(Context context) {
return Room.inMemoryDatabaseBuilder(context, SplitRoomDatabase.class)
SplitRoomDatabase database = Room.inMemoryDatabaseBuilder(context, SplitRoomDatabase.class)
.fallbackToDestructiveMigration()
.allowMainThreadQueries()
.build();

database.clearAllTables();
return database;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.split.android.client.events.SplitEvent;
import io.split.android.client.service.impressions.ImpressionsMode;
import io.split.android.client.utils.Json;
import io.split.android.client.utils.logger.Logger;
import io.split.android.client.utils.logger.SplitLogLevel;
import okhttp3.mockwebserver.Dispatcher;
import okhttp3.mockwebserver.MockResponse;
Expand All @@ -52,13 +53,21 @@ public class ImpressionsToggleTest {
private final AtomicReference<String> mImpressionsBody = new AtomicReference<>(null);
private final AtomicReference<String> mUniqueKeysBody = new AtomicReference<>(null);

private CountDownLatch mCountLatch;
private CountDownLatch mImpressionsLatch;
private CountDownLatch mUniqueKeysLatch;

@Before
public void setUp() {
setupServer();
mRequestCountdownLatch = new CountDownLatch(1);
mCountBody.set(null);
mImpressionsBody.set(null);
mUniqueKeysBody.set(null);

mCountLatch = new CountDownLatch(1);
mImpressionsLatch = new CountDownLatch(1);
mUniqueKeysLatch = new CountDownLatch(1);
}

@Test
Expand All @@ -74,19 +83,22 @@ public void managerContainsProperty() throws InterruptedException {
}

@Test
public void test() throws InterruptedException {
public void testNoneMode() throws InterruptedException {
// 1. Initialize SDK in impressions NONE mode
SplitFactory splitFactory = getReadyFactory(ImpressionsMode.NONE);

// 2. Fetch splitChanges with both flags with trackImpressions true & false
SplitClient client = splitFactory.client();
client.getTreatment("tracked");
client.getTreatment("not_tracked");
String trackedTreatment = client.getTreatment("tracked");
String notTrackedTreatment = client.getTreatment("not_tracked");
Thread.sleep(200);

// 3. Verify all counts & mtks are tracked
client.flush();

Thread.sleep(2000);
mUniqueKeysLatch.await(5, TimeUnit.SECONDS);
mCountLatch.await(5, TimeUnit.SECONDS);

assertNotNull(mCountBody.get());
assertNotNull(mUniqueKeysBody.get());
assertNull(mImpressionsBody.get());
Expand Down Expand Up @@ -153,6 +165,7 @@ private void setupServer() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
mRequestCountdownLatch.await();
Logger.e("Path is: " + request.getPath());
if (request.getPath().contains("/" + IntegrationHelper.ServicePath.MEMBERSHIPS)) {
return new MockResponse().setResponseCode(200).setBody(emptyAllSegments());
} else if (request.getPath().contains("/" + IntegrationHelper.ServicePath.SPLIT_CHANGES)) {
Expand All @@ -164,12 +177,15 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
.setBody(IntegrationHelper.emptySplitChanges(1506703262916L, 1506703262916L));
}
} else if (request.getPath().contains("/" + IntegrationHelper.ServicePath.COUNT)) {
mCountLatch.countDown();
mCountBody.set(request.getBody().readUtf8());
return new MockResponse().setResponseCode(200);
} else if (request.getPath().contains("/" + IntegrationHelper.ServicePath.IMPRESSIONS)) {
mImpressionsLatch.countDown();
mImpressionsBody.set(request.getBody().readUtf8());
return new MockResponse().setResponseCode(200);
} else if (request.getPath().contains("/" + IntegrationHelper.ServicePath.UNIQUE_KEYS)) {
mUniqueKeysLatch.countDown();
mUniqueKeysBody.set(request.getBody().readUtf8());
return new MockResponse().setResponseCode(200);
} else {
Expand Down

0 comments on commit a79d535

Please sign in to comment.