Commit 4531afda authored by Nick Thomas's avatar Nick Thomas

Use flushdb, not flushall, in specs

Some specs need a clean Redis state to run successfully. We want to add
per-environment isolation using redis databases, but to do that, we
need to use flushdb instead of flushall.
parent b047f9e5
......@@ -2,7 +2,7 @@
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(:gap_id) { previous_event_id + 1 }
let(:event_id_with_gap) { previous_event_id + 2 }
......
......@@ -137,7 +137,7 @@ RSpec.describe 'Merge request > User sees pipelines', :js do
check_head_pipeline(expected_project: parent_project)
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)
create_merge_request_pipeline
......
......@@ -138,7 +138,7 @@ RSpec.describe ProjectsHelper do
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 }
before do
......
......@@ -2,7 +2,7 @@
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
Class.new do
include ::Gitlab::RateLimitHelpers
......
......@@ -2,8 +2,8 @@
require 'spec_helper'
RSpec.describe Gitlab::SidekiqStatus do
describe '.set', :clean_gitlab_redis_shared_state do
RSpec.describe Gitlab::SidekiqStatus, :clean_gitlab_redis_queues, :clean_gitlab_redis_shared_state do
describe '.set' do
it 'stores the job ID' do
described_class.set('123')
......@@ -16,7 +16,7 @@ RSpec.describe Gitlab::SidekiqStatus do
end
end
describe '.unset', :clean_gitlab_redis_shared_state do
describe '.unset' do
it 'removes the job ID' do
described_class.set('123')
described_class.unset('123')
......@@ -29,7 +29,7 @@ RSpec.describe Gitlab::SidekiqStatus do
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
expect(described_class.all_completed?(%w(123))).to eq(true)
end
......@@ -41,7 +41,7 @@ RSpec.describe Gitlab::SidekiqStatus do
end
end
describe '.running?', :clean_gitlab_redis_shared_state do
describe '.running?' do
it 'returns true if job is running' do
described_class.set('123')
......@@ -53,7 +53,7 @@ RSpec.describe Gitlab::SidekiqStatus do
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
expect(described_class.num_running(%w(123))).to eq(0)
end
......@@ -66,7 +66,7 @@ RSpec.describe Gitlab::SidekiqStatus do
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
expect(described_class.num_completed(%w(123))).to eq(1)
end
......@@ -88,7 +88,7 @@ RSpec.describe Gitlab::SidekiqStatus do
end
end
describe 'completed', :clean_gitlab_redis_shared_state do
describe 'completed' do
it 'returns the completed job' do
expect(described_class.completed_jids(%w(123))).to eq(['123'])
end
......
......@@ -75,7 +75,7 @@ RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do
end
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
is_expected.to be_falsy
......@@ -88,7 +88,7 @@ RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do
end
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
is_expected.to be_truthy
......
......@@ -21,7 +21,7 @@ RSpec.describe API::Branches do
stub_feature_flags(branch_list_keyset_pagination: false)
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" }
shared_examples_for 'repository branches' do
......
......@@ -2,7 +2,7 @@
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 RedisHelpers
include WorkhorseHelpers
......@@ -142,7 +142,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
context 'when redis data are flushed' do
before do
redis_shared_state_cleanup!
redis_trace_chunks_cleanup!
end
it 'has empty trace' do
......
......@@ -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')
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)
end
......
......@@ -2,7 +2,7 @@
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_it_be(:user, reload: true) { create :user }
......@@ -50,7 +50,7 @@ RSpec.describe EventCreateService do
end
end
describe 'Merge Requests', :clean_gitlab_redis_shared_state do
describe 'Merge Requests' do
describe '#open_mr' do
subject(:open_mr) { service.open_mr(merge_request, merge_request.author) }
......@@ -194,7 +194,7 @@ RSpec.describe EventCreateService do
end
end
describe '#wiki_event', :clean_gitlab_redis_shared_state do
describe '#wiki_event' do
let_it_be(:user) { create(:user) }
let_it_be(:wiki_page) { create(: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
end
end
describe '#push', :clean_gitlab_redis_shared_state do
describe '#push' do
let(:push_data) do
{
commits: [
......@@ -272,7 +272,7 @@ RSpec.describe EventCreateService do
end
end
describe '#bulk_push', :clean_gitlab_redis_shared_state do
describe '#bulk_push' do
let(:push_data) do
{
action: :created,
......@@ -306,7 +306,7 @@ RSpec.describe EventCreateService do
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(:author) { user }
......
......@@ -554,24 +554,13 @@ RSpec.describe Git::BranchPushService, services: true do
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) }
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)
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
expect(housekeeping).not_to receive(:execute)
......
......@@ -2,7 +2,7 @@
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(:user) { create(:user) }
let_it_be(:member) { create(:user) }
......
......@@ -5,21 +5,21 @@ module RedisHelpers
# Usage: performance enhancement
def redis_cache_cleanup!
Gitlab::Redis::Cache.with(&:flushall)
Gitlab::Redis::Cache.with(&:flushdb)
end
# Usage: SideKiq, Mailroom, CI Runner, Workhorse, push services
def redis_queues_cleanup!
Gitlab::Redis::Queues.with(&:flushall)
Gitlab::Redis::Queues.with(&:flushdb)
end
# Usage: session state, rate limiting
def redis_shared_state_cleanup!
Gitlab::Redis::SharedState.with(&:flushall)
Gitlab::Redis::SharedState.with(&:flushdb)
end
# Usage: CI trace chunks
def redis_trace_chunks_cleanup!
Gitlab::Redis::TraceChunks.with(&:flushall)
Gitlab::Redis::TraceChunks.with(&:flushdb)
end
end
......@@ -5,9 +5,9 @@ RSpec.shared_context 'unique ips sign in limit' do
let(:request_context) { Gitlab::RequestContext.instance }
before do
Gitlab::Redis::Cache.with(&:flushall)
Gitlab::Redis::Queues.with(&:flushall)
Gitlab::Redis::SharedState.with(&:flushall)
redis_cache_cleanup!
redis_queues_cleanup!
redis_shared_state_cleanup!
end
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