diff options
Diffstat (limited to 'spec/lib/gitlab/sidekiq_status')
-rw-r--r-- | spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb b/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb index 2f2499753b9..cb1616ec40a 100644 --- a/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb +++ b/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb @@ -1,24 +1,61 @@ # frozen_string_literal: true -require 'fast_spec_helper' +# This can use fast_spec_helper when the feature flag stubbing is removed. +require 'spec_helper' -RSpec.describe Gitlab::SidekiqStatus::ClientMiddleware do +RSpec.describe Gitlab::SidekiqStatus::ClientMiddleware, :clean_gitlab_redis_queues do describe '#call' do - context 'when the job has status_expiration set' do - it 'tracks the job in Redis with a value of 2' do - expect(Gitlab::SidekiqStatus).to receive(:set).with('123', 1.hour.to_i, value: 2) + context 'when opt_in_sidekiq_status is disabled' do + before do + stub_feature_flags(opt_in_sidekiq_status: false) + end + + context 'when the job has status_expiration set' do + it 'tracks the job in Redis' do + expect(Gitlab::SidekiqStatus).to receive(:set).with('123', 1.hour.to_i).and_call_original + + described_class.new + .call('Foo', { 'jid' => '123', 'status_expiration' => 1.hour.to_i }, double(:queue), double(:pool)) { nil } + + expect(Gitlab::SidekiqStatus.num_running(['123'])).to eq(1) + end + end + + context 'when the job does not have status_expiration set' do + it 'tracks the job in Redis' do + expect(Gitlab::SidekiqStatus).to receive(:set).with('123', 30.minutes.to_i).and_call_original + + described_class.new + .call('Foo', { 'jid' => '123' }, double(:queue), double(:pool)) { nil } - described_class.new - .call('Foo', { 'jid' => '123', 'status_expiration' => 1.hour.to_i }, double(:queue), double(:pool)) { nil } + expect(Gitlab::SidekiqStatus.num_running(['123'])).to eq(1) + end end end - context 'when the job does not have status_expiration set' do - it 'tracks the job in Redis with a value of 1' do - expect(Gitlab::SidekiqStatus).to receive(:set).with('123', Gitlab::SidekiqStatus::DEFAULT_EXPIRATION, value: 1) + context 'when opt_in_sidekiq_status is enabled' do + before do + stub_feature_flags(opt_in_sidekiq_status: true) + end + + context 'when the job has status_expiration set' do + it 'tracks the job in Redis' do + expect(Gitlab::SidekiqStatus).to receive(:set).with('123', 1.hour.to_i).and_call_original + + described_class.new + .call('Foo', { 'jid' => '123', 'status_expiration' => 1.hour.to_i }, double(:queue), double(:pool)) { nil } + + expect(Gitlab::SidekiqStatus.num_running(['123'])).to eq(1) + end + end + + context 'when the job does not have status_expiration set' do + it 'does not track the job in Redis' do + described_class.new + .call('Foo', { 'jid' => '123' }, double(:queue), double(:pool)) { nil } - described_class.new - .call('Foo', { 'jid' => '123' }, double(:queue), double(:pool)) { nil } + expect(Gitlab::SidekiqStatus.num_running(['123'])).to be_zero + end end end end |