Skip to content

Commit

Permalink
Better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Sep 12, 2023
1 parent 14b3116 commit b9c31b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,25 @@ public void setUp() throws Exception {

@Test
public void featureFlagIsUpdatedAccordingToSetsWhenTheyAreConfigured() throws IOException, InterruptedException {
/*
This test creates a factory with 2 configured sets.
The first split change will have 2 splits (workm and workm_set_3), one that belongs to set_1 and set_2 and one that belongs to set_3;
-> it should be added to storage
The second change will have 1 split (workm) that belongs to set_1 only.
-> it should remain in storage and be updated
The third change will have 1 split (workm) that belongs to set_3 only.
-> it should be removed from storage
*/

// 1. Initialize a factory with polling and sets set_1 & set_2 configured.
createFactory(mContext, mRoomDb, false, "set_1", "set_2");

// 2. Receive split change with 1 split belonging to set_1 & set_2 and one belonging to set_3
// -> only one feature flag should be added
boolean awaitFirst = firstChangeLatch.await(5, TimeUnit.SECONDS);
Thread.sleep(200);
int firstSize = mRoomDb.splitDao().getAll().size();
boolean firstSetsCorrect = mRoomDb.splitDao().getAll().get(0).getBody().contains("[\"set_1\",\"set_2\"]");

// 3. Receive split change with 1 split belonging to set_1 only
// -> the feature flag should be updated
boolean awaitSecond = secondChangeLatch.await(5, TimeUnit.SECONDS);
Thread.sleep(200);
int secondSize = mRoomDb.splitDao().getAll().size();
boolean secondSetsCorrect = mRoomDb.splitDao().getAll().get(0).getBody().contains("[\"set_1\"]");

// 4. Receive split change with 1 split belonging to set_3 only
// -> the feature flag should be removed
boolean awaitThird = thirdChangeLatch.await(5, TimeUnit.SECONDS);
Thread.sleep(200);
int thirdSize = mRoomDb.splitDao().getAll().size();
Expand All @@ -109,28 +103,20 @@ public void featureFlagIsUpdatedAccordingToSetsWhenTheyAreConfigured() throws IO

@Test
public void featureFlagSetsAreIgnoredWhenSetsAreNotConfigured() throws IOException, InterruptedException {
/*
This test creates a factory with no sets configured.
The first split change will have 2 splits (workm and workm_set_3), one that belongs to set_1 and set_2 and one that belongs to set_3;
-> both should be added to storage.
The second change will have 1 split (workm) that belongs to set_1 only.
-> that split should be updated.
The third change will have 1 split (workm) that belongs to set_3 only.
-> that split should be updated.
*/

// 1. Initialize a factory with polling and sets set_1 & set_2 configured.
createFactory(mContext, mRoomDb, false);

// 2. Receive split change with 1 split belonging to set_1 & set_2 and one belonging to set_3
// -> only one feature flag should be added
boolean awaitFirst = firstChangeLatch.await(5, TimeUnit.SECONDS);
Thread.sleep(500);
int firstSize = mRoomDb.splitDao().getAll().size();
List<SplitEntity> firstEntities = mRoomDb.splitDao().getAll();
boolean firstSetsCorrect = firstEntities.get(0).getBody().contains("[\"set_1\",\"set_2\"]") &&
firstEntities.get(1).getBody().contains("[\"set_3\"]");

// 3. Receive split change with 1 split belonging to set_1 only
// -> the feature flag should be updated
boolean awaitSecond = secondChangeLatch.await(5, TimeUnit.SECONDS);
Thread.sleep(500);
int secondSize = mRoomDb.splitDao().getAll().size();
Expand All @@ -145,6 +131,8 @@ public void featureFlagSetsAreIgnoredWhenSetsAreNotConfigured() throws IOExcepti
Logger.w("body0: " + body0);
Logger.w("body1: " + body1);

// 4. Receive split change with 1 split belonging to set_3 only
// -> the feature flag should be removed
boolean awaitThird = thirdChangeLatch.await(5, TimeUnit.SECONDS);
Thread.sleep(500);
List<SplitEntity> thirdEntities = mRoomDb.splitDao().getAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void sdkWithoutSetsConfiguredDoesNotExcludeUpdates() throws IOException,
readyClient.on(SplitEvent.SDK_UPDATE, TestingHelper.testTask(updateLatch));

// 2. Receive notification with new feature flag with no sets.
// 3. Assert that the update is processed and the split is stored.
pushToStreaming(mStreamingData, noSetsSplitChange);
boolean updateAwait = updateLatch.await(5, TimeUnit.SECONDS);

Expand All @@ -93,12 +94,15 @@ public void sdkWithSetsConfiguredDeletedDueToEmptySets() throws IOException, Int
SplitClient readyClient = getReadyClient(mContext, mRoomDb, streamingData, "set_1", "set_2");

// 1. Receive a SPLIT_UPDATE with "sets":["set_1", "set_2"]
// -> flag is added to the storage
boolean firstChange = processUpdate(readyClient, streamingData, splitChange2, "\"sets\":[\"set_1\",\"set_2\"]", "\"name\":\"workm\"");

// 2. Receive a SPLIT_UPDATE with "sets":["set_1"]
// -> flag is updated in storage
boolean secondChange = processUpdate(readyClient, streamingData, splitChange3, "\"sets\":[\"set_1\"]", "\"name\":\"workm\"");

// 3. Receive a SPLIT_UPDATE with "sets":[]
// -> flag is removed from storage
boolean thirdChange = processUpdate(readyClient, streamingData, splitChange4None);

assertTrue(firstChange);
Expand All @@ -112,15 +116,19 @@ public void sdkWithSetsConfiguredDeletedDueToNonMatchingSets() throws IOExceptio
SplitClient readyClient = getReadyClient(mContext, mRoomDb, streamingData, "set_1", "set_2");

// 1. Receive a SPLIT_UPDATE with "sets":["set_1", "set_2"]
// -> workm is added to the storage
boolean firstChange = processUpdate(readyClient, streamingData, splitChange2, "\"sets\":[\"set_1\",\"set_2\"]", "\"name\":\"workm\"");

// 2. Receive a SPLIT_UPDATE with "sets":["set_1"]
// -> workm sets are updated to set_1 only
boolean secondChange = processUpdate(readyClient, streamingData, splitChange3, "\"sets\":[\"set_1\"]", "\"name\":\"workm\"");

// 3. Receive a SPLIT_UPDATE with "sets":["set_3"]
// -> workm is removed from the storage
boolean thirdChange = processUpdate(readyClient, streamingData, splitChange4);

// 4. Receive a SPLIT_UPDATE with "sets":["set_3", "set_4"]
// -> workm is not added to the storage
boolean fourthChange = processUpdate(readyClient, streamingData, splitChange5);

assertTrue(firstChange);
Expand All @@ -137,6 +145,7 @@ public void sdkWithSetsReceivesSplitKill() throws IOException, InterruptedExcept
SplitClient readyClient = getReadyClient(mContext, mRoomDb, streamingData, "set_1", "set_2");

// 2. Receive a SPLIT_UPDATE with "sets":["set_1", "set_2"]
// -> flag is added to the storage
CountDownLatch firstUpdate = new CountDownLatch(1);
readyClient.on(SplitEvent.SDK_UPDATE, TestingHelper.testTask(firstUpdate));
pushToStreaming(streamingData, splitChange2);
Expand All @@ -146,7 +155,8 @@ public void sdkWithSetsReceivesSplitKill() throws IOException, InterruptedExcept
entities.get(0).getBody().contains("\"killed\":false") &&
entities.get(0).getBody().contains("\"name\":\"workm\"");

// 3. Receive a SPLIT_KILL for workm
// 3. Receive a SPLIT_KILL for flag
// -> flag is updated in storage
CountDownLatch secondUpdate = new CountDownLatch(1);
readyClient.on(SplitEvent.SDK_UPDATE, TestingHelper.testTask(secondUpdate));
pushToStreaming(streamingData, IntegrationHelper.splitKill("5", "workm"));
Expand Down

0 comments on commit b9c31b1

Please sign in to comment.