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
82552153
Commit
82552153
authored
Jun 29, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve specs for background stage_id ref migration
parent
316d8821
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
12 deletions
+18
-12
db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
...0170628080858_migrate_stage_id_reference_in_background.rb
+5
-6
spec/migrations/migrate_stage_id_reference_in_background_spec.rb
...grations/migrate_stage_id_reference_in_background_spec.rb
+13
-6
No files found.
db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
View file @
82552153
...
...
@@ -12,13 +12,12 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
end
def
up
Build
.
where
(
stage_id:
nil
)
.
in_batches
(
of:
BATCH_SIZE
)
do
|
relation
,
index
|
schedule
=
index
*
5
.
minutes
jobs
=
relation
.
pluck
(
:id
).
map
{
|
id
|
[
MIGRATION
,
[
id
]]
}
Build
.
where
(
stage_id:
nil
).
in_batches
(
of:
BATCH_SIZE
)
do
|
relation
,
index
|
schedule
=
index
*
5
.
minutes
jobs
=
relation
.
pluck
(
:id
).
map
{
|
id
|
[
MIGRATION
,
[
id
]]
}
BackgroundMigrationWorker
.
perform_bulk_in
(
schedule
,
jobs
)
end
BackgroundMigrationWorker
.
perform_bulk_in
(
schedule
,
jobs
)
end
end
def
down
...
...
spec/migrations/migrate_stage_id_reference_in_background_spec.rb
View file @
82552153
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20170628080858_migrate_stage_id_reference_in_background'
)
describe
MigrateStageIdReferenceInBackground
,
:migration
,
:sidekiq
do
matcher
:
hav
e_scheduled_migration
do
|
delay
,
*
expected
|
matcher
:
b
e_scheduled_migration
do
|
delay
,
*
expected
|
match
do
|
migration
|
BackgroundMigrationWorker
.
jobs
.
any?
do
|
job
|
job
[
'args'
]
==
[
migration
,
expected
]
&&
...
...
@@ -24,16 +24,22 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
stub_const
(
'MigrateStageIdReferenceInBackground::BATCH_SIZE'
,
2
)
projects
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
345
,
name:
'gitlab2'
,
path:
'gitlab2'
)
pipelines
.
create!
(
id:
1
,
project_id:
123
,
ref:
'master'
,
sha:
'adf43c3a'
)
pipelines
.
create!
(
id:
2
,
project_id:
345
,
ref:
'feature'
,
sha:
'cdf43c3c'
)
jobs
.
create!
(
id:
1
,
commit_id:
1
,
project_id:
123
,
stage_idx:
2
,
stage:
'build'
)
jobs
.
create!
(
id:
2
,
commit_id:
1
,
project_id:
123
,
stage_idx:
2
,
stage:
'build'
)
jobs
.
create!
(
id:
3
,
commit_id:
1
,
project_id:
123
,
stage_idx:
1
,
stage:
'test'
)
jobs
.
create!
(
id:
4
,
commit_id:
1
,
project_id:
123
,
stage_idx:
3
,
stage:
'deploy'
)
jobs
.
create!
(
id:
5
,
commit_id:
2
,
project_id:
345
,
stage_idx:
1
,
stage:
'test'
)
stages
.
create
(
id:
101
,
pipeline_id:
1
,
project_id:
123
,
name:
'test'
)
stages
.
create
(
id:
102
,
pipeline_id:
1
,
project_id:
123
,
name:
'build'
)
stages
.
create
(
id:
103
,
pipeline_id:
1
,
project_id:
123
,
name:
'deploy'
)
jobs
.
create!
(
id:
6
,
commit_id:
2
,
project_id:
345
,
stage_id:
101
,
stage_idx:
1
,
stage:
'test'
)
end
it
'correctly schedules background migrations'
do
...
...
@@ -41,10 +47,11 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
Timecop
.
freeze
do
migrate!
expect
(
described_class
::
MIGRATION
).
to
have_scheduled_migration
(
5
.
minutes
,
1
)
expect
(
described_class
::
MIGRATION
).
to
have_scheduled_migration
(
5
.
minutes
,
2
)
expect
(
described_class
::
MIGRATION
).
to
have_scheduled_migration
(
10
.
minutes
,
3
)
expect
(
described_class
::
MIGRATION
).
to
have_scheduled_migration
(
10
.
minutes
,
4
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
5
.
minutes
,
1
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
5
.
minutes
,
2
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
10
.
minutes
,
3
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
10
.
minutes
,
4
)
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
5
end
end
end
...
...
@@ -55,7 +62,7 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
migrate!
expect
(
jobs
.
where
(
stage_id:
nil
)).
to
be_
empty
expect
(
jobs
.
where
(
stage_id:
nil
)).
to
be_
one
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