-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: change seed for variantutils to ensure fair distribution #220
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
40aa62d
fix: change seed for variantutils to ensure fair distribution
chriswk eea0042
chore: remove debug map
chriswk e0b244d
Security updates of dependencies
chriswk 1aac936
fix: start work on reproducing client-spec tests in java tests to sim…
chriswk 76786f6
fix: New seed for variant hashing
chriswk a8b8b05
nit: rename parentEvaluation to parent satisfied
chriswk 7ff4c7f
logback classic in 1.4 requires java 11
chriswk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 48 additions & 2 deletions
50
src/test/java/io/getunleash/strategy/StrategyUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,60 @@ | ||
package io.getunleash.strategy; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.getunleash.variant.VariantUtil; | ||
import java.util.UUID; | ||
import org.assertj.core.data.Offset; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class StrategyUtilsTest { | ||
|
||
@Test | ||
public void normalized_values_are_the_same_across_node_java_and_go_clients() { | ||
assertEquals(73, StrategyUtils.getNormalizedNumber("123", "gr1")); | ||
assertEquals(25, StrategyUtils.getNormalizedNumber("999", "groupX")); | ||
assertEquals(73, StrategyUtils.getNormalizedNumber("123", "gr1", 0)); | ||
assertEquals(25, StrategyUtils.getNormalizedNumber("999", "groupX", 0)); | ||
} | ||
|
||
@Test | ||
public void normalized_values_with_variant_seed_are_the_same_across_node_java() { | ||
assertThat( | ||
StrategyUtils.getNormalizedNumber( | ||
"123", "gr1", VariantUtil.VARIANT_NORMALIZATION_SEED)) | ||
.isEqualTo(96); | ||
assertThat( | ||
StrategyUtils.getNormalizedNumber( | ||
"999", "groupX", VariantUtil.VARIANT_NORMALIZATION_SEED)) | ||
.isEqualTo(60); | ||
} | ||
|
||
@Test | ||
public void | ||
selecting_ten_percent_of_users_and_then_finding_variants_should_still_have_variants_evenly_distributed() { | ||
int ones = 0, twos = 0, threes = 0, loopSize = 500000, selectionSize = 0; | ||
for (int i = 0; i < loopSize; i++) { | ||
String id = UUID.randomUUID().toString(); | ||
int featureRollout = | ||
StrategyUtils.getNormalizedNumber(id, "feature.name.that.is.quite.long", 0); | ||
if (featureRollout < 11) { | ||
int variantGroup = | ||
StrategyUtils.getNormalizedNumber( | ||
id, | ||
"feature.name.that.is.quite.long", | ||
1000, | ||
VariantUtil.VARIANT_NORMALIZATION_SEED); | ||
if (variantGroup <= 333) { | ||
ones++; | ||
} else if (variantGroup <= 666) { | ||
twos++; | ||
} else if (variantGroup <= 1000) { | ||
threes++; | ||
} | ||
selectionSize++; | ||
} | ||
} | ||
assertThat(ones / (double) (selectionSize)).isCloseTo(0.33, Offset.offset(0.01)); | ||
assertThat(twos / (double) (selectionSize)).isCloseTo(0.33, Offset.offset(0.01)); | ||
assertThat(threes / (double) (selectionSize)).isCloseTo(0.33, Offset.offset(0.01)); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we default seed to 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was done on purpose so every call site has to consider its seed.