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
bcd664f5
Commit
bcd664f5
authored
Jun 03, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix specs. Rename migration file name which was conflicted with background migration's.
parent
0d00d02e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
74 deletions
+78
-74
db/post_migrate/20180529152628_schedule_to_archive_legacy_traces.rb
...grate/20180529152628_schedule_to_archive_legacy_traces.rb
+2
-2
spec/lib/gitlab/background_migration/archive_legacy_traces_spec.rb
...gitlab/background_migration/archive_legacy_traces_spec.rb
+8
-27
spec/migrations/archive_legacy_traces_spec.rb
spec/migrations/archive_legacy_traces_spec.rb
+0
-45
spec/migrations/schedule_to_archive_legacy_traces_spec.rb
spec/migrations/schedule_to_archive_legacy_traces_spec.rb
+45
-0
spec/support/trace/trace_helpers.rb
spec/support/trace/trace_helpers.rb
+23
-0
No files found.
db/post_migrate/20180529152628_archive_legacy_traces.rb
→
db/post_migrate/20180529152628_
schedule_to_
archive_legacy_traces.rb
View file @
bcd664f5
class
ArchiveLegacyTraces
<
ActiveRecord
::
Migration
class
ScheduleTo
ArchiveLegacyTraces
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
DOWNTIME
=
false
...
@@ -21,7 +21,7 @@ class ArchiveLegacyTraces < ActiveRecord::Migration
...
@@ -21,7 +21,7 @@ class ArchiveLegacyTraces < ActiveRecord::Migration
def
up
def
up
queue_background_migration_jobs_by_range_at_intervals
(
queue_background_migration_jobs_by_range_at_intervals
(
::
ArchiveLegacyTraces
::
Build
.
finished
.
without_archived_trace
,
::
ScheduleTo
ArchiveLegacyTraces
::
Build
.
finished
.
without_archived_trace
,
BACKGROUND_MIGRATION_CLASS
,
BACKGROUND_MIGRATION_CLASS
,
5
.
minutes
,
5
.
minutes
,
batch_size:
BATCH_SIZE
)
batch_size:
BATCH_SIZE
)
...
...
spec/lib/gitlab/background_migration/archive_legacy_traces_spec.rb
View file @
bcd664f5
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
ArchiveLegacyTraces
,
:migration
,
schema:
20180529152628
do
describe
Gitlab
::
BackgroundMigration
::
ArchiveLegacyTraces
,
:migration
,
schema:
20180529152628
do
include
TraceHelpers
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:builds
)
{
table
(
:ci_builds
)
}
let
(
:builds
)
{
table
(
:ci_builds
)
}
...
@@ -9,52 +11,31 @@ describe Gitlab::BackgroundMigration::ArchiveLegacyTraces, :migration, schema: 2
...
@@ -9,52 +11,31 @@ describe Gitlab::BackgroundMigration::ArchiveLegacyTraces, :migration, schema: 2
before
do
before
do
namespaces
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
)
namespaces
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
,
namespace_id:
123
)
projects
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
,
namespace_id:
123
)
build
=
builds
.
create!
(
id:
1
,
project_id:
123
,
status:
'success'
)
@build
=
builds
.
create!
(
id:
1
,
project_id:
123
,
status:
'success'
,
type:
'Ci::Build'
)
@legacy_trace_dir
=
File
.
join
(
Settings
.
gitlab_ci
.
builds_path
,
build
.
created_at
.
utc
.
strftime
(
"%Y_%m"
),
build
.
project_id
.
to_s
)
FileUtils
.
mkdir_p
(
@legacy_trace_dir
)
@legacy_trace_path
=
File
.
join
(
@legacy_trace_dir
,
"
#{
build
.
id
}
.log"
)
end
end
context
'when trace file exsits at the right place'
do
context
'when trace file exsits at the right place'
do
before
do
before
do
File
.
open
(
@legacy_trace_path
,
'wb'
)
{
|
stream
|
stream
.
write
(
'aiueo'
)
}
create_legacy_trace
(
@build
,
'aiueo'
)
end
end
it
'correctly archive legacy traces'
do
it
'correctly archive legacy traces'
do
expect
(
job_artifacts
.
count
).
to
eq
(
0
)
expect
(
job_artifacts
.
count
).
to
eq
(
0
)
expect
(
File
.
exist?
(
@legacy_trace_path
)).
to
be_truthy
expect
(
File
.
exist?
(
legacy_trace_path
(
@build
)
)).
to
be_truthy
described_class
.
new
.
perform
(
1
,
1
)
described_class
.
new
.
perform
(
1
,
1
)
expect
(
job_artifacts
.
count
).
to
eq
(
1
)
expect
(
job_artifacts
.
count
).
to
eq
(
1
)
expect
(
File
.
exist?
(
@legacy_trace_path
)).
to
be_falsy
expect
(
File
.
exist?
(
legacy_trace_path
(
@build
)
)).
to
be_falsy
expect
(
File
.
read
(
new_trace_path
)).
to
eq
(
'aiueo'
)
expect
(
File
.
read
(
archived_trace_path
(
job_artifacts
.
first
)
)).
to
eq
(
'aiueo'
)
end
end
end
end
context
'when trace file does not exsits at the right place'
do
context
'when trace file does not exsits at the right place'
do
it
'correctly archive legacy traces'
do
it
'does not raise errors and create job artifact row'
do
expect
(
job_artifacts
.
count
).
to
eq
(
0
)
expect
(
File
.
exist?
(
@legacy_trace_path
)).
to
be_falsy
described_class
.
new
.
perform
(
1
,
1
)
described_class
.
new
.
perform
(
1
,
1
)
expect
(
job_artifacts
.
count
).
to
eq
(
0
)
expect
(
job_artifacts
.
count
).
to
eq
(
0
)
end
end
end
end
def
new_trace_path
job_artifact
=
job_artifacts
.
first
disk_hash
=
Digest
::
SHA2
.
hexdigest
(
job_artifact
.
project_id
.
to_s
)
creation_date
=
job_artifact
.
created_at
.
utc
.
strftime
(
'%Y_%m_%d'
)
File
.
join
(
Gitlab
.
config
.
artifacts
.
path
,
disk_hash
[
0
..
1
],
disk_hash
[
2
..
3
],
disk_hash
,
creation_date
,
job_artifact
.
job_id
.
to_s
,
job_artifact
.
id
.
to_s
,
'job.log'
)
end
end
end
spec/migrations/archive_legacy_traces_spec.rb
deleted
100644 → 0
View file @
0d00d02e
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20180529152628_archive_legacy_traces'
)
describe
ArchiveLegacyTraces
,
:migration
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:builds
)
{
table
(
:ci_builds
)
}
let
(
:job_artifacts
)
{
table
(
:ci_job_artifacts
)
}
before
do
namespaces
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
,
namespace_id:
123
)
build
=
builds
.
create!
(
id:
1
)
@legacy_trace_path
=
File
.
join
(
Settings
.
gitlab_ci
.
builds_path
,
build
.
created_at
.
utc
.
strftime
(
"%Y_%m"
),
build
.
project_id
.
to_s
,
"
#{
job
.
id
}
.log"
)
File
.
open
(
@legacy_trace_path
,
'wb'
)
{
|
stream
|
stream
.
write
(
'aiueo'
)
}
end
it
'correctly archive legacy traces'
do
expect
(
job_artifacts
.
count
).
to
eq
(
0
)
expect
(
File
.
exist?
(
@legacy_trace_path
)).
to
be_truthy
migrate!
expect
(
job_artifacts
.
count
).
to
eq
(
1
)
expect
(
File
.
exist?
(
@legacy_trace_path
)).
to
be_falsy
expect
(
File
.
exist?
(
new_trace_path
)).
to
be_truthy
end
def
new_trace_path
job_artifact
=
job_artifacts
.
first
disk_hash
=
Digest
::
SHA2
.
hexdigest
(
job_artifact
.
project_id
.
to_s
)
creation_date
=
job_artifact
.
created_at
.
utc
.
strftime
(
'%Y_%m_%d'
)
File
.
join
(
disk_hash
[
0
..
1
],
disk_hash
[
2
..
3
],
disk_hash
,
creation_date
,
job_artifact
.
job_id
.
to_s
,
job_artifact
.
id
.
to_s
)
end
end
spec/migrations/schedule_to_archive_legacy_traces_spec.rb
0 → 100644
View file @
bcd664f5
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20180529152628_schedule_to_archive_legacy_traces'
)
describe
ScheduleToArchiveLegacyTraces
,
:migration
do
include
TraceHelpers
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:builds
)
{
table
(
:ci_builds
)
}
let
(
:job_artifacts
)
{
table
(
:ci_job_artifacts
)
}
before
do
namespaces
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
123
,
name:
'gitlab1'
,
path:
'gitlab1'
,
namespace_id:
123
)
@build_success
=
builds
.
create!
(
id:
1
,
project_id:
123
,
status:
'success'
,
type:
'Ci::Build'
)
@build_failed
=
builds
.
create!
(
id:
2
,
project_id:
123
,
status:
'failed'
,
type:
'Ci::Build'
)
@builds_canceled
=
builds
.
create!
(
id:
3
,
project_id:
123
,
status:
'canceled'
,
type:
'Ci::Build'
)
@build_running
=
builds
.
create!
(
id:
4
,
project_id:
123
,
status:
'running'
,
type:
'Ci::Build'
)
create_legacy_trace
(
@build_success
,
'This job is done'
)
create_legacy_trace
(
@build_failed
,
'This job is done'
)
create_legacy_trace
(
@builds_canceled
,
'This job is done'
)
create_legacy_trace
(
@build_running
,
'This job is not done yet'
)
end
it
'correctly archive legacy traces'
do
expect
(
job_artifacts
.
count
).
to
eq
(
0
)
expect
(
File
.
exist?
(
legacy_trace_path
(
@build_success
))).
to
be_truthy
expect
(
File
.
exist?
(
legacy_trace_path
(
@build_failed
))).
to
be_truthy
expect
(
File
.
exist?
(
legacy_trace_path
(
@builds_canceled
))).
to
be_truthy
expect
(
File
.
exist?
(
legacy_trace_path
(
@build_running
))).
to
be_truthy
migrate!
expect
(
job_artifacts
.
count
).
to
eq
(
3
)
expect
(
File
.
exist?
(
legacy_trace_path
(
@build_success
))).
to
be_falsy
expect
(
File
.
exist?
(
legacy_trace_path
(
@build_failed
))).
to
be_falsy
expect
(
File
.
exist?
(
legacy_trace_path
(
@builds_canceled
))).
to
be_falsy
expect
(
File
.
exist?
(
legacy_trace_path
(
@build_running
))).
to
be_truthy
expect
(
File
.
exist?
(
archived_trace_path
(
job_artifacts
.
where
(
job_id:
@build_success
.
id
).
first
))).
to
be_truthy
expect
(
File
.
exist?
(
archived_trace_path
(
job_artifacts
.
where
(
job_id:
@build_failed
.
id
).
first
))).
to
be_truthy
expect
(
File
.
exist?
(
archived_trace_path
(
job_artifacts
.
where
(
job_id:
@builds_canceled
.
id
).
first
))).
to
be_truthy
expect
(
job_artifacts
.
where
(
job_id:
@build_running
.
id
)).
not_to
be_exist
end
end
spec/support/trace/trace_helpers.rb
0 → 100644
View file @
bcd664f5
module
TraceHelpers
def
create_legacy_trace
(
build
,
content
)
File
.
open
(
legacy_trace_path
(
build
),
'wb'
)
{
|
stream
|
stream
.
write
(
content
)
}
end
def
legacy_trace_path
(
build
)
legacy_trace_dir
=
File
.
join
(
Settings
.
gitlab_ci
.
builds_path
,
build
.
created_at
.
utc
.
strftime
(
"%Y_%m"
),
build
.
project_id
.
to_s
)
FileUtils
.
mkdir_p
(
legacy_trace_dir
)
File
.
join
(
legacy_trace_dir
,
"
#{
build
.
id
}
.log"
)
end
def
archived_trace_path
(
job_artifact
)
disk_hash
=
Digest
::
SHA2
.
hexdigest
(
job_artifact
.
project_id
.
to_s
)
creation_date
=
job_artifact
.
created_at
.
utc
.
strftime
(
'%Y_%m_%d'
)
File
.
join
(
Gitlab
.
config
.
artifacts
.
path
,
disk_hash
[
0
..
1
],
disk_hash
[
2
..
3
],
disk_hash
,
creation_date
,
job_artifact
.
job_id
.
to_s
,
job_artifact
.
id
.
to_s
,
'job.log'
)
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