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
af41bd41
Commit
af41bd41
authored
Jul 17, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix off-by-one error in background migration retries
parent
7b146ab6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
14 deletions
+25
-14
lib/gitlab/background_migration.rb
lib/gitlab/background_migration.rb
+10
-5
spec/lib/gitlab/background_migration_spec.rb
spec/lib/gitlab/background_migration_spec.rb
+15
-9
No files found.
lib/gitlab/background_migration.rb
View file @
af41bd41
...
@@ -48,12 +48,17 @@ module Gitlab
...
@@ -48,12 +48,17 @@ module Gitlab
#
#
# arguments - The arguments to pass to the background migration's "perform"
# arguments - The arguments to pass to the background migration's "perform"
# method.
# method.
def
self
.
perform
(
class_name
,
arguments
,
retries:
1
)
def
self
.
perform
(
class_name
,
arguments
,
retries:
0
)
const_get
(
class_name
).
new
.
perform
(
*
arguments
)
const_get
(
class_name
).
new
.
perform
(
*
arguments
)
rescue
=>
e
rescue
StandardError
Rails
.
logger
.
warn
(
"Retrying background migration
#{
class_name
}
"
\
if
retries
>
0
"with
#{
arguments
}
"
)
Rails
.
logger
.
warn
(
"Retrying background migration
#{
class_name
}
"
\
(
retries
-=
1
)
>
0
?
retry
:
raise
"with
#{
arguments
}
"
)
retries
-=
1
retry
else
raise
end
end
end
end
end
end
end
spec/lib/gitlab/background_migration_spec.rb
View file @
af41bd41
...
@@ -63,14 +63,10 @@ describe Gitlab::BackgroundMigration do
...
@@ -63,14 +63,10 @@ describe Gitlab::BackgroundMigration do
end
end
context
'when standard error is being raised'
do
context
'when standard error is being raised'
do
before
do
allow
(
migration
).
to
receive
(
:perform
).
with
(
10
,
20
)
.
and_raise
(
StandardError
,
'Migration error'
)
end
it
'recovers from an exception and retries the migration'
do
it
'recovers from an exception and retries the migration'
do
expect
(
migration
).
to
receive
(
:perform
).
with
(
10
,
20
)
expect
(
migration
).
to
receive
(
:perform
).
with
(
10
,
20
)
.
exactly
(
3
).
times
.
ordered
.
and_raise
(
StandardError
,
'Migration error'
)
.
exactly
(
4
).
times
.
ordered
expect
(
migration
).
to
receive
(
:perform
).
with
(
20
,
30
)
expect
(
migration
).
to
receive
(
:perform
).
with
(
20
,
30
)
.
once
.
ordered
.
once
.
ordered
expect
(
Rails
.
logger
).
to
receive
(
:warn
)
expect
(
Rails
.
logger
).
to
receive
(
:warn
)
...
@@ -148,7 +144,17 @@ describe Gitlab::BackgroundMigration do
...
@@ -148,7 +144,17 @@ describe Gitlab::BackgroundMigration do
expect
(
migration
).
to
receive
(
:perform
).
with
(
10
,
20
)
expect
(
migration
).
to
receive
(
:perform
).
with
(
10
,
20
)
.
and_raise
(
StandardError
).
once
.
and_raise
(
StandardError
).
once
expect
{
described_class
.
perform
(
'Foo'
,
[
10
,
20
],
retries:
0
)
}
expect
{
described_class
.
perform
(
'Foo'
,
[
10
,
20
],
retries:
0
)
}
.
to
raise_error
(
StandardError
)
end
end
context
'when retries count is one'
do
it
'retries a background migration when needed'
do
expect
(
migration
).
to
receive
(
:perform
).
with
(
10
,
20
)
.
and_raise
(
StandardError
).
twice
expect
{
described_class
.
perform
(
'Foo'
,
[
10
,
20
],
retries:
1
)
}
.
to
raise_error
(
StandardError
)
.
to
raise_error
(
StandardError
)
end
end
end
end
...
@@ -156,9 +162,9 @@ describe Gitlab::BackgroundMigration do
...
@@ -156,9 +162,9 @@ describe Gitlab::BackgroundMigration do
context
'when retries count is larger than zero'
do
context
'when retries count is larger than zero'
do
it
'retries a background migration when needed'
do
it
'retries a background migration when needed'
do
expect
(
migration
).
to
receive
(
:perform
).
with
(
10
,
20
)
expect
(
migration
).
to
receive
(
:perform
).
with
(
10
,
20
)
.
and_raise
(
StandardError
).
exactly
(
3
).
times
.
and_raise
(
StandardError
).
exactly
(
4
).
times
expect
{
described_class
.
perform
(
'Foo'
,
[
10
,
20
],
retries:
3
)
}
expect
{
described_class
.
perform
(
'Foo'
,
[
10
,
20
],
retries:
3
)
}
.
to
raise_error
(
StandardError
)
.
to
raise_error
(
StandardError
)
end
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