File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,11 @@ def next_interval
4141 @last_good_time = nil
4242 target = ( [ @base_interval * ( 2 ** @attempts ) , @max_interval ] . min ) . to_f
4343 @attempts += 1
44- ( target / 2 ) + @jitter_rand . rand ( target / 2 )
44+ if target == 0
45+ 0 # in some Ruby versions it's illegal to call rand(0)
46+ else
47+ ( target / 2 ) + @jitter_rand . rand ( target / 2 )
48+ end
4549 end
4650
4751 #
Original file line number Diff line number Diff line change @@ -47,6 +47,17 @@ module Impl
4747 expect ( interval ) . to be <= ( initial * 2 )
4848 expect ( interval ) . to be >= initial
4949 end
50+
51+ it "always returns zero if the initial delay is zero" do
52+ initial = 0
53+ max = 60
54+ b = Backoff . new ( initial , max )
55+
56+ for i in 1 ..6 do
57+ interval = b . next_interval
58+ expect ( interval ) . to eq ( 0 )
59+ end
60+ end
5061 end
5162 end
5263end
You can’t perform that action at this time.
0 commit comments