debian-mirror-gitlab/spec/lib/gitlab/sidekiq_middleware/monitor_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::SidekiqMiddleware::Monitor do
2019-12-04 20:38:33 +05:30
let(:monitor) { described_class.new }
describe '#call' do
let(:worker) { double }
let(:job) { { 'jid' => 'job-id' } }
let(:queue) { 'my-queue' }
it 'calls Gitlab::SidekiqDaemon::Monitor' do
expect(Gitlab::SidekiqDaemon::Monitor.instance).to receive(:within_job)
2019-12-21 20:55:43 +05:30
.with(anything, 'job-id', 'my-queue')
2019-12-04 20:38:33 +05:30
.and_call_original
expect { |blk| monitor.call(worker, job, queue, &blk) }.to yield_control
end
it 'passthroughs the return value' do
result = monitor.call(worker, job, queue) do
'value'
end
expect(result).to eq('value')
end
context 'when cancel happens' do
subject do
monitor.call(worker, job, queue) do
raise Gitlab::SidekiqDaemon::Monitor::CancelledError
end
end
it 'skips the job' do
expect { subject }.to raise_error(Sidekiq::JobRetry::Skip)
end
it 'puts job in DeadSet' do
::Sidekiq::DeadSet.new.clear
expect do
2022-08-27 11:52:29 +05:30
subject
rescue Sidekiq::JobRetry::Skip
nil
2019-12-04 20:38:33 +05:30
end.to change { ::Sidekiq::DeadSet.new.size }.by(1)
end
end
end
end