Sha256: dca84e8bd29fb4659978a1e6937fbf8c61274233679f4f22bf235c7ff8a3659f
Contents?: true
Size: 1.35 KB
Versions: 4
Compression:
Stored size: 1.35 KB
Contents
require "ld-eventsource" require "http_stub" module SSE module Impl describe Backoff do it "increases exponentially with jitter" do initial = 1.5 max = 60 b = Backoff.new(initial, max) previous = 0 for i in 1..6 do interval = b.next_interval expect(interval).to be > previous target = initial * (2 ** (i - 1)) expect(interval).to be <= target expect(interval).to be >= target / 2 previous = i end interval = b.next_interval expect(interval).to be >= previous expect(interval).to be <= max end it "resets to initial delay if reset threshold has elapsed" do initial = 1.5 max = 60 threshold = 2 b = Backoff.new(initial, max, reconnect_reset_interval: threshold) for i in 1..6 do # just cause the backoff to increase quickly, don't actually do these delays b.next_interval end b.mark_success sleep(threshold + 0.001) interval = b.next_interval expect(interval).to be <= initial expect(interval).to be >= initial / 2 interval = b.next_interval # make sure it continues increasing after that expect(interval).to be <= (initial * 2) expect(interval).to be >= initial end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
ld-eventsource-2.1.0 | spec/backoff_spec.rb |
ld-eventsource-2.0.1 | spec/backoff_spec.rb |
ld-eventsource-2.0.0 | spec/backoff_spec.rb |
ld-eventsource-2.0.0.pre.beta.1 | spec/backoff_spec.rb |