Commit 85f96425 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'fix/gb/fix-runner-exponential-backoff' into 'master'

Ensure that runner exponential backoff is an integer

Closes #258628

See merge request gitlab-org/gitlab!43849
parents 005f49c0 0004915e
......@@ -57,11 +57,11 @@ module Gitlab
end
def duration
Time.current - @started
(Time.current - @started).ceil
end
def slot
return 0 if duration <= 1
return 0 if duration < 2
Math.log(duration, 2).floor - 1
end
......
......@@ -15,14 +15,36 @@ RSpec.describe Gitlab::Ci::Runner::Backoff do
end
end
end
it 'returns an integer value' do
freeze_time do
described_class.new(5.seconds.ago).then do |backoff|
expect(backoff.duration).to be 5
end
end
end
it 'returns the smallest number greater than or equal to duration' do
freeze_time do
described_class.new(0.5.seconds.ago).then do |backoff|
expect(backoff.duration).to be 1
end
end
end
end
describe '#slot' do
using RSpec::Parameterized::TableSyntax
where(:started, :slot) do
0 | 0
0.1 | 0
0.9 | 0
1 | 0
1.1 | 0
1.9 | 0
2 | 0
2.9 | 0
3 | 0
4 | 1
5 | 1
......@@ -30,6 +52,7 @@ RSpec.describe Gitlab::Ci::Runner::Backoff do
7 | 1
8 | 2
9 | 2
9.9 | 2
10 | 2
15 | 2
16 | 3
......@@ -59,15 +82,22 @@ RSpec.describe Gitlab::Ci::Runner::Backoff do
using RSpec::Parameterized::TableSyntax
where(:started, :backoff) do
0 | 1
0.1 | 1
0.9 | 1
1 | 1
1.1 | 1
1.9 | 1
2 | 1
3 | 1
4 | 2
5 | 2
6 | 2
6.5 | 2
7 | 2
8 | 4
9 | 4
9.9 | 4
10 | 4
15 | 4
16 | 8
......
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