diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 06:07:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 06:07:58 +0300 |
commit | 1eeef229aae5affdce415c2364858e8efc64f4b5 (patch) | |
tree | 7bbd126a3b41c4c8855a8e84ece3972030177acb /spec | |
parent | 5d32a7a175fd1a7a6c97019a022c11434ea637dc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/bitbucket_import/importer_spec.rb | 68 | ||||
-rw-r--r-- | spec/lib/gitlab/import/metrics_spec.rb | 56 | ||||
-rw-r--r-- | spec/services/projects/import_service_spec.rb | 20 |
3 files changed, 140 insertions, 4 deletions
diff --git a/spec/lib/gitlab/bitbucket_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importer_spec.rb index b95175efc0c..b3c1f86c5ee 100644 --- a/spec/lib/gitlab/bitbucket_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/importer_spec.rb @@ -87,6 +87,7 @@ describe Gitlab::BitbucketImport::Importer do values: sample_issues_statuses } end + let(:counter) { double('counter', increment: true) } subject { described_class.new(project) } @@ -213,6 +214,24 @@ describe Gitlab::BitbucketImport::Importer do expect(merge_request_diff.start_commit_sha).to eq target_branch_sha end end + + context 'metrics' do + before do + allow(Gitlab::Metrics).to receive(:counter) { counter } + allow(pull_request).to receive(:raw).and_return('hello world') + end + + it 'counts imported pull requests' do + expect(Gitlab::Metrics).to receive(:counter).with( + :bitbucket_importer_imported_pull_requests, + 'The number of imported Bitbucket pull requests' + ) + + expect(counter).to receive(:increment) + + subject.execute + end + end end context 'issues statuses' do @@ -339,5 +358,54 @@ describe Gitlab::BitbucketImport::Importer do expect(importer.errors).to be_empty end end + + context 'metrics' do + before do + allow(Gitlab::Metrics).to receive(:counter) { counter } + end + + it 'counts imported issues' do + expect(Gitlab::Metrics).to receive(:counter).with( + :bitbucket_importer_imported_issues, + 'The number of imported Bitbucket issues' + ) + + expect(counter).to receive(:increment) + + subject.execute + end + end + end + + describe '#execute' do + context 'metrics' do + let(:histogram) { double(:histogram) } + + before do + allow(subject).to receive(:import_wiki) + allow(subject).to receive(:import_issues) + allow(subject).to receive(:import_pull_requests) + + allow(Gitlab::Metrics).to receive(:counter) { counter } + allow(Gitlab::Metrics).to receive(:histogram) { histogram } + end + + it 'counts and measures duration of imported projects' do + expect(Gitlab::Metrics).to receive(:counter).with( + :bitbucket_importer_imported_projects, + 'The number of imported Bitbucket projects' + ) + + expect(Gitlab::Metrics).to receive(:histogram).with( + :bitbucket_importer_total_duration_seconds, + 'Total time spent importing Bitbucket projects, in seconds' + ) + + expect(counter).to receive(:increment) + expect(histogram).to receive(:observe).with({ importer: described_class::IMPORTER }, anything) + + subject.execute + end + end end end diff --git a/spec/lib/gitlab/import/metrics_spec.rb b/spec/lib/gitlab/import/metrics_spec.rb new file mode 100644 index 00000000000..0799d19fcef --- /dev/null +++ b/spec/lib/gitlab/import/metrics_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Import::Metrics do + let(:importer_stub) do + Class.new do + prepend Gitlab::Import::Metrics + + Gitlab::Import::Metrics.measure :execute, metrics: { + importer_counter: { + type: :counter, + description: 'description' + }, + importer_histogram: { + type: :histogram, + labels: { importer: 'importer' }, + description: 'description' + } + } + + def execute + true + end + end + end + + subject { importer_stub.new.execute } + + describe '#execute' do + let(:counter) { double(:counter) } + let(:histogram) { double(:histogram) } + + it 'increments counter metric' do + expect(Gitlab::Metrics) + .to receive(:counter) + .with(:importer_counter, 'description') + .and_return(counter) + + expect(counter).to receive(:increment) + + subject + end + + it 'measures method duration and reports histogram metric' do + expect(Gitlab::Metrics) + .to receive(:histogram) + .with(:importer_histogram, 'description') + .and_return(histogram) + + expect(histogram).to receive(:observe).with({ importer: 'importer' }, anything) + + subject + end + end +end diff --git a/spec/services/projects/import_service_spec.rb b/spec/services/projects/import_service_spec.rb index 1e9ac40128a..af8118f9b11 100644 --- a/spec/services/projects/import_service_spec.rb +++ b/spec/services/projects/import_service_spec.rb @@ -123,8 +123,13 @@ describe Projects::ImportService do it 'succeeds if repository import is successful' do expect(project.repository).to receive(:import_repository).and_return(true) - expect_any_instance_of(Gitlab::BitbucketImport::Importer).to receive(:execute).and_return(true) - expect_any_instance_of(Projects::LfsPointers::LfsImportService).to receive(:execute).and_return(status: :success) + expect_next_instance_of(Gitlab::BitbucketImport::Importer) do |importer| + expect(importer).to receive(:execute).and_return(true) + end + + expect_next_instance_of(Projects::LfsPointers::LfsImportService) do |service| + expect(service).to receive(:execute).and_return(status: :success) + end result = subject.execute @@ -147,8 +152,15 @@ describe Projects::ImportService do error_message = 'error message' expect(project.repository).to receive(:import_repository).and_return(true) - expect_any_instance_of(Gitlab::BitbucketImport::Importer).to receive(:execute).and_return(true) - expect_any_instance_of(Projects::LfsPointers::LfsImportService).to receive(:execute).and_return(status: :error, message: error_message) + + expect_next_instance_of(Gitlab::BitbucketImport::Importer) do |importer| + expect(importer).to receive(:execute).and_return(true) + end + + expect_next_instance_of(Projects::LfsPointers::LfsImportService) do |service| + expect(service).to receive(:execute).and_return(status: :error, message: error_message) + end + expect(Gitlab::AppLogger).to receive(:error).with("The Lfs import process failed. #{error_message}") subject.execute |