diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/workers/analytics/usage_trends/counter_job_worker_spec.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/workers/analytics/usage_trends/counter_job_worker_spec.rb')
-rw-r--r-- | spec/workers/analytics/usage_trends/counter_job_worker_spec.rb | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/spec/workers/analytics/usage_trends/counter_job_worker_spec.rb b/spec/workers/analytics/usage_trends/counter_job_worker_spec.rb index c45ec20fe5a..ee1bbafa9b5 100644 --- a/spec/workers/analytics/usage_trends/counter_job_worker_spec.rb +++ b/spec/workers/analytics/usage_trends/counter_job_worker_spec.rb @@ -48,11 +48,43 @@ RSpec.describe Analytics::UsageTrends::CounterJobWorker do end it 'does not insert anything when BatchCount returns error' do - allow(Gitlab::Database::BatchCount).to receive(:batch_count).and_return(Gitlab::Database::BatchCounter::FALLBACK) + allow(Gitlab::Database::BatchCount).to receive(:batch_count_with_timeout) + .and_return({ status: :canceled }) expect { subject }.not_to change { Analytics::UsageTrends::Measurement.count } end + context 'when the timeout elapses' do + let(:min_id) { 1 } + let(:max_id) { 12345 } + let(:continue_from) { 321 } + let(:partial_results) { 42 } + let(:final_count) { 123 } + + subject { described_class.new.perform(users_measurement_identifier, min_id, max_id, recorded_at) } + + it 'continues counting later when the timeout elapses' do + expect(Gitlab::Database::BatchCount).to receive(:batch_count_with_timeout) + .with(anything, start: min_id, finish: max_id, timeout: 250.seconds, partial_results: nil) + .and_return({ status: :timeout, partial_results: partial_results, continue_from: continue_from }) + + expect(described_class).to receive(:perform_async).with(anything, continue_from, max_id, recorded_at, partial_results) do |*args| + described_class.new.perform(*args) + end + + expect(Gitlab::Database::BatchCount).to receive(:batch_count_with_timeout) + .with(anything, start: continue_from, finish: max_id, timeout: 250.seconds, partial_results: partial_results) + .and_return({ status: :completed, count: final_count }) + + expect { subject }.to change { Analytics::UsageTrends::Measurement.count } + + measurement = Analytics::UsageTrends::Measurement.users.last + expect(measurement.recorded_at).to be_like_time(recorded_at) + expect(measurement.identifier).to eq('users') + expect(measurement.count).to eq(final_count) + end + end + context 'when pipelines_succeeded identifier is passed' do let_it_be(:pipeline) { create(:ci_pipeline, :success) } |