Commit 9f999549 authored by Douwe Maan's avatar Douwe Maan

Merge branch '2639-geo-dynamic-backoff-strategy-is-not-working' into 'master'

Geo: Fix Dynamic Backoff strategy and add specs

Closes #2639

See merge request !2128
parents 41527bfa 5d728481
......@@ -11,6 +11,7 @@ module GeoDynamicBackoff
end
end
class_methods do
private
def linear_backoff_strategy(count)
......@@ -22,4 +23,5 @@ module GeoDynamicBackoff
count = count - 30 # we must start counting after 30
(count**4) + 15 + (rand(30) * (count + 1))
end
end
end
---
title: 'Geo: fixed Dynamic Backoff strategy that was not being used by workers'
merge_request: 2128
author:
require 'spec_helper'
describe GeoDynamicBackoff do
class TestWorkerBackOff
include Sidekiq::Worker
include GeoDynamicBackoff
def perform(options)
false
end
end
let(:worker) do
TestWorkerBackOff
end
context 'retry strategy' do
it 'sets a custom strategy for retrying' do
expect(worker.sidekiq_retry_in_block).to be_a(Proc)
end
it 'when retry_count is in 1..30, retries with linear_backoff_strategy' do
expect(worker).to receive(:linear_backoff_strategy)
worker.sidekiq_retry_in_block.call(1)
expect(worker).to receive(:linear_backoff_strategy)
worker.sidekiq_retry_in_block.call(30)
end
it 'when retry_count is > 30, retries with geometric_backoff_strategy' do
expect(worker).to receive(:geometric_backoff_strategy)
worker.sidekiq_retry_in_block.call(31)
end
end
context '.linear_backoff_strategy' do
it 'returns rand + retry_count' do
allow(worker).to receive(:rand).and_return(1)
expect(worker.sidekiq_retry_in_block.call(1)).to eq(2)
end
end
context '.geometric_backoff_strategy' do
it 'when retry_count is 31 for a fixed rand()=1 returns 18' do
allow(worker).to receive(:rand).and_return(1)
expect(worker.sidekiq_retry_in_block.call(31)).to eq(18)
end
it 'when retry_count is 32 for a fixed rand()=1 returns 18' do
allow(worker).to receive(:rand).and_return(1)
expect(worker.sidekiq_retry_in_block.call(32)).to eq(34)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment