Commit 899dbb7f authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'use-redis-flushdb-in-specs' into 'master'

Use flushdb, not flushall, in specs

See merge request gitlab-org/gitlab!63629
parents 3f77252c 4531afda
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do RSpec.describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_shared_state do
let(:previous_event_id) { 7 } let(:previous_event_id) { 7 }
let(:gap_id) { previous_event_id + 1 } let(:gap_id) { previous_event_id + 1 }
let(:event_id_with_gap) { previous_event_id + 2 } let(:event_id_with_gap) { previous_event_id + 2 }
......
...@@ -137,7 +137,7 @@ RSpec.describe 'Merge request > User sees pipelines', :js do ...@@ -137,7 +137,7 @@ RSpec.describe 'Merge request > User sees pipelines', :js do
check_head_pipeline(expected_project: parent_project) check_head_pipeline(expected_project: parent_project)
end end
it 'does not create a pipeline in the parent project when user cancels the action' do it 'does not create a pipeline in the parent project when user cancels the action', :clean_gitlab_redis_cache, :clean_gitlab_redis_shared_state do
visit project_merge_request_path(parent_project, merge_request) visit project_merge_request_path(parent_project, merge_request)
create_merge_request_pipeline create_merge_request_pipeline
......
...@@ -138,7 +138,7 @@ RSpec.describe ProjectsHelper do ...@@ -138,7 +138,7 @@ RSpec.describe ProjectsHelper do
end end
end end
describe "#project_list_cache_key", :clean_gitlab_redis_shared_state do describe "#project_list_cache_key", :clean_gitlab_redis_cache do
let(:project) { project_with_repo } let(:project) { project_with_repo }
before do before do
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::RateLimitHelpers, :clean_gitlab_redis_shared_state do RSpec.describe Gitlab::RateLimitHelpers, :clean_gitlab_redis_cache do
let(:limiter_class) do let(:limiter_class) do
Class.new do Class.new do
include ::Gitlab::RateLimitHelpers include ::Gitlab::RateLimitHelpers
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::SidekiqStatus do RSpec.describe Gitlab::SidekiqStatus, :clean_gitlab_redis_queues, :clean_gitlab_redis_shared_state do
describe '.set', :clean_gitlab_redis_shared_state do describe '.set' do
it 'stores the job ID' do it 'stores the job ID' do
described_class.set('123') described_class.set('123')
...@@ -16,7 +16,7 @@ RSpec.describe Gitlab::SidekiqStatus do ...@@ -16,7 +16,7 @@ RSpec.describe Gitlab::SidekiqStatus do
end end
end end
describe '.unset', :clean_gitlab_redis_shared_state do describe '.unset' do
it 'removes the job ID' do it 'removes the job ID' do
described_class.set('123') described_class.set('123')
described_class.unset('123') described_class.unset('123')
...@@ -29,7 +29,7 @@ RSpec.describe Gitlab::SidekiqStatus do ...@@ -29,7 +29,7 @@ RSpec.describe Gitlab::SidekiqStatus do
end end
end end
describe '.all_completed?', :clean_gitlab_redis_shared_state do describe '.all_completed?' do
it 'returns true if all jobs have been completed' do it 'returns true if all jobs have been completed' do
expect(described_class.all_completed?(%w(123))).to eq(true) expect(described_class.all_completed?(%w(123))).to eq(true)
end end
...@@ -41,7 +41,7 @@ RSpec.describe Gitlab::SidekiqStatus do ...@@ -41,7 +41,7 @@ RSpec.describe Gitlab::SidekiqStatus do
end end
end end
describe '.running?', :clean_gitlab_redis_shared_state do describe '.running?' do
it 'returns true if job is running' do it 'returns true if job is running' do
described_class.set('123') described_class.set('123')
...@@ -53,7 +53,7 @@ RSpec.describe Gitlab::SidekiqStatus do ...@@ -53,7 +53,7 @@ RSpec.describe Gitlab::SidekiqStatus do
end end
end end
describe '.num_running', :clean_gitlab_redis_shared_state do describe '.num_running' do
it 'returns 0 if all jobs have been completed' do it 'returns 0 if all jobs have been completed' do
expect(described_class.num_running(%w(123))).to eq(0) expect(described_class.num_running(%w(123))).to eq(0)
end end
...@@ -66,7 +66,7 @@ RSpec.describe Gitlab::SidekiqStatus do ...@@ -66,7 +66,7 @@ RSpec.describe Gitlab::SidekiqStatus do
end end
end end
describe '.num_completed', :clean_gitlab_redis_shared_state do describe '.num_completed' do
it 'returns 1 if all jobs have been completed' do it 'returns 1 if all jobs have been completed' do
expect(described_class.num_completed(%w(123))).to eq(1) expect(described_class.num_completed(%w(123))).to eq(1)
end end
...@@ -88,7 +88,7 @@ RSpec.describe Gitlab::SidekiqStatus do ...@@ -88,7 +88,7 @@ RSpec.describe Gitlab::SidekiqStatus do
end end
end end
describe 'completed', :clean_gitlab_redis_shared_state do describe 'completed' do
it 'returns the completed job' do it 'returns the completed job' do
expect(described_class.completed_jids(%w(123))).to eq(['123']) expect(described_class.completed_jids(%w(123))).to eq(['123'])
end end
......
...@@ -75,7 +75,7 @@ RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do ...@@ -75,7 +75,7 @@ RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do
end end
it 'returns false when the local version was bumped' do it 'returns false when the local version was bumped' do
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:local_markdown_version).and_return(2) stub_application_setting(local_markdown_version: 2)
thing.cached_markdown_version = cache_version thing.cached_markdown_version = cache_version
is_expected.to be_falsy is_expected.to be_falsy
...@@ -88,7 +88,7 @@ RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do ...@@ -88,7 +88,7 @@ RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do
end end
it 'returns true when the cached version is just right' do it 'returns true when the cached version is just right' do
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:local_markdown_version).and_return(2) stub_application_setting(local_markdown_version: 2)
thing.cached_markdown_version = cache_version + 2 thing.cached_markdown_version = cache_version + 2
is_expected.to be_truthy is_expected.to be_truthy
......
...@@ -21,7 +21,7 @@ RSpec.describe API::Branches do ...@@ -21,7 +21,7 @@ RSpec.describe API::Branches do
stub_feature_flags(branch_list_keyset_pagination: false) stub_feature_flags(branch_list_keyset_pagination: false)
end end
describe "GET /projects/:id/repository/branches", :use_clean_rails_redis_caching do describe "GET /projects/:id/repository/branches", :use_clean_rails_redis_caching, :clean_gitlab_redis_shared_state do
let(:route) { "/projects/#{project_id}/repository/branches" } let(:route) { "/projects/#{project_id}/repository/branches" }
shared_examples_for 'repository branches' do shared_examples_for 'repository branches' do
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do RSpec.describe API::Ci::Runner, :clean_gitlab_redis_trace_chunks do
include StubGitlabCalls include StubGitlabCalls
include RedisHelpers include RedisHelpers
include WorkhorseHelpers include WorkhorseHelpers
...@@ -142,7 +142,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -142,7 +142,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
context 'when redis data are flushed' do context 'when redis data are flushed' do
before do before do
redis_shared_state_cleanup! redis_trace_chunks_cleanup!
end end
it 'has empty trace' do it 'has empty trace' do
......
...@@ -39,7 +39,7 @@ RSpec.describe DesignManagement::CopyDesignCollection::QueueService, :clean_gitl ...@@ -39,7 +39,7 @@ RSpec.describe DesignManagement::CopyDesignCollection::QueueService, :clean_gitl
expect { subject }.to change { target_issue.design_collection.copy_state }.from('ready').to('in_progress') expect { subject }.to change { target_issue.design_collection.copy_state }.from('ready').to('in_progress')
end end
it 'queues a DesignManagement::CopyDesignCollectionWorker' do it 'queues a DesignManagement::CopyDesignCollectionWorker', :clean_gitlab_redis_queues do
expect { subject }.to change(DesignManagement::CopyDesignCollectionWorker.jobs, :size).by(1) expect { subject }.to change(DesignManagement::CopyDesignCollectionWorker.jobs, :size).by(1)
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe EventCreateService do RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redis_shared_state do
let(:service) { described_class.new } let(:service) { described_class.new }
let_it_be(:user, reload: true) { create :user } let_it_be(:user, reload: true) { create :user }
...@@ -50,7 +50,7 @@ RSpec.describe EventCreateService do ...@@ -50,7 +50,7 @@ RSpec.describe EventCreateService do
end end
end end
describe 'Merge Requests', :clean_gitlab_redis_shared_state do describe 'Merge Requests' do
describe '#open_mr' do describe '#open_mr' do
subject(:open_mr) { service.open_mr(merge_request, merge_request.author) } subject(:open_mr) { service.open_mr(merge_request, merge_request.author) }
...@@ -194,7 +194,7 @@ RSpec.describe EventCreateService do ...@@ -194,7 +194,7 @@ RSpec.describe EventCreateService do
end end
end end
describe '#wiki_event', :clean_gitlab_redis_shared_state do describe '#wiki_event' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:wiki_page) { create(:wiki_page) } let_it_be(:wiki_page) { create(:wiki_page) }
let_it_be(:meta) { create(:wiki_page_meta, :for_wiki_page, wiki_page: wiki_page) } let_it_be(:meta) { create(:wiki_page_meta, :for_wiki_page, wiki_page: wiki_page) }
...@@ -247,7 +247,7 @@ RSpec.describe EventCreateService do ...@@ -247,7 +247,7 @@ RSpec.describe EventCreateService do
end end
end end
describe '#push', :clean_gitlab_redis_shared_state do describe '#push' do
let(:push_data) do let(:push_data) do
{ {
commits: [ commits: [
...@@ -272,7 +272,7 @@ RSpec.describe EventCreateService do ...@@ -272,7 +272,7 @@ RSpec.describe EventCreateService do
end end
end end
describe '#bulk_push', :clean_gitlab_redis_shared_state do describe '#bulk_push' do
let(:push_data) do let(:push_data) do
{ {
action: :created, action: :created,
...@@ -306,7 +306,7 @@ RSpec.describe EventCreateService do ...@@ -306,7 +306,7 @@ RSpec.describe EventCreateService do
end end
end end
describe 'design events', :clean_gitlab_redis_shared_state do describe 'design events' do
let_it_be(:design) { create(:design, project: project) } let_it_be(:design) { create(:design, project: project) }
let_it_be(:author) { user } let_it_be(:author) { user }
......
...@@ -554,24 +554,13 @@ RSpec.describe Git::BranchPushService, services: true do ...@@ -554,24 +554,13 @@ RSpec.describe Git::BranchPushService, services: true do
end end
end end
describe "housekeeping" do describe "housekeeping", :clean_gitlab_redis_cache, :clean_gitlab_redis_queues, :clean_gitlab_redis_shared_state do
let(:housekeeping) { Repositories::HousekeepingService.new(project) } let(:housekeeping) { Repositories::HousekeepingService.new(project) }
before do before do
# Flush any raw key-value data stored by the housekeeping code.
Gitlab::Redis::Cache.with { |conn| conn.flushall }
Gitlab::Redis::Queues.with { |conn| conn.flushall }
Gitlab::Redis::SharedState.with { |conn| conn.flushall }
allow(Repositories::HousekeepingService).to receive(:new).and_return(housekeeping) allow(Repositories::HousekeepingService).to receive(:new).and_return(housekeeping)
end end
after do
Gitlab::Redis::Cache.with { |conn| conn.flushall }
Gitlab::Redis::Queues.with { |conn| conn.flushall }
Gitlab::Redis::SharedState.with { |conn| conn.flushall }
end
it 'does not perform housekeeping when not needed' do it 'does not perform housekeeping when not needed' do
expect(housekeeping).not_to receive(:execute) expect(housekeeping).not_to receive(:execute)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_shared_state, :sidekiq_inline do RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_cache, :clean_gitlab_redis_shared_state, :sidekiq_inline do
let_it_be(:source) { create(:project) } let_it_be(:source) { create(:project) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:member) { create(:user) } let_it_be(:member) { create(:user) }
......
...@@ -5,21 +5,21 @@ module RedisHelpers ...@@ -5,21 +5,21 @@ module RedisHelpers
# Usage: performance enhancement # Usage: performance enhancement
def redis_cache_cleanup! def redis_cache_cleanup!
Gitlab::Redis::Cache.with(&:flushall) Gitlab::Redis::Cache.with(&:flushdb)
end end
# Usage: SideKiq, Mailroom, CI Runner, Workhorse, push services # Usage: SideKiq, Mailroom, CI Runner, Workhorse, push services
def redis_queues_cleanup! def redis_queues_cleanup!
Gitlab::Redis::Queues.with(&:flushall) Gitlab::Redis::Queues.with(&:flushdb)
end end
# Usage: session state, rate limiting # Usage: session state, rate limiting
def redis_shared_state_cleanup! def redis_shared_state_cleanup!
Gitlab::Redis::SharedState.with(&:flushall) Gitlab::Redis::SharedState.with(&:flushdb)
end end
# Usage: CI trace chunks # Usage: CI trace chunks
def redis_trace_chunks_cleanup! def redis_trace_chunks_cleanup!
Gitlab::Redis::TraceChunks.with(&:flushall) Gitlab::Redis::TraceChunks.with(&:flushdb)
end end
end end
...@@ -5,9 +5,9 @@ RSpec.shared_context 'unique ips sign in limit' do ...@@ -5,9 +5,9 @@ RSpec.shared_context 'unique ips sign in limit' do
let(:request_context) { Gitlab::RequestContext.instance } let(:request_context) { Gitlab::RequestContext.instance }
before do before do
Gitlab::Redis::Cache.with(&:flushall) redis_cache_cleanup!
Gitlab::Redis::Queues.with(&:flushall) redis_queues_cleanup!
Gitlab::Redis::SharedState.with(&:flushall) redis_shared_state_cleanup!
end end
before do before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment