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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
4a132952
Commit
4a132952
authored
Dec 18, 2018
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract a shared example for legacy and hashed storage migrations tests
parent
754f6611
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
78 deletions
+46
-78
spec/lib/gitlab/background_migration/backfill_hashed_project_repositories_spec.rb
...nd_migration/backfill_hashed_project_repositories_spec.rb
+1
-39
spec/lib/gitlab/background_migration/backfill_legacy_project_repositories_spec.rb
...nd_migration/backfill_legacy_project_repositories_spec.rb
+1
-39
spec/support/shared_examples/lib/gitlab/background_migration/backfill_project_repositories_examples.rb
...round_migration/backfill_project_repositories_examples.rb
+44
-0
No files found.
spec/lib/gitlab/background_migration/backfill_hashed_project_repositories_spec.rb
View file @
4a132952
...
...
@@ -3,43 +3,5 @@
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
BackfillHashedProjectRepositories
,
:migration
,
schema:
20181130102132
do
describe
'#perform'
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:project_repositories
)
{
table
(
:project_repositories
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:shards
)
{
table
(
:shards
)
}
let
(
:group
)
{
namespaces
.
create!
(
name:
'foo'
,
path:
'foo'
)
}
let
(
:shard
)
{
shards
.
create!
(
name:
'default'
)
}
it
'creates a project_repository row for projects on hashed storage that need one'
do
projects
.
create!
(
id:
1
,
name:
'foo'
,
path:
'foo'
,
namespace_id:
group
.
id
,
storage_version:
1
)
projects
.
create!
(
id:
2
,
name:
'bar'
,
path:
'bar'
,
namespace_id:
group
.
id
,
storage_version:
2
)
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
to
change
(
project_repositories
,
:count
).
by
(
2
)
end
it
'does nothing for projects on hashed storage that have already a project_repository row'
do
projects
.
create!
(
id:
1
,
name:
'foo'
,
path:
'foo'
,
namespace_id:
group
.
id
,
storage_version:
1
)
project_repositories
.
create!
(
project_id:
1
,
disk_path:
'@phony/foo/bar'
,
shard_id:
shard
.
id
)
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
not_to
change
(
project_repositories
,
:count
)
end
it
'does nothing for projects on legacy storage'
do
projects
.
create!
(
name:
'foo'
,
path:
'foo'
,
namespace_id:
group
.
id
,
storage_version:
0
)
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
not_to
change
(
project_repositories
,
:count
)
end
it
'inserts rows in a single query'
do
projects
.
create!
(
name:
'foo'
,
path:
'foo'
,
namespace_id:
group
.
id
,
storage_version:
1
,
repository_storage:
shard
.
name
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}
projects
.
create!
(
name:
'bar'
,
path:
'bar'
,
namespace_id:
group
.
id
,
storage_version:
1
,
repository_storage:
shard
.
name
)
projects
.
create!
(
name:
'zoo'
,
path:
'zoo'
,
namespace_id:
group
.
id
,
storage_version:
1
,
repository_storage:
shard
.
name
)
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
not_to
exceed_query_limit
(
control_count
)
end
end
it_behaves_like
'backfill migration for project repositories'
,
:hashed
end
spec/lib/gitlab/background_migration/backfill_legacy_project_repositories_spec.rb
View file @
4a132952
...
...
@@ -3,43 +3,5 @@
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
BackfillLegacyProjectRepositories
,
:migration
,
schema:
20181218192239
do
describe
'#perform'
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:project_repositories
)
{
table
(
:project_repositories
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:shards
)
{
table
(
:shards
)
}
let
(
:group
)
{
namespaces
.
create!
(
name:
'foo'
,
path:
'foo'
)
}
let
(
:shard
)
{
shards
.
create!
(
name:
'default'
)
}
it
'creates a project_repository row for projects on legacy storage that need one'
do
projects
.
create!
(
id:
1
,
name:
'foo'
,
path:
'foo'
,
namespace_id:
group
.
id
,
storage_version:
nil
)
projects
.
create!
(
id:
2
,
name:
'bar'
,
path:
'bar'
,
namespace_id:
group
.
id
,
storage_version:
0
)
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
to
change
(
project_repositories
,
:count
).
by
(
2
)
end
it
'does nothing for projects on legacy storage that have already a project_repository row'
do
projects
.
create!
(
id:
1
,
name:
'foo'
,
path:
'foo'
,
namespace_id:
group
.
id
,
storage_version:
0
)
project_repositories
.
create!
(
project_id:
1
,
disk_path:
'phony/foo/bar'
,
shard_id:
shard
.
id
)
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
not_to
change
(
project_repositories
,
:count
)
end
it
'does nothing for projects on hashed storage'
do
projects
.
create!
(
name:
'foo'
,
path:
'foo'
,
namespace_id:
group
.
id
,
storage_version:
1
)
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
not_to
change
(
project_repositories
,
:count
)
end
it
'inserts rows in a single query'
do
projects
.
create!
(
name:
'foo'
,
path:
'foo'
,
namespace_id:
group
.
id
,
storage_version:
0
,
repository_storage:
shard
.
name
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}
projects
.
create!
(
name:
'bar'
,
path:
'bar'
,
namespace_id:
group
.
id
,
storage_version:
0
,
repository_storage:
shard
.
name
)
projects
.
create!
(
name:
'zoo'
,
path:
'zoo'
,
namespace_id:
group
.
id
,
storage_version:
0
,
repository_storage:
shard
.
name
)
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
not_to
exceed_query_limit
(
control_count
)
end
end
it_behaves_like
'backfill migration for project repositories'
,
:legacy
end
spec/support/shared_examples/lib/gitlab/background_migration/backfill_project_repositories_examples.rb
0 → 100644
View file @
4a132952
shared_examples
'backfill migration for project repositories'
do
|
storage
|
describe
'#perform'
do
let
(
:storage_versions
)
{
storage
==
:legacy
?
[
nil
,
0
]
:
[
1
,
2
]
}
let
(
:storage_version
)
{
storage_versions
.
first
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:project_repositories
)
{
table
(
:project_repositories
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:shards
)
{
table
(
:shards
)
}
let
(
:group
)
{
namespaces
.
create!
(
name:
'foo'
,
path:
'foo'
)
}
let
(
:shard
)
{
shards
.
create!
(
name:
'default'
)
}
it
"creates a project_repository row for projects on
#{
storage
}
storage that needs one"
do
storage_versions
.
each_with_index
do
|
storage_version
,
index
|
projects
.
create!
(
name:
"foo-
#{
index
}
"
,
path:
"foo-
#{
index
}
"
,
namespace_id:
group
.
id
,
storage_version:
storage_version
)
end
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
to
change
(
project_repositories
,
:count
).
by
(
2
)
end
it
"does nothing for projects on
#{
storage
}
storage that have already a project_repository row"
do
projects
.
create!
(
id:
1
,
name:
'foo'
,
path:
'foo'
,
namespace_id:
group
.
id
,
storage_version:
storage_version
)
project_repositories
.
create!
(
project_id:
1
,
disk_path:
'phony/foo/bar'
,
shard_id:
shard
.
id
)
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
not_to
change
(
project_repositories
,
:count
)
end
it
"does nothing for projects on
#{
storage
==
:legacy
?
'hashed'
:
'legacy'
}
storage"
do
projects
.
create!
(
name:
'foo'
,
path:
'foo'
,
namespace_id:
group
.
id
,
storage_version:
storage
==
:legacy
?
1
:
nil
)
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
not_to
change
(
project_repositories
,
:count
)
end
it
'inserts rows in a single query'
do
projects
.
create!
(
name:
'foo'
,
path:
'foo'
,
namespace_id:
group
.
id
,
storage_version:
storage_version
,
repository_storage:
shard
.
name
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}
projects
.
create!
(
name:
'bar'
,
path:
'bar'
,
namespace_id:
group
.
id
,
storage_version:
storage_version
,
repository_storage:
shard
.
name
)
projects
.
create!
(
name:
'zoo'
,
path:
'zoo'
,
namespace_id:
group
.
id
,
storage_version:
storage_version
,
repository_storage:
shard
.
name
)
expect
{
described_class
.
new
.
perform
(
1
,
projects
.
last
.
id
)
}.
not_to
exceed_query_limit
(
control_count
)
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