launchdarkly-server-sdk 5.6.0 → 5.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 502749fe2b55f4a3116ea223872835e76f7f698b
4
- data.tar.gz: 9ab5eae90b672dc39db4c3487bd67aa32878b467
3
+ metadata.gz: 634c7b652bbff689dc0d705f75536ee40e76648f
4
+ data.tar.gz: 7c932f06ef8f16e2f5a13f7c34d19aa834acfeb0
5
5
  SHA512:
6
- metadata.gz: a4f9f6642ab989aab6069924fc8b9f543123672cf475be58b72e1410a2563f246ce40d0cfef34dad0c77c37e28d695d05368c719df889eb5766d3618b19848b3
7
- data.tar.gz: 8c3af4780de0251380f194c8e4c4c3ce359f2a1612763e45a2a8b2eadab3d0dd20f83d5f0d60f8efb45759f5f8a4af7ccc6143085d2999065e4ca8791cf50291
6
+ metadata.gz: 81c83640f62d49bed5f91cf9b77f551d0df663491ed96fbfadc69a68a5a09787667c26554a09098bad9b8ba4ef55c78b2e15ab7743c99a3ba43c80b3de48723c
7
+ data.tar.gz: 72adc3f1ff659659c2093b3f81e680de298a15f20a43df7cc958c9a62040a8670e18505e604254f48401eb8fa5618d61873b7a22ba43fe1fe3a463f16f265a3f
@@ -0,0 +1,21 @@
1
+ **Requirements**
2
+
3
+ - [ ] I have added test coverage for new or changed functionality
4
+ - [ ] I have followed the repository's [pull request submission guidelines](../blob/master/CONTRIBUTING.md#submitting-pull-requests)
5
+ - [ ] I have validated my changes against all supported platform versions
6
+
7
+ **Related issues**
8
+
9
+ Provide links to any issues in this repository or elsewhere relating to this pull request.
10
+
11
+ **Describe the solution you've provided**
12
+
13
+ Provide a clear and concise description of what you expect to happen.
14
+
15
+ **Describe alternatives you've considered**
16
+
17
+ Provide a clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+
21
+ Add any other context about the pull request here.
data/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to the LaunchDarkly Ruby SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
4
4
 
5
- ## [5.6.0] - 2019-08-20
5
+ ## [5.6.0] - 2019-08-28
6
6
  ### Added:
7
7
  - Added support for upcoming LaunchDarkly experimentation features. See `LDClient.track()`.
8
8
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- launchdarkly-server-sdk (5.6.0)
4
+ launchdarkly-server-sdk (5.6.1)
5
5
  concurrent-ruby (~> 1.0)
6
6
  json (>= 1.8, < 3)
7
7
  ld-eventsource (= 1.0.1)
@@ -323,20 +323,28 @@ module LaunchDarkly
323
323
  end
324
324
 
325
325
  def variation_index_for_user(flag, rule, user)
326
- if !rule[:variation].nil? # fixed variation
327
- return rule[:variation]
328
- elsif !rule[:rollout].nil? # percentage rollout
326
+ variation = rule[:variation]
327
+ return variation if !variation.nil? # fixed variation
328
+ rollout = rule[:rollout]
329
+ return nil if rollout.nil?
330
+ variations = rollout[:variations]
331
+ if !variations.nil? && variations.length > 0 # percentage rollout
329
332
  rollout = rule[:rollout]
330
333
  bucket_by = rollout[:bucketBy].nil? ? "key" : rollout[:bucketBy]
331
334
  bucket = bucket_user(user, flag[:key], bucket_by, flag[:salt])
332
335
  sum = 0;
333
- rollout[:variations].each do |variate|
336
+ variations.each do |variate|
334
337
  sum += variate[:weight].to_f / 100000.0
335
338
  if bucket < sum
336
339
  return variate[:variation]
337
340
  end
338
341
  end
339
- nil
342
+ # The user's bucket value was greater than or equal to the end of the last bucket. This could happen due
343
+ # to a rounding error, or due to the fact that we are scaling to 100000 rather than 99999, or the flag
344
+ # data could contain buckets that don't actually add up to 100000. Rather than returning an error in
345
+ # this case (or changing the scaling, which would potentially change the results for *all* users), we
346
+ # will simply put the user in the last bucket.
347
+ variations[-1][:variation]
340
348
  else # the rule isn't well-formed
341
349
  nil
342
350
  end
