|
4 | 4 | subject { LaunchDarkly::Impl::EvaluatorBucketing } |
5 | 5 |
|
6 | 6 | describe "bucket_user" do |
| 7 | + describe "seed exists" do |
| 8 | + let(:seed) { 61 } |
| 9 | + it "gets the expected bucket values for seed" do |
| 10 | + user = { key: "userKeyA" } |
| 11 | + bucket = subject.bucket_user(user, "hashKey", "key", "saltyA", seed) |
| 12 | + expect(bucket).to be_within(0.0000001).of(0.09801207); |
| 13 | + |
| 14 | + user = { key: "userKeyB" } |
| 15 | + bucket = subject.bucket_user(user, "hashKey", "key", "saltyA", seed) |
| 16 | + expect(bucket).to be_within(0.0000001).of(0.14483777); |
| 17 | + |
| 18 | + user = { key: "userKeyC" } |
| 19 | + bucket = subject.bucket_user(user, "hashKey", "key", "saltyA", seed) |
| 20 | + expect(bucket).to be_within(0.0000001).of(0.9242641); |
| 21 | + end |
| 22 | + |
| 23 | + it "should return the same bucket if the seed and user is the same" do |
| 24 | + user = { key: "userKeyA" } |
| 25 | + bucket1 = subject.bucket_user(user, "hashKey", "bucket_by", "saltyA", seed) |
| 26 | + bucket2 = subject.bucket_user(user, "hashKey1", "bucket_by", "saltyB", seed) |
| 27 | + bucket3 = subject.bucket_user(user, "hashKey2", "bucket_by", "saltyC", seed) |
| 28 | + expect(bucket1).to eq(bucket2) |
| 29 | + expect(bucket2).to eq(bucket3) |
| 30 | + end |
| 31 | + end |
| 32 | + |
7 | 33 | it "gets expected bucket values for specific keys" do |
8 | 34 | user = { key: "userKeyA" } |
9 | | - bucket = subject.bucket_user(user, "hashKey", "key", "saltyA") |
| 35 | + bucket = subject.bucket_user(user, "hashKey", "key", "saltyA", nil) |
10 | 36 | expect(bucket).to be_within(0.0000001).of(0.42157587); |
11 | 37 |
|
12 | 38 | user = { key: "userKeyB" } |
13 | | - bucket = subject.bucket_user(user, "hashKey", "key", "saltyA") |
| 39 | + bucket = subject.bucket_user(user, "hashKey", "key", "saltyA", nil) |
14 | 40 | expect(bucket).to be_within(0.0000001).of(0.6708485); |
15 | 41 |
|
16 | 42 | user = { key: "userKeyC" } |
17 | | - bucket = subject.bucket_user(user, "hashKey", "key", "saltyA") |
| 43 | + bucket = subject.bucket_user(user, "hashKey", "key", "saltyA", nil) |
18 | 44 | expect(bucket).to be_within(0.0000001).of(0.10343106); |
19 | 45 | end |
20 | 46 |
|
|
26 | 52 | intAttr: 33333 |
27 | 53 | } |
28 | 54 | } |
29 | | - stringResult = subject.bucket_user(user, "hashKey", "stringAttr", "saltyA") |
30 | | - intResult = subject.bucket_user(user, "hashKey", "intAttr", "saltyA") |
| 55 | + stringResult = subject.bucket_user(user, "hashKey", "stringAttr", "saltyA", nil) |
| 56 | + intResult = subject.bucket_user(user, "hashKey", "intAttr", "saltyA", nil) |
31 | 57 |
|
32 | 58 | expect(intResult).to be_within(0.0000001).of(0.54771423) |
33 | 59 | expect(intResult).to eq(stringResult) |
|
40 | 66 | floatAttr: 33.5 |
41 | 67 | } |
42 | 68 | } |
43 | | - result = subject.bucket_user(user, "hashKey", "floatAttr", "saltyA") |
| 69 | + result = subject.bucket_user(user, "hashKey", "floatAttr", "saltyA", nil) |
44 | 70 | expect(result).to eq(0.0) |
45 | 71 | end |
46 | 72 |
|
|
52 | 78 | boolAttr: true |
53 | 79 | } |
54 | 80 | } |
55 | | - result = subject.bucket_user(user, "hashKey", "boolAttr", "saltyA") |
| 81 | + result = subject.bucket_user(user, "hashKey", "boolAttr", "saltyA", nil) |
56 | 82 | expect(result).to eq(0.0) |
57 | 83 | end |
58 | 84 | end |
|
65 | 91 |
|
66 | 92 | # First verify that with our test inputs, the bucket value will be greater than zero and less than 100000, |
67 | 93 | # so we can construct a rollout whose second bucket just barely contains that value |
68 | | - bucket_value = (subject.bucket_user(user, flag_key, "key", salt) * 100000).truncate() |
| 94 | + bucket_value = (subject.bucket_user(user, flag_key, "key", salt, nil) * 100000).truncate() |
69 | 95 | expect(bucket_value).to be > 0 |
70 | 96 | expect(bucket_value).to be < 100000 |
71 | 97 |
|
|
83 | 109 | } |
84 | 110 | flag = { key: flag_key, salt: salt } |
85 | 111 |
|
86 | | - result_variation = subject.variation_index_for_user(flag, rule, user) |
| 112 | + result_variation, _ = subject.variation_index_for_user(flag, rule, user) |
87 | 113 | expect(result_variation).to be matched_variation |
88 | 114 | end |
89 | 115 |
|
|
92 | 118 | flag_key = "flagkey" |
93 | 119 | salt = "salt" |
94 | 120 |
|
95 | | - bucket_value = (subject.bucket_user(user, flag_key, "key", salt) * 100000).truncate() |
| 121 | + bucket_value = (subject.bucket_user(user, flag_key, "key", salt, nil) * 100000).truncate() |
96 | 122 |
|
97 | 123 | # We'll construct a list of variations that stops right at the target bucket value |
98 | 124 | rule = { |
|
104 | 130 | } |
105 | 131 | flag = { key: flag_key, salt: salt } |
106 | 132 |
|
107 | | - result_variation = subject.variation_index_for_user(flag, rule, user) |
| 133 | + result_variation, _ = subject.variation_index_for_user(flag, rule, user) |
108 | 134 | expect(result_variation).to be 0 |
109 | 135 | end |
110 | 136 | end |
|
0 commit comments