Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-06 06:09:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-06 06:09:33 +0300
commit6c005ae9783ad6752e3082d05e1053d20d8da92a (patch)
treed99b44427d04388442363deca27c7f6b4fd0af77 /spec
parentde088a681f5db1fd2f4be56bf59925312705bb72 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/usage_ping_controller_spec.rb2
-rw-r--r--spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb34
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb32
3 files changed, 45 insertions, 23 deletions
diff --git a/spec/controllers/projects/usage_ping_controller_spec.rb b/spec/controllers/projects/usage_ping_controller_spec.rb
index 284db93d7a8..43a2020b7aa 100644
--- a/spec/controllers/projects/usage_ping_controller_spec.rb
+++ b/spec/controllers/projects/usage_ping_controller_spec.rb
@@ -42,7 +42,7 @@ describe Projects::UsagePingController do
it 'increments the counter' do
expect do
subject
- end.to change { Gitlab::UsageDataCounters::WebIdeCounter.total_previews_count }.by(1)
+ end.to change { Gitlab::UsageDataCounters::WebIdeCounter.total_count('WEB_IDE_PREVIEWS_COUNT') }.by(1)
end
end
end
diff --git a/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb
index 96ebeb8ff76..920d1d23567 100644
--- a/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb
+++ b/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb
@@ -3,35 +3,27 @@
require 'spec_helper'
describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_state do
- shared_examples 'counter examples' do
+ shared_examples 'counter examples' do |event|
it 'increments counter and return the total count' do
- expect(described_class.public_send(total_counter_method)).to eq(0)
+ expect(described_class.public_send(:total_count, event)).to eq(0)
- 2.times { described_class.public_send(increment_counter_method) }
+ 2.times { described_class.public_send(:"increment_#{event}_count") }
- expect(described_class.public_send(total_counter_method)).to eq(2)
+ redis_key = "web_ide_#{event}_count".upcase
+ expect(described_class.public_send(:total_count, redis_key)).to eq(2)
end
end
describe 'commits counter' do
- let(:increment_counter_method) { :increment_commits_count }
- let(:total_counter_method) { :total_commits_count }
-
- it_behaves_like 'counter examples'
+ it_behaves_like 'counter examples', 'commits'
end
describe 'merge requests counter' do
- let(:increment_counter_method) { :increment_merge_requests_count }
- let(:total_counter_method) { :total_merge_requests_count }
-
- it_behaves_like 'counter examples'
+ it_behaves_like 'counter examples', 'merge_requests'
end
describe 'views counter' do
- let(:increment_counter_method) { :increment_views_count }
- let(:total_counter_method) { :total_views_count }
-
- it_behaves_like 'counter examples'
+ it_behaves_like 'counter examples', 'views'
end
describe 'previews counter' do
@@ -42,21 +34,19 @@ describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_st
end
context 'when web ide clientside preview is enabled' do
- let(:increment_counter_method) { :increment_previews_count }
- let(:total_counter_method) { :total_previews_count }
-
- it_behaves_like 'counter examples'
+ it_behaves_like 'counter examples', 'previews'
end
context 'when web ide clientside preview is not enabled' do
let(:setting_enabled) { false }
it 'does not increment the counter' do
- expect(described_class.total_previews_count).to eq(0)
+ redis_key = 'WEB_IDE_PREVIEWS_COUNT'
+ expect(described_class.total_count(redis_key)).to eq(0)
2.times { described_class.increment_previews_count }
- expect(described_class.total_previews_count).to eq(0)
+ expect(described_class.total_count(redis_key)).to eq(0)
end
end
end
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index ddbc4240f10..ea7ff5d61b3 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -116,6 +116,7 @@ describe Gitlab::UsageData, :aggregate_failures do
subject { described_class.usage_data_counters }
it { is_expected.to all(respond_to :totals) }
+ it { is_expected.to all(respond_to :fallback_totals) }
describe 'the results of calling #totals on all objects in the array' do
subject { described_class.usage_data_counters.map(&:totals) }
@@ -124,6 +125,13 @@ describe Gitlab::UsageData, :aggregate_failures do
it { is_expected.to all(have_attributes(keys: all(be_a Symbol), values: all(be_a Integer))) }
end
+ describe 'the results of calling #fallback_totals on all objects in the array' do
+ subject { described_class.usage_data_counters.map(&:fallback_totals) }
+
+ it { is_expected.to all(be_a Hash) }
+ it { is_expected.to all(have_attributes(keys: all(be_a Symbol), values: all(eq(-1)))) }
+ end
+
it 'does not have any conflicts' do
all_keys = subject.flat_map { |counter| counter.totals.keys }
@@ -576,4 +584,28 @@ describe Gitlab::UsageData, :aggregate_failures do
expect(described_class.alt_usage_data(1)).to eq 1
end
end
+
+ describe '#redis_usage_data' do
+ context 'with block given' do
+ it 'returns the fallback when it gets an error' do
+ expect(described_class.redis_usage_data { raise ::Redis::CommandError } ).to eq(-1)
+ end
+
+ it 'returns the evaluated block when given' do
+ expect(described_class.redis_usage_data { 1 }).to eq(1)
+ end
+ end
+
+ context 'with counter given' do
+ it 'returns the falback values for all counter keys when it gets an error' do
+ allow(::Gitlab::UsageDataCounters::WikiPageCounter).to receive(:totals).and_raise(::Redis::CommandError)
+ expect(described_class.redis_usage_data(::Gitlab::UsageDataCounters::WikiPageCounter)).to eql(::Gitlab::UsageDataCounters::WikiPageCounter.fallback_totals)
+ end
+
+ it 'returns the totals when couter is given' do
+ allow(::Gitlab::UsageDataCounters::WikiPageCounter).to receive(:totals).and_return({ wiki_pages_create: 2 })
+ expect(described_class.redis_usage_data(::Gitlab::UsageDataCounters::WikiPageCounter)).to eql({ wiki_pages_create: 2 })
+ end
+ end
+ end
end