@@ -1,3 +1,3 @@
1
1
  module LaunchDarkly
2
- VERSION = "5.6.0"
2
+ VERSION = "5.6.1"
3
3
  end
@@ -560,6 +560,58 @@ describe LaunchDarkly::Evaluation do
560
560
  end
561
561
  end
562
562
 
563
+ describe "variation_index_for_user" do
564
+ it "matches bucket" do
565
+ user = { key: "userkey" }
566
+ flag_key = "flagkey"
567
+ salt = "salt"
568
+
569
+ # First verify that with our test inputs, the bucket value will be greater than zero and less than 100000,
570
+ # so we can construct a rollout whose second bucket just barely contains that value
571
+ bucket_value = (bucket_user(user, flag_key, "key", salt) * 100000).truncate()
572
+ expect(bucket_value).to be > 0
573
+ expect(bucket_value).to be < 100000
574
+
575
+ bad_variation_a = 0
576
+ matched_variation = 1
577
+ bad_variation_b = 2
578
+ rule = {
579
+ rollout: {
580
+ variations: [
581
+ { variation: bad_variation_a, weight: bucket_value }, # end of bucket range is not inclusive, so it will *not* match the target value
582
+ { variation: matched_variation, weight: 1 }, # size of this bucket is 1, so it only matches that specific value
583
+ { variation: bad_variation_b, weight: 100000 - (bucket_value + 1) }
584
+ ]
585
+ }
586
+ }
587
+ flag = { key: flag_key, salt: salt }
588
+
589
+ result_variation = variation_index_for_user(flag, rule, user)
590
+ expect(result_variation).to be matched_variation
591
+ end
592
+
593
+ it "uses last bucket if bucket value is equal to total weight" do
594
+ user = { key: "userkey" }
595
+ flag_key = "flagkey"
596
+ salt = "salt"
597
+
598
+ bucket_value = (bucket_user(user, flag_key, "key", salt) * 100000).truncate()
599
+
600
+ # We'll construct a list of variations that stops right at the target bucket value
601
+ rule = {
602
+ rollout: {
603
+ variations: [
604
+ { variation: 0, weight: bucket_value }
605
+ ]
606
+ }
607
+ }
608
+ flag = { key: flag_key, salt: salt }
609
+
610
+ result_variation = variation_index_for_user(flag, rule, user)
611
+ expect(result_variation).to be 0
612
+ end
613
+ end
614
+
563
615
  describe "bucket_user" do
564
616
  it "gets expected bucket values for specific keys" do
565
617
  user = { key: "userKeyA" }
@@ -28,7 +28,7 @@ end
28
28
 
29
29
 
30
30
  describe "Consul feature store" do
31
- return if ENV['LD_SKIP_DATABASE_TESTS'] == '1'
31
+ break if ENV['LD_SKIP_DATABASE_TESTS'] == '1'
32
32
 
33
33
  # These tests will all fail if there isn't a local Consul instance running.
34
34
 
@@ -89,7 +89,7 @@ end
89
89
 
90
90
 
91
91
  describe "DynamoDB feature store" do
92
- return if ENV['LD_SKIP_DATABASE_TESTS'] == '1'
92
+ break if ENV['LD_SKIP_DATABASE_TESTS'] == '1'
93
93
 
94
94
  # These tests will all fail if there isn't a local DynamoDB instance running.
95
95
 
@@ -31,7 +31,7 @@ end
31
31
  describe LaunchDarkly::RedisFeatureStore do
32
32
  subject { LaunchDarkly::RedisFeatureStore }
33
33
 
34
- return if ENV['LD_SKIP_DATABASE_TESTS'] == '1'
34
+ break if ENV['LD_SKIP_DATABASE_TESTS'] == '1'
35
35
 
36
36
  # These tests will all fail if there isn't a Redis instance running on the default port.
37
37
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: launchdarkly-server-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.6.0
4
+ version: 5.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - LaunchDarkly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-20 00:00:00.000000000 Z
11
+ date: 2020-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb
@@ -237,6 +237,7 @@ files:
237
237
  - ".circleci/config.yml"
238
238
  - ".github/ISSUE_TEMPLATE/bug_report.md"
239
239
  - ".github/ISSUE_TEMPLATE/feature_request.md"
240
+ - ".github/pull_request_template.md"
240
241
  - ".gitignore"
241
242
  - ".hound.yml"
242
243
  - ".ldrelease/config.yml"