diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 03:09:12 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 03:09:12 +0300 |
commit | d43aaf286fe6b8e8383e73ea580274d8841608d7 (patch) | |
tree | ca03542a55583538a1ec13023dffed20457407b5 /spec/lib/gitlab | |
parent | 87af6f2e0590af0ed1bb3e5de1bb5d21855a94d2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_middleware_spec.rb | 20 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_spec.rb | 16 |
3 files changed, 37 insertions, 1 deletions
diff --git a/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb b/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb index 23c5b59922b..3343587beff 100644 --- a/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb +++ b/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb @@ -67,7 +67,7 @@ describe Gitlab::SidekiqMiddleware::ServerMetrics do allow(Gitlab::Metrics::System).to receive(:monotonic_time).and_return(monotonic_time_before, monotonic_time_after) allow(Gitlab::InstrumentationHelper).to receive(:queue_duration_for_job).with(job).and_return(queue_duration_for_job) allow(ActiveRecord::LogSubscriber).to receive(:runtime).and_return(db_duration * 1000) - allow(Gitlab::GitalyClient).to receive(:query_time).and_return(gitaly_duration) + allow(subject).to receive(:get_gitaly_time).and_return(gitaly_duration) expect(running_jobs_metric).to receive(:increment).with(labels, 1) expect(running_jobs_metric).to receive(:increment).with(labels, -1) diff --git a/spec/lib/gitlab/sidekiq_middleware_spec.rb b/spec/lib/gitlab/sidekiq_middleware_spec.rb index 2f325fd5052..88f83ebc2ac 100644 --- a/spec/lib/gitlab/sidekiq_middleware_spec.rb +++ b/spec/lib/gitlab/sidekiq_middleware_spec.rb @@ -8,6 +8,8 @@ describe Gitlab::SidekiqMiddleware do include Sidekiq::Worker def perform(_arg) + Gitlab::SafeRequestStore['gitaly_call_actual'] = 1 + Gitlab::GitalyClient.query_time = 5 end end @@ -99,6 +101,24 @@ describe Gitlab::SidekiqMiddleware do it "passes through server middlewares" do worker_class.perform_async(*job_args) end + + context "server metrics" do + let(:gitaly_histogram) { double(:gitaly_histogram) } + + before do + allow(Gitlab::Metrics).to receive(:histogram).and_call_original + + allow(Gitlab::Metrics).to receive(:histogram) + .with(:sidekiq_jobs_gitaly_seconds, anything, anything, anything) + .and_return(gitaly_histogram) + end + + it "records correct Gitaly duration" do + expect(gitaly_histogram).to receive(:observe).with(anything, 5.0) + + worker_class.perform_async(*job_args) + end + end end end diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 113cb4ba6bf..21117f11f63 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -387,6 +387,22 @@ describe Gitlab::UsageData do expect(described_class.count(relation, fallback: 15, batch: false)).to eq(15) end end + + describe '#distinct_count' do + let(:relation) { double(:relation) } + + it 'returns the count when counting succeeds' do + allow(relation).to receive(:distinct_count_by).and_return(1) + + expect(described_class.distinct_count(relation, batch: false)).to eq(1) + end + + it 'returns the fallback value when counting fails' do + allow(relation).to receive(:distinct_count_by).and_raise(ActiveRecord::StatementInvalid.new('')) + + expect(described_class.distinct_count(relation, fallback: 15, batch: false)).to eq(15) + end + end end end end |