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
9b7239c4
Commit
9b7239c4
authored
May 05, 2020
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide SleepingLock#attempts and expose #retried?
parent
fd82c357
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
7 deletions
+35
-7
lib/gitlab/exclusive_lease_helpers.rb
lib/gitlab/exclusive_lease_helpers.rb
+1
-1
lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb
lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb
+5
-3
spec/lib/gitlab/exclusive_lease_helpers/sleeping_lock_spec.rb
.../lib/gitlab/exclusive_lease_helpers/sleeping_lock_spec.rb
+29
-3
No files found.
lib/gitlab/exclusive_lease_helpers.rb
View file @
9b7239c4
...
...
@@ -35,7 +35,7 @@ module Gitlab
lease
.
obtain
(
1
+
retries
)
yield
(
lease
.
attempts
>
1
)
yield
(
lease
.
retried?
)
ensure
lease
&
.
cancel
end
...
...
lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb
View file @
9b7239c4
...
...
@@ -4,8 +4,6 @@ module Gitlab
module
ExclusiveLeaseHelpers
# Wrapper around ExclusiveLease that adds retry logic
class
SleepingLock
attr_reader
:attempts
delegate
:cancel
,
to: :@lease
def
initialize
(
key
,
timeout
:,
delay
:)
...
...
@@ -23,9 +21,13 @@ module Gitlab
end
end
def
retried?
attempts
>
1
end
private
attr_reader
:delay
attr_reader
:delay
,
:attempts
def
held?
@uuid
.
present?
...
...
spec/lib/gitlab/exclusive_lease_helpers/sleeping_lock_spec.rb
View file @
9b7239c4
...
...
@@ -11,6 +11,32 @@ describe Gitlab::ExclusiveLeaseHelpers::SleepingLock, :clean_gitlab_redis_shared
subject
{
described_class
.
new
(
key
,
timeout:
timeout
,
delay:
delay
)
}
describe
'#retried?'
do
before
do
stub_exclusive_lease
(
key
,
'uuid'
)
end
context
'we have not made any attempts'
do
it
{
is_expected
.
not_to
be_retried
}
end
context
'we just made a single (initial) attempt'
do
it
'is not considered a retry'
do
subject
.
send
(
:try_obtain
)
is_expected
.
not_to
be_retried
end
end
context
'made multiple attempts'
do
it
'is considered a retry'
do
2
.
times
{
subject
.
send
(
:try_obtain
)
}
is_expected
.
to
be_retried
end
end
end
describe
'#obtain'
do
context
'when the lease is not held'
do
before
do
...
...
@@ -22,7 +48,7 @@ describe Gitlab::ExclusiveLeaseHelpers::SleepingLock, :clean_gitlab_redis_shared
subject
.
obtain
(
10
)
expect
(
subject
.
attempts
).
to
eq
(
1
)
expect
(
subject
).
not_to
be_retried
end
end
...
...
@@ -51,14 +77,14 @@ describe Gitlab::ExclusiveLeaseHelpers::SleepingLock, :clean_gitlab_redis_shared
end
context
'when lease is granted after retry'
do
it
'
records the successful attempt number
'
do
it
'
knows that it retried
'
do
expect
(
subject
).
to
receive
(
:sleep
).
with
(
delay
).
exactly
(
3
).
times
expect
(
lease
).
to
receive
(
:try_obtain
).
exactly
(
3
).
times
{
nil
}
expect
(
lease
).
to
receive
(
:try_obtain
).
once
{
'obtained'
}
subject
.
obtain
(
max_attempts
)
expect
(
subject
.
attempts
).
to
eq
(
4
)
expect
(
subject
).
to
be_retried
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