summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-05-04 17:02:08 +0900
committerShinya Maeda <shinya@gitlab.com>2018-05-04 17:02:08 +0900
commit812dd06d512ab7774b375ce45aa9235aafc99911 (patch)
tree34cc187b9a70ad95967dff67f3efa397424b9aee /spec
parent47c8e06cefb7396c6f08b9908bd34dd21c8d08b0 (diff)
downloadgitlab-ce-812dd06d512ab7774b375ce45aa9235aafc99911.tar.gz
Introduce Redis helpers. Rename BuildTraceChunkFlushToDbWorker to Ci::BuildTraceChunkFlushWorker.
Diffstat (limited to 'spec')
-rw-r--r--spec/models/ci/build_trace_chunk_spec.rb4
-rw-r--r--spec/requests/api/runner_spec.rb6
-rw-r--r--spec/spec_helper.rb19
-rw-r--r--spec/support/chunked_io/chunked_io_helpers.rb5
-rw-r--r--spec/support/redis/redis_helpers.rb18
5 files changed, 36 insertions, 16 deletions
diff --git a/spec/models/ci/build_trace_chunk_spec.rb b/spec/models/ci/build_trace_chunk_spec.rb
index 991f501f633..118b72da11c 100644
--- a/spec/models/ci/build_trace_chunk_spec.rb
+++ b/spec/models/ci/build_trace_chunk_spec.rb
@@ -75,7 +75,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
let(:value) { 'a' * described_class::CHUNK_SIZE }
it 'schedules stashing data' do
- expect(BuildTraceChunkFlushToDbWorker).to receive(:perform_async).once
+ expect(Ci::BuildTraceChunkFlushWorker).to receive(:perform_async).once
subject
end
@@ -112,7 +112,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
context 'when fullfilled chunk size' do
it 'does not schedule stashing data' do
- expect(BuildTraceChunkFlushToDbWorker).not_to receive(:perform_async)
+ expect(Ci::BuildTraceChunkFlushWorker).not_to receive(:perform_async)
subject
end
diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb
index f27c95b4907..ff23b625244 100644
--- a/spec/requests/api/runner_spec.rb
+++ b/spec/requests/api/runner_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe API::Runner, :clean_gitlab_redis_shared_state do
include StubGitlabCalls
- include ChunkedIOHelpers
+ include RedisHelpers
let(:registration_token) { 'abcdefg123456' }
@@ -873,8 +873,8 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
patch_the_trace
expect(job.reload.trace.raw).to eq 'BUILD TRACE appended appended'
- # GitLab-Rails enxounters an outage on Redis
- redis_shared_state_outage!
+ # GitLab-Rails encounters an outage on Redis
+ redis_shared_state_cleanup!
expect(job.reload.trace.raw).to eq ''
# GitLab-Runner patchs
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index cc61cd7d838..b4fc596a751 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -86,6 +86,7 @@ RSpec.configure do |config|
config.include WaitForRequests, :js
config.include LiveDebugger, :js
config.include MigrationsHelpers, :migration
+ config.include RedisHelpers
if ENV['CI']
# This includes the first try, i.e. tests will be run 4 times before failing.
@@ -146,21 +147,27 @@ RSpec.configure do |config|
end
config.around(:each, :clean_gitlab_redis_cache) do |example|
- Gitlab::Redis::Cache.with(&:flushall)
+ redis_cache_cleanup!
example.run
- Gitlab::Redis::Cache.with(&:flushall)
+ redis_cache_cleanup!
end
config.around(:each, :clean_gitlab_redis_shared_state) do |example|
- Gitlab::Redis::SharedState.with(&:flushall)
- Sidekiq.redis(&:flushall)
+ redis_shared_state_cleanup!
example.run
- Gitlab::Redis::SharedState.with(&:flushall)
- Sidekiq.redis(&:flushall)
+ redis_shared_state_cleanup!
+ end
+
+ config.around(:each, :clean_gitlab_redis_queues) do |example|
+ redis_queues_cleanup!
+
+ example.run
+
+ redis_queues_cleanup!
end
# The :each scope runs "inside" the example, so this hook ensures the DB is in the
diff --git a/spec/support/chunked_io/chunked_io_helpers.rb b/spec/support/chunked_io/chunked_io_helpers.rb
index 4238a4b3e94..fec1f951563 100644
--- a/spec/support/chunked_io/chunked_io_helpers.rb
+++ b/spec/support/chunked_io/chunked_io_helpers.rb
@@ -8,9 +8,4 @@ module ChunkedIOHelpers
stub_const('Ci::BuildTraceChunk::CHUNK_SIZE', size)
stub_const('Gitlab::Ci::Trace::ChunkedIO::CHUNK_SIZE', size)
end
-
- def redis_shared_state_outage!
- Gitlab::Redis::SharedState.with(&:flushall)
- Sidekiq.redis(&:flushall)
- end
end
diff --git a/spec/support/redis/redis_helpers.rb b/spec/support/redis/redis_helpers.rb
new file mode 100644
index 00000000000..0457e8487d8
--- /dev/null
+++ b/spec/support/redis/redis_helpers.rb
@@ -0,0 +1,18 @@
+module RedisHelpers
+ # config/README.md
+
+ # Usage: performance enhancement
+ def redis_cache_cleanup!
+ Gitlab::Redis::Cache.with(&:flushall)
+ end
+
+ # Usage: SideKiq, Mailroom, CI Runner, Workhorse, push services
+ def redis_queues_cleanup!
+ Gitlab::Redis::Queues.with(&:flushall)
+ end
+
+ # Usage: session state, rate limiting
+ def redis_shared_state_cleanup!
+ Gitlab::Redis::SharedState.with(&:flushall)
+ end
+end