diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-10-28 18:01:17 +0100 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-12-03 21:26:49 +0100 |
commit | 72347448db55f738407d468833bbb98fe56ff677 (patch) | |
tree | 741701ababd520af43347dc6d75d4f67f38e0c55 /spec/lib | |
parent | 01c7cb90dabc095ae9d343e7af889c43e895c7c1 (diff) | |
download | gitlab-ce-72347448db55f738407d468833bbb98fe56ff677.tar.gz |
More specs for fallback testing.
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/database/count_spec.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database/count_spec.rb b/spec/lib/gitlab/database/count_spec.rb index 1e1749b9b14..b31856fd675 100644 --- a/spec/lib/gitlab/database/count_spec.rb +++ b/spec/lib/gitlab/database/count_spec.rb @@ -27,6 +27,39 @@ describe Gitlab::Database::Count do end context 'fallbacks' do + subject { described_class.approximate_counts(models, strategies: strategies) } + + let(:strategies) do + [ + double('s1', :enabled? => true, new: first_strategy), + double('s2', :enabled? => true, new: second_strategy) + ] + end + + let(:first_strategy) { double('first strategy', count: {}) } + let(:second_strategy) { double('second strategy', count: {}) } + + it 'gets results from first strategy' do + expect(strategies[0]).to receive(:new).with(models).and_return(first_strategy) + expect(first_strategy).to receive(:count) + + subject + end + + it 'gets more results from second strategy if some counts are missing' do + expect(first_strategy).to receive(:count).and_return({ Project => 3 }) + expect(strategies[1]).to receive(:new).with([Identity]).and_return(second_strategy) + expect(second_strategy).to receive(:count).and_return({ Identity => 1 }) + + expect(subject).to eq({ Project => 3, Identity => 1 }) + end + + it 'does not get more results as soon as all counts are present' do + expect(first_strategy).to receive(:count).and_return({ Project => 3, Identity => 1 }) + expect(strategies[1]).not_to receive(:new) + + subject + end end context 'with PostgreSQL', :postgresql do |