diff options
Diffstat (limited to 'spec/lib/gitlab/import/metrics_spec.rb')
-rw-r--r-- | spec/lib/gitlab/import/metrics_spec.rb | 108 |
1 files changed, 101 insertions, 7 deletions
diff --git a/spec/lib/gitlab/import/metrics_spec.rb b/spec/lib/gitlab/import/metrics_spec.rb index 0a912427014..035294a620f 100644 --- a/spec/lib/gitlab/import/metrics_spec.rb +++ b/spec/lib/gitlab/import/metrics_spec.rb @@ -2,20 +2,67 @@ require 'spec_helper' -RSpec.describe Gitlab::Import::Metrics do +RSpec.describe Gitlab::Import::Metrics, :aggregate_failures do let(:importer) { :test_importer } - let(:project) { create(:project) } + let(:project) { build(:project, id: non_existing_record_id, created_at: Time.current) } let(:histogram) { double(:histogram) } let(:counter) { double(:counter) } subject { described_class.new(importer, project) } - describe '#report_import_time' do + before do + allow(Gitlab::Metrics).to receive(:counter) { counter } + allow(counter).to receive(:increment) + allow(histogram).to receive(:observe) + end + + describe '#track_start_import' do + context 'when project is not a github import' do + it 'does not emit importer metrics' do + expect(subject).not_to receive(:track_usage_event) + + subject.track_start_import + end + end + + context 'when project is a github import' do + before do + project.import_type = 'github' + end + + it 'emits importer metrics' do + expect(subject).to receive(:track_usage_event).with(:github_import_project_start, project.id) + + subject.track_start_import + end + end + end + + describe '#track_failed_import' do + context 'when project is not a github import' do + it 'does not emit importer metrics' do + expect(subject).not_to receive(:track_usage_event) + + subject.track_failed_import + end + end + + context 'when project is a github import' do + before do + project.import_type = 'github' + end + + it 'emits importer metrics' do + expect(subject).to receive(:track_usage_event).with(:github_import_project_failure, project.id) + + subject.track_failed_import + end + end + end + + describe '#track_finished_import' do before do - allow(Gitlab::Metrics).to receive(:counter) { counter } allow(Gitlab::Metrics).to receive(:histogram) { histogram } - allow(counter).to receive(:increment) - allow(counter).to receive(:observe) end it 'emits importer metrics' do @@ -32,9 +79,56 @@ RSpec.describe Gitlab::Import::Metrics do ) expect(counter).to receive(:increment) - expect(histogram).to receive(:observe).with({ importer: :test_importer }, anything) subject.track_finished_import + + expect(subject.duration).not_to be_nil + end + + context 'when project is not a github import' do + it 'does not emit importer metrics' do + expect(subject).not_to receive(:track_usage_event) + + subject.track_finished_import + + expect(histogram).to have_received(:observe).with({ importer: :test_importer }, anything) + end + end + + context 'when project is a github import' do + before do + project.import_type = 'github' + end + + it 'emits importer metrics' do + expect(subject).to receive(:track_usage_event).with(:github_import_project_success, project.id) + + subject.track_finished_import + + expect(histogram).to have_received(:observe).with({ project: project.full_path }, anything) + end + end + end + + describe '#issues_counter' do + it 'creates a counter for issues' do + expect(Gitlab::Metrics).to receive(:counter).with( + :test_importer_imported_issues_total, + 'The number of imported issues' + ) + + subject.issues_counter + end + end + + describe '#merge_requests_counter' do + it 'creates a counter for issues' do + expect(Gitlab::Metrics).to receive(:counter).with( + :test_importer_imported_merge_requests_total, + 'The number of imported merge (pull) requests' + ) + + subject.merge_requests_counter end end end |