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
5627f28c
Commit
5627f28c
authored
May 04, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added shared exmaple for fast_destroy_all concern
parent
ecf8287c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
69 deletions
+53
-69
spec/models/ci/build_trace_chunk_spec.rb
spec/models/ci/build_trace_chunk_spec.rb
+15
-0
spec/models/concerns/fast_destroy_all_spec.rb
spec/models/concerns/fast_destroy_all_spec.rb
+0
-69
spec/support/shared_examples/fast_destroy_all.rb
spec/support/shared_examples/fast_destroy_all.rb
+38
-0
No files found.
spec/models/ci/build_trace_chunk_spec.rb
View file @
5627f28c
...
...
@@ -14,6 +14,21 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
stub_feature_flags
(
ci_enable_live_trace:
true
)
end
context
'FastDestroyAll'
do
let
(
:parent
)
{
create
(
:project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
parent
)
}
let
(
:build
)
{
create
(
:ci_build
,
:running
,
:trace_live
,
pipeline:
pipeline
,
project:
parent
)
}
let
(
:subjects
)
{
build
.
trace_chunks
}
it_behaves_like
'fast destroyable'
def
external_data_counter
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
redis
.
scan_each
(
match:
"gitlab:ci:trace:*:chunks:*"
).
to_a
.
size
end
end
end
describe
'CHUNK_SIZE'
do
it
'Chunk size can not be changed without special care'
do
expect
(
described_class
::
CHUNK_SIZE
).
to
eq
(
128
.
kilobytes
)
...
...
spec/models/concerns/fast_destroy_all_spec.rb
deleted
100644 → 0
View file @
ecf8287c
require
'spec_helper'
describe
FastDestroyAll
,
:clean_gitlab_redis_shared_state
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
before
do
stub_feature_flags
(
ci_enable_live_trace:
true
)
end
describe
'Forbid #destroy and #destroy_all'
do
let
(
:build
)
{
create
(
:ci_build
,
:running
,
:trace_live
,
pipeline:
pipeline
,
project:
project
)
}
let
(
:trace_chunks
)
{
build
.
trace_chunks
}
it
'does not delete database rows and associted external data'
do
expect
(
trace_chunks
.
first
).
to
be_a
(
described_class
)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
expect
(
redis
.
scan_each
(
match:
"gitlab:ci:trace:*:chunks:*"
).
to_a
.
size
).
to
eq
(
1
)
expect
(
trace_chunks
.
count
).
to
eq
(
1
)
expect
{
trace_chunks
.
first
.
destroy
}.
to
raise_error
(
'`destroy` and `destroy_all` are forbbiden. Please use `fast_destroy_all`'
)
expect
{
trace_chunks
.
destroy_all
}.
to
raise_error
(
'`destroy` and `destroy_all` are forbbiden. Please use `fast_destroy_all`'
)
expect
(
trace_chunks
.
count
).
to
eq
(
1
)
expect
(
redis
.
scan_each
(
match:
"gitlab:ci:trace:*:chunks:*"
).
to_a
.
size
).
to
eq
(
1
)
end
end
end
describe
'.fast_destroy_all'
do
let
(
:build
)
{
create
(
:ci_build
,
:running
,
:trace_live
,
pipeline:
pipeline
,
project:
project
)
}
let
(
:trace_chunks
)
{
build
.
trace_chunks
}
it
'deletes database rows and associted external data'
do
expect
(
trace_chunks
.
first
).
to
be_a
(
described_class
)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
expect
(
redis
.
scan_each
(
match:
"gitlab:ci:trace:*:chunks:*"
).
to_a
.
size
).
to
eq
(
1
)
expect
(
trace_chunks
.
count
).
to
eq
(
1
)
expect
{
build
.
trace_chunks
.
fast_destroy_all
}.
not_to
raise_error
expect
(
trace_chunks
.
count
).
to
eq
(
0
)
expect
(
redis
.
scan_each
(
match:
"gitlab:ci:trace:*:chunks:*"
).
to_a
.
size
).
to
eq
(
0
)
end
end
end
describe
'.use_fast_destroy'
do
let
(
:build
)
{
create
(
:ci_build
,
:running
,
:trace_live
,
pipeline:
pipeline
,
project:
project
)
}
let
(
:trace_chunks
)
{
build
.
trace_chunks
}
it
'performs cascading delete with fast_destroy_all'
do
expect
(
trace_chunks
.
first
).
to
be_a
(
described_class
)
expect
(
project
).
to
be_a
(
described_class
::
Helpers
)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
expect
(
redis
.
scan_each
(
match:
"gitlab:ci:trace:*:chunks:*"
).
to_a
.
size
).
to
eq
(
1
)
expect
(
trace_chunks
.
count
).
to
eq
(
1
)
project
.
destroy
expect
(
trace_chunks
.
count
).
to
eq
(
0
)
expect
(
redis
.
scan_each
(
match:
"gitlab:ci:trace:*:chunks:*"
).
to_a
.
size
).
to
eq
(
0
)
end
end
end
end
spec/support/shared_examples/fast_destroy_all.rb
0 → 100644
View file @
5627f28c
shared_examples_for
'fast destroyable'
do
describe
'Forbid #destroy and #destroy_all'
do
it
'does not delete database rows and associted external data'
do
expect
(
external_data_counter
).
to
be
>
0
expect
(
subjects
.
count
).
to
be
>
0
expect
{
subjects
.
first
.
destroy
}.
to
raise_error
(
'`destroy` and `destroy_all` are forbbiden. Please use `fast_destroy_all`'
)
expect
{
subjects
.
destroy_all
}.
to
raise_error
(
'`destroy` and `destroy_all` are forbbiden. Please use `fast_destroy_all`'
)
expect
(
subjects
.
count
).
to
be
>
0
expect
(
external_data_counter
).
to
be
>
0
end
end
describe
'.fast_destroy_all'
do
it
'deletes database rows and associted external data'
do
expect
(
external_data_counter
).
to
be
>
0
expect
(
subjects
.
count
).
to
be
>
0
expect
{
subjects
.
fast_destroy_all
}.
not_to
raise_error
expect
(
subjects
.
count
).
to
eq
(
0
)
expect
(
external_data_counter
).
to
eq
(
0
)
end
end
describe
'.use_fast_destroy'
do
it
'performs cascading delete with fast_destroy_all'
do
expect
(
external_data_counter
).
to
be
>
0
expect
(
subjects
.
count
).
to
be
>
0
expect
{
parent
.
destroy
}.
not_to
raise_error
expect
(
subjects
.
count
).
to
eq
(
0
)
expect
(
external_data_counter
).
to
eq
(
0
)
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