File: percentage_of_actors.rb

package info (click to toggle)
ruby-flipper 0.26.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,296 kB
  • sloc: ruby: 16,377; sh: 61; javascript: 24; makefile: 14
file content (31 lines) | stat: -rw-r--r-- 767 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'bundler/setup'
require 'flipper'

stats = Flipper[:stats]

# Some class that represents what will be trying to do something
class User < Struct.new(:id)
  include Flipper::Identifier
end

total = 100_000

# create array of fake users
users = (1..total).map { |n| User.new(n) }

perform_test = lambda { |number|
  Flipper.enable_percentage_of_actors :stats, number

  enabled = users.map { |user|
    Flipper.enabled?(:stats, user) ? true : nil
  }.compact

  actual = (enabled.size / total.to_f * 100).round(3)

  puts "percentage: #{actual.to_s.rjust(6, ' ')} vs #{number.to_s.rjust(3, ' ')}"
}

puts "percentage: Actual vs Hoped For"
[0.001, 0.01, 0.1, 1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 99, 100].each do |number|
  perform_test.call number
end