From b9c31b15e49d4a669dfc2e7a45e304fe41c05cba Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Tue, 12 Sep 2023 18:06:05 -0300 Subject: [PATCH] Better comments --- .../integration/sets/FlagSetsPollingTest.java | 40 +++++++------------ .../sets/FlagSetsStreamingTest.java | 12 +++++- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/androidTest/java/tests/integration/sets/FlagSetsPollingTest.java b/src/androidTest/java/tests/integration/sets/FlagSetsPollingTest.java index dfc0a8b98..1458a4016 100644 --- a/src/androidTest/java/tests/integration/sets/FlagSetsPollingTest.java +++ b/src/androidTest/java/tests/integration/sets/FlagSetsPollingTest.java @@ -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(); @@ -109,21 +103,11 @@ 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(); @@ -131,6 +115,8 @@ public void featureFlagSetsAreIgnoredWhenSetsAreNotConfigured() throws IOExcepti 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(); @@ -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 thirdEntities = mRoomDb.splitDao().getAll(); diff --git a/src/androidTest/java/tests/integration/sets/FlagSetsStreamingTest.java b/src/androidTest/java/tests/integration/sets/FlagSetsStreamingTest.java index e4e60f0c3..d61a46e06 100644 --- a/src/androidTest/java/tests/integration/sets/FlagSetsStreamingTest.java +++ b/src/androidTest/java/tests/integration/sets/FlagSetsStreamingTest.java @@ -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); @@ -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); @@ -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); @@ -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); @@ -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"));