BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
07693b43
Commit
07693b43
authored
Jun 28, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for delayed stage_id background migrations
parent
1dc20f7a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
4 deletions
+48
-4
20170628080858_migrate_stage_id_reference_in_background.rb
...0170628080858_migrate_stage_id_reference_in_background.rb
+4
-3
migrate_stage_id_reference_in_background_spec.rb
...grations/migrate_stage_id_reference_in_background_spec.rb
+44
-1
No files found.
db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
View file @
07693b43
...
@@ -15,9 +15,10 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
...
@@ -15,9 +15,10 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
Build
.
where
(
stage_id:
nil
)
Build
.
where
(
stage_id:
nil
)
.
find_in_batches
(
batch_size:
BATCH_SIZE
)
.
find_in_batches
(
batch_size:
BATCH_SIZE
)
.
with_index
do
|
builds
,
batch
|
.
with_index
do
|
builds
,
batch
|
migrations
=
builds
.
map
{
|
build
|
[
MIGRATION
,
[
build
.
id
]]
}
builds
.
each
do
|
build
|
schedule
=
(
batch
-
1
)
*
5
.
minutes
BackgroundMigrationWorker
.
perform_bulk
(
*
migrations
)
BackgroundMigrationWorker
.
perform_at
(
schedule
,
MIGRATION
,
[
build
.
id
])
end
end
end
end
end
...
...
spec/migrations/migrate_stage_id_reference_in_background_spec.rb
View file @
07693b43
require
'spec_helper'
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20170628080858_migrate_stage_id_reference_in_background'
)
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20170628080858_migrate_stage_id_reference_in_background'
)
describe
MigrateStageIdReferenceInBackground
,
:migration
,
:redis
do
RSpec
::
Matchers
.
define
:have_migrated
do
|*
expected
|
match
do
|
migration
|
BackgroundMigrationWorker
.
jobs
.
any?
do
|
job
|
job
[
'enqueued_at'
].
present?
&&
job
[
'args'
]
==
[
migration
,
expected
]
end
end
failure_message
do
|
migration
|
<<-
EOS
Background migration `
#{
migration
}
` with args `
#{
expected
.
inspect
}
`
not migrated!
EOS
end
end
RSpec
::
Matchers
.
define
:have_scheduled_migration
do
|
time
,
*
expected
|
match
do
|
migration
|
BackgroundMigrationWorker
.
jobs
.
any?
do
|
job
|
job
[
'args'
]
==
[
migration
,
expected
]
&&
job
[
'at'
]
>=
time
end
end
failure_message
do
|
migration
|
<<-
EOS
Background migration `
#{
migration
}
` with args `
#{
expected
.
inspect
}
`
not scheduled!
EOS
end
end
describe
MigrateStageIdReferenceInBackground
,
:migration
do
let
(
:jobs
)
{
table
(
:ci_builds
)
}
let
(
:jobs
)
{
table
(
:ci_builds
)
}
let
(
:stages
)
{
table
(
:ci_stages
)
}
let
(
:stages
)
{
table
(
:ci_stages
)
}
let
(
:pipelines
)
{
table
(
:ci_pipelines
)
}
let
(
:pipelines
)
{
table
(
:ci_pipelines
)
}
...
@@ -23,11 +53,24 @@ describe MigrateStageIdReferenceInBackground, :migration, :redis do
...
@@ -23,11 +53,24 @@ describe MigrateStageIdReferenceInBackground, :migration, :redis do
stages
.
create
(
id:
103
,
pipeline_id:
1
,
project_id:
123
,
name:
'deploy'
)
stages
.
create
(
id:
103
,
pipeline_id:
1
,
project_id:
123
,
name:
'deploy'
)
end
end
it
'correctly schedules background migrations'
do
Sidekiq
::
Testing
.
fake!
do
migrate!
expect
(
described_class
::
MIGRATION
).
to
have_migrated
(
1
)
expect
(
described_class
::
MIGRATION
).
to
have_migrated
(
2
)
expect
(
described_class
::
MIGRATION
).
to
have_scheduled_migration
(
5
.
minutes
,
3
)
expect
(
described_class
::
MIGRATION
).
to
have_scheduled_migration
(
5
.
minutes
,
4
)
end
end
it
'schedules background migrations'
do
it
'schedules background migrations'
do
Sidekiq
::
Testing
.
inline!
do
expect
(
jobs
.
where
(
stage_id:
nil
)).
to
be_present
expect
(
jobs
.
where
(
stage_id:
nil
)).
to
be_present
migrate!
migrate!
expect
(
jobs
.
where
(
stage_id:
nil
)).
to
be_empty
expect
(
jobs
.
where
(
stage_id:
nil
)).
to
be_empty
end
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