Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8cfc1e80
Commit
8cfc1e80
authored
Jun 14, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix GeoDynaicBackoff strategy code and added specs
parent
7bcb1d21
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
8 deletions
+64
-8
app/workers/concerns/geo_dynamic_backoff.rb
app/workers/concerns/geo_dynamic_backoff.rb
+10
-8
spec/workers/concerns/geo_dynamic_backoff_spec.rb
spec/workers/concerns/geo_dynamic_backoff_spec.rb
+54
-0
No files found.
app/workers/concerns/geo_dynamic_backoff.rb
View file @
8cfc1e80
...
...
@@ -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
spec/workers/concerns/geo_dynamic_backoff_spec.rb
0 → 100644
View file @
8cfc1e80
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment