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
Léo-Paul Géneau
gitlab-ce
Commits
44cc5876
Commit
44cc5876
authored
Jun 25, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for each data store
parent
82d98426
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
441 additions
and
0 deletions
+441
-0
spec/factories/ci/build_trace_chunks.rb
spec/factories/ci/build_trace_chunks.rb
+58
-0
spec/models/ci/build_trace_chunks/database_spec.rb
spec/models/ci/build_trace_chunks/database_spec.rb
+105
-0
spec/models/ci/build_trace_chunks/fog_spec.rb
spec/models/ci/build_trace_chunks/fog_spec.rb
+146
-0
spec/models/ci/build_trace_chunks/redis_spec.rb
spec/models/ci/build_trace_chunks/redis_spec.rb
+132
-0
No files found.
spec/factories/ci/build_trace_chunks.rb
View file @
44cc5876
...
@@ -3,5 +3,63 @@ FactoryBot.define do
...
@@ -3,5 +3,63 @@ FactoryBot.define do
build
factory: :ci_build
build
factory: :ci_build
chunk_index
0
chunk_index
0
data_store
:redis
data_store
:redis
trait
:redis_with_data
do
data_store
:redis
transient
do
initial_data
'test data'
end
after
(
:create
)
do
|
build_trace_chunk
,
evaluator
|
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
redis
.
set
(
"gitlab:ci:trace:
#{
build_trace_chunk
.
build
.
id
}
:chunks:
#{
build_trace_chunk
.
chunk_index
.
to_i
}
"
,
evaluator
.
initial_data
,
ex:
1
.
day
)
end
end
end
trait
:redis_without_data
do
data_store
:redis
end
trait
:database_with_data
do
data_store
:database
transient
do
initial_data
'test data'
end
after
(
:build
)
do
|
build_trace_chunk
,
evaluator
|
build_trace_chunk
.
raw_data
=
evaluator
.
initial_data
end
end
trait
:database_without_data
do
data_store
:database
end
trait
:fog_with_data
do
data_store
:fog
transient
do
initial_data
'test data'
end
after
(
:create
)
do
|
build_trace_chunk
,
evaluator
|
::
Fog
::
Storage
.
new
(
JobArtifactUploader
.
object_store_credentials
).
tap
do
|
connection
|
connection
.
put_object
(
'artifacts'
,
"tmp/builds/
#{
build_trace_chunk
.
build
.
id
}
/chunks/
#{
build_trace_chunk
.
chunk_index
.
to_i
}
.log"
,
evaluator
.
initial_data
)
end
end
end
trait
:fog_without_data
do
data_store
:fog
end
end
end
end
end
spec/models/ci/build_trace_chunks/database_spec.rb
0 → 100644
View file @
44cc5876
require
'spec_helper'
describe
Ci
::
BuildTraceChunks
::
Database
do
let
(
:data_store
)
{
described_class
.
new
}
describe
'#available?'
do
subject
{
data_store
.
available?
}
it
{
is_expected
.
to
be_truthy
}
end
describe
'#data'
do
subject
{
data_store
.
data
(
model
)
}
context
'when data exists'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:database_with_data
,
initial_data:
'sample data in database'
)
}
it
'returns the data'
do
is_expected
.
to
eq
(
'sample data in database'
)
end
end
context
'when data does not exist'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:database_without_data
)
}
it
'returns nil'
do
is_expected
.
to
be_nil
end
end
end
describe
'#set_data'
do
subject
{
data_store
.
set_data
(
model
,
data
)
}
let
(
:data
)
{
'abc123'
}
context
'when data exists'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:database_with_data
,
initial_data:
'sample data in database'
)
}
it
'overwrites data'
do
expect
(
data_store
.
data
(
model
)).
to
eq
(
'sample data in database'
)
subject
expect
(
data_store
.
data
(
model
)).
to
eq
(
'abc123'
)
end
end
context
'when data does not exist'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:database_without_data
)
}
it
'sets new data'
do
expect
(
data_store
.
data
(
model
)).
to
be_nil
subject
expect
(
data_store
.
data
(
model
)).
to
eq
(
'abc123'
)
end
end
end
describe
'#delete_data'
do
subject
{
data_store
.
delete_data
(
model
)
}
context
'when data exists'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:database_with_data
,
initial_data:
'sample data in database'
)
}
it
'deletes data'
do
expect
(
data_store
.
data
(
model
)).
to
eq
(
'sample data in database'
)
subject
expect
(
data_store
.
data
(
model
)).
to
be_nil
end
end
context
'when data does not exist'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:database_without_data
)
}
it
'does nothing'
do
expect
(
data_store
.
data
(
model
)).
to
be_nil
subject
expect
(
data_store
.
data
(
model
)).
to
be_nil
end
end
end
describe
'#keys'
do
subject
{
data_store
.
keys
(
relation
)
}
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:relation
)
{
build
.
trace_chunks
}
before
do
create
(
:ci_build_trace_chunk
,
:database_with_data
,
chunk_index:
0
,
build:
build
)
create
(
:ci_build_trace_chunk
,
:database_with_data
,
chunk_index:
1
,
build:
build
)
end
it
'returns empty array'
do
is_expected
.
to
eq
([])
end
end
end
spec/models/ci/build_trace_chunks/fog_spec.rb
0 → 100644
View file @
44cc5876
require
'spec_helper'
describe
Ci
::
BuildTraceChunks
::
Fog
do
let
(
:data_store
)
{
described_class
.
new
}
before
do
stub_artifacts_object_storage
end
describe
'#available?'
do
subject
{
data_store
.
available?
}
context
'when object storage is enabled'
do
it
{
is_expected
.
to
be_truthy
}
end
context
'when object storage is disabled'
do
before
do
stub_artifacts_object_storage
(
enabled:
false
)
end
it
{
is_expected
.
to
be_falsy
}
end
end
describe
'#data'
do
subject
{
data_store
.
data
(
model
)
}
context
'when data exists'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:fog_with_data
,
initial_data:
'sample data in fog'
)
}
it
'returns the data'
do
is_expected
.
to
eq
(
'sample data in fog'
)
end
end
context
'when data does not exist'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:fog_without_data
)
}
it
'returns nil'
do
expect
{
data_store
.
data
(
model
)
}.
to
raise_error
(
Excon
::
Error
::
NotFound
)
end
end
end
describe
'#set_data'
do
subject
{
data_store
.
set_data
(
model
,
data
)
}
let
(
:data
)
{
'abc123'
}
context
'when data exists'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:fog_with_data
,
initial_data:
'sample data in fog'
)
}
it
'overwrites data'
do
expect
(
data_store
.
data
(
model
)).
to
eq
(
'sample data in fog'
)
subject
expect
(
data_store
.
data
(
model
)).
to
eq
(
'abc123'
)
end
end
context
'when data does not exist'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:fog_without_data
)
}
it
'sets new data'
do
expect
{
data_store
.
data
(
model
)
}.
to
raise_error
(
Excon
::
Error
::
NotFound
)
subject
expect
(
data_store
.
data
(
model
)).
to
eq
(
'abc123'
)
end
end
end
describe
'#delete_data'
do
subject
{
data_store
.
delete_data
(
model
)
}
context
'when data exists'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:fog_with_data
,
initial_data:
'sample data in fog'
)
}
it
'deletes data'
do
expect
(
data_store
.
data
(
model
)).
to
eq
(
'sample data in fog'
)
subject
expect
{
data_store
.
data
(
model
)
}.
to
raise_error
(
Excon
::
Error
::
NotFound
)
end
end
context
'when data does not exist'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:fog_without_data
)
}
it
'does nothing'
do
expect
{
data_store
.
data
(
model
)
}.
to
raise_error
(
Excon
::
Error
::
NotFound
)
subject
expect
{
data_store
.
data
(
model
)
}.
to
raise_error
(
Excon
::
Error
::
NotFound
)
end
end
end
describe
'#keys'
do
subject
{
data_store
.
keys
(
relation
)
}
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:relation
)
{
build
.
trace_chunks
}
before
do
create
(
:ci_build_trace_chunk
,
:fog_with_data
,
chunk_index:
0
,
build:
build
)
create
(
:ci_build_trace_chunk
,
:fog_with_data
,
chunk_index:
1
,
build:
build
)
end
it
'returns keys'
do
is_expected
.
to
eq
([[
build
.
id
,
0
],
[
build
.
id
,
1
]])
end
end
describe
'#delete_keys'
do
subject
{
data_store
.
delete_keys
(
keys
)
}
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:relation
)
{
build
.
trace_chunks
}
let
(
:keys
)
{
data_store
.
keys
(
relation
)
}
before
do
create
(
:ci_build_trace_chunk
,
:fog_with_data
,
chunk_index:
0
,
build:
build
)
create
(
:ci_build_trace_chunk
,
:fog_with_data
,
chunk_index:
1
,
build:
build
)
end
it
'deletes multiple data'
do
::
Fog
::
Storage
.
new
(
JobArtifactUploader
.
object_store_credentials
).
tap
do
|
connection
|
expect
(
connection
.
get_object
(
'artifacts'
,
"tmp/builds/
#{
build
.
id
}
/chunks/0.log"
)[
:body
]).
to
be_present
expect
(
connection
.
get_object
(
'artifacts'
,
"tmp/builds/
#{
build
.
id
}
/chunks/1.log"
)[
:body
]).
to
be_present
end
subject
::
Fog
::
Storage
.
new
(
JobArtifactUploader
.
object_store_credentials
).
tap
do
|
connection
|
expect
{
connection
.
get_object
(
'artifacts'
,
"tmp/builds/
#{
build
.
id
}
/chunks/0.log"
)[
:body
]
}.
to
raise_error
(
Excon
::
Error
::
NotFound
)
expect
{
connection
.
get_object
(
'artifacts'
,
"tmp/builds/
#{
build
.
id
}
/chunks/1.log"
)[
:body
]
}.
to
raise_error
(
Excon
::
Error
::
NotFound
)
end
end
end
end
spec/models/ci/build_trace_chunks/redis_spec.rb
0 → 100644
View file @
44cc5876
require
'spec_helper'
describe
Ci
::
BuildTraceChunks
::
Redis
,
:clean_gitlab_redis_shared_state
do
let
(
:data_store
)
{
described_class
.
new
}
describe
'#available?'
do
subject
{
data_store
.
available?
}
it
{
is_expected
.
to
be_truthy
}
end
describe
'#data'
do
subject
{
data_store
.
data
(
model
)
}
context
'when data exists'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:redis_with_data
,
initial_data:
'sample data in redis'
)
}
it
'returns the data'
do
is_expected
.
to
eq
(
'sample data in redis'
)
end
end
context
'when data does not exist'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:redis_without_data
)
}
it
'returns nil'
do
is_expected
.
to
be_nil
end
end
end
describe
'#set_data'
do
subject
{
data_store
.
set_data
(
model
,
data
)
}
let
(
:data
)
{
'abc123'
}
context
'when data exists'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:redis_with_data
,
initial_data:
'sample data in redis'
)
}
it
'overwrites data'
do
expect
(
data_store
.
data
(
model
)).
to
eq
(
'sample data in redis'
)
subject
expect
(
data_store
.
data
(
model
)).
to
eq
(
'abc123'
)
end
end
context
'when data does not exist'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:redis_without_data
)
}
it
'sets new data'
do
expect
(
data_store
.
data
(
model
)).
to
be_nil
subject
expect
(
data_store
.
data
(
model
)).
to
eq
(
'abc123'
)
end
end
end
describe
'#delete_data'
do
subject
{
data_store
.
delete_data
(
model
)
}
context
'when data exists'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:redis_with_data
,
initial_data:
'sample data in redis'
)
}
it
'deletes data'
do
expect
(
data_store
.
data
(
model
)).
to
eq
(
'sample data in redis'
)
subject
expect
(
data_store
.
data
(
model
)).
to
be_nil
end
end
context
'when data does not exist'
do
let
(
:model
)
{
create
(
:ci_build_trace_chunk
,
:redis_without_data
)
}
it
'does nothing'
do
expect
(
data_store
.
data
(
model
)).
to
be_nil
subject
expect
(
data_store
.
data
(
model
)).
to
be_nil
end
end
end
describe
'#keys'
do
subject
{
data_store
.
keys
(
relation
)
}
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:relation
)
{
build
.
trace_chunks
}
before
do
create
(
:ci_build_trace_chunk
,
:redis_with_data
,
chunk_index:
0
,
build:
build
)
create
(
:ci_build_trace_chunk
,
:redis_with_data
,
chunk_index:
1
,
build:
build
)
end
it
'returns keys'
do
is_expected
.
to
eq
([[
build
.
id
,
0
],
[
build
.
id
,
1
]])
end
end
describe
'#delete_keys'
do
subject
{
data_store
.
delete_keys
(
keys
)
}
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:relation
)
{
build
.
trace_chunks
}
let
(
:keys
)
{
data_store
.
keys
(
relation
)
}
before
do
create
(
:ci_build_trace_chunk
,
:redis_with_data
,
chunk_index:
0
,
build:
build
)
create
(
:ci_build_trace_chunk
,
:redis_with_data
,
chunk_index:
1
,
build:
build
)
end
it
'deletes multiple data'
do
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
expect
(
redis
.
exists
(
"gitlab:ci:trace:
#{
build
.
id
}
:chunks:0"
)).
to
be_truthy
expect
(
redis
.
exists
(
"gitlab:ci:trace:
#{
build
.
id
}
:chunks:1"
)).
to
be_truthy
end
subject
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
expect
(
redis
.
exists
(
"gitlab:ci:trace:
#{
build
.
id
}
:chunks:0"
)).
to
be_falsy
expect
(
redis
.
exists
(
"gitlab:ci:trace:
#{
build
.
id
}
:chunks:1"
)).
to
be_falsy
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