diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-04 15:10:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-04 15:10:17 +0300 |
commit | c80a1141e306596202f694b101bfb1aab1864de9 (patch) | |
tree | 46aaee47523ecd57fa6396dae224c3f1cc4079eb /spec/lib | |
parent | 57f8f3552ca37f38f19a6520737ae1ce0009efb3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/checks/matching_merge_request_spec.rb | 92 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/cache_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/queues_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/shared_state_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/wrapper_spec.rb | 6 |
5 files changed, 116 insertions, 9 deletions
diff --git a/spec/lib/gitlab/checks/matching_merge_request_spec.rb b/spec/lib/gitlab/checks/matching_merge_request_spec.rb index ca7ee784ee3..74087d13e2c 100644 --- a/spec/lib/gitlab/checks/matching_merge_request_spec.rb +++ b/spec/lib/gitlab/checks/matching_merge_request_spec.rb @@ -18,6 +18,9 @@ RSpec.describe Gitlab::Checks::MatchingMergeRequest do subject { described_class.new(newrev, target_branch, project) } + let(:total_counter) { subject.send(:total_counter) } + let(:stale_counter) { subject.send(:stale_counter) } + it 'matches a merge request' do expect(subject.match?).to be true end @@ -27,5 +30,94 @@ RSpec.describe Gitlab::Checks::MatchingMergeRequest do expect(matcher.match?).to be false end + + context 'with load balancing disabled', :request_store, :redis do + before do + expect(::Gitlab::Database::LoadBalancing).to receive(:enable?).at_least(:once).and_return(false) + expect(::Gitlab::Database::LoadBalancing::Sticking).not_to receive(:unstick_or_continue_sticking) + expect(::Gitlab::Database::LoadBalancing::Sticking).not_to receive(:select_valid_replicas) + end + + it 'does not attempt to stick to primary' do + expect(subject.match?).to be true + end + + it 'increments no counters' do + expect { subject.match? } + .to change { total_counter.get }.by(0) + .and change { stale_counter.get }.by(0) + end + end + + context 'with load balancing enabled', :request_store, :redis do + let(:session) { ::Gitlab::Database::LoadBalancing::Session.current } + let(:all_caught_up) { true } + + before do + expect(::Gitlab::Database::LoadBalancing).to receive(:enable?).at_least(:once).and_return(true) + allow(::Gitlab::Database::LoadBalancing::Sticking).to receive(:all_caught_up?).and_return(all_caught_up) + end + + shared_examples 'secondary that has caught up to a primary' do + it 'continues to use the secondary' do + expect(session.use_primary?).to be false + expect(subject.match?).to be true + end + + it 'only increments total counter' do + expect { subject.match? } + .to change { total_counter.get }.by(1) + .and change { stale_counter.get }.by(0) + end + end + + shared_examples 'secondary that is lagging primary' do + it 'sticks to the primary' do + expect(subject.match?).to be true + expect(session.use_primary?).to be true + end + + it 'increments both total and stale counters' do + expect { subject.match? } + .to change { total_counter.get }.by(1) + .and change { stale_counter.get }.by(1) + end + end + + context 'with load_balancing_atomic_replica feature flag enabled' do + before do + stub_feature_flags(load_balancing_atomic_replica: true) + + expect(::Gitlab::Database::LoadBalancing::Sticking).to receive(:select_valid_host).with(:project, project.id).and_call_original + allow(::Gitlab::Database::LoadBalancing::Sticking).to receive(:select_caught_up_replicas).with(:project, project.id).and_return(all_caught_up) + end + + it_behaves_like 'secondary that has caught up to a primary' + + context 'on secondary behind primary' do + let(:all_caught_up) { false } + + it_behaves_like 'secondary that is lagging primary' + end + end + + context 'with load_balancing_atomic_replica feature flag disabled' do + before do + stub_feature_flags(load_balancing_atomic_replica: false) + + expect(::Gitlab::Database::LoadBalancing::Sticking).not_to receive(:select_valid_host) + expect(::Gitlab::Database::LoadBalancing::Sticking).to receive(:unstick_or_continue_sticking).and_call_original + allow(::Gitlab::Database::LoadBalancing::Sticking).to receive(:all_caught_up?).and_return(all_caught_up) + end + + it_behaves_like 'secondary that has caught up to a primary' + + context 'on secondary behind primary' do + let(:all_caught_up) { false } + + it_behaves_like 'secondary that is lagging primary' + end + end + end end end diff --git a/spec/lib/gitlab/redis/cache_spec.rb b/spec/lib/gitlab/redis/cache_spec.rb index bc33bbe115a..31141ac1139 100644 --- a/spec/lib/gitlab/redis/cache_spec.rb +++ b/spec/lib/gitlab/redis/cache_spec.rb @@ -5,7 +5,14 @@ require 'spec_helper' RSpec.describe Gitlab::Redis::Cache do let(:instance_specific_config_file) { "config/redis.cache.yml" } let(:environment_config_file_name) { "GITLAB_REDIS_CACHE_CONFIG_FILE" } - let(:class_redis_url) { 'redis://localhost:6380' } include_examples "redis_shared_examples" + + describe '#raw_config_hash' do + it 'has a legacy default URL' do + expect(subject).to receive(:fetch_config) { false } + + expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:6380' ) + end + end end diff --git a/spec/lib/gitlab/redis/queues_spec.rb b/spec/lib/gitlab/redis/queues_spec.rb index 85fca9320cf..2e396cde3bf 100644 --- a/spec/lib/gitlab/redis/queues_spec.rb +++ b/spec/lib/gitlab/redis/queues_spec.rb @@ -5,7 +5,14 @@ require 'spec_helper' RSpec.describe Gitlab::Redis::Queues do let(:instance_specific_config_file) { "config/redis.queues.yml" } let(:environment_config_file_name) { "GITLAB_REDIS_QUEUES_CONFIG_FILE" } - let(:class_redis_url) { 'redis://localhost:6381' } include_examples "redis_shared_examples" + + describe '#raw_config_hash' do + it 'has a legacy default URL' do + expect(subject).to receive(:fetch_config) { false } + + expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:6381' ) + end + end end diff --git a/spec/lib/gitlab/redis/shared_state_spec.rb b/spec/lib/gitlab/redis/shared_state_spec.rb index 2543c4d9678..d240abfbf5b 100644 --- a/spec/lib/gitlab/redis/shared_state_spec.rb +++ b/spec/lib/gitlab/redis/shared_state_spec.rb @@ -5,7 +5,14 @@ require 'spec_helper' RSpec.describe Gitlab::Redis::SharedState do let(:instance_specific_config_file) { "config/redis.shared_state.yml" } let(:environment_config_file_name) { "GITLAB_REDIS_SHARED_STATE_CONFIG_FILE" } - let(:class_redis_url) { 'redis://localhost:6382' } include_examples "redis_shared_examples" + + describe '#raw_config_hash' do + it 'has a legacy default URL' do + expect(subject).to receive(:fetch_config) { false } + + expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:6382' ) + end + end end diff --git a/spec/lib/gitlab/redis/wrapper_spec.rb b/spec/lib/gitlab/redis/wrapper_spec.rb index 39156d06849..dd1f0d8b414 100644 --- a/spec/lib/gitlab/redis/wrapper_spec.rb +++ b/spec/lib/gitlab/redis/wrapper_spec.rb @@ -8,10 +8,4 @@ RSpec.describe Gitlab::Redis::Wrapper do expect { described_class.instrumentation_class }.to raise_error(NameError) end end - - describe '.default_url' do - it 'is not implemented' do - expect { described_class.default_url }.to raise_error(NotImplementedError) - end - end end |