debian-mirror-gitlab/spec/workers/concerns/waitable_worker_spec.rb

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

54 lines
1.1 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe WaitableWorker, feature_category: :shared do
2018-03-27 19:54:05 +05:30
let(:worker) do
Class.new do
def self.name
'Gitlab::Foo::Bar::DummyWorker'
end
2018-11-08 19:23:39 +05:30
cattr_accessor(:counter) { 0 }
2018-03-27 19:54:05 +05:30
include ApplicationWorker
prepend WaitableWorker
2018-11-18 11:00:15 +05:30
def perform(count = 0)
self.class.counter += count
2018-03-27 19:54:05 +05:30
end
end
end
subject(:job) { worker.new }
describe '#perform' do
shared_examples 'perform' do
it 'notifies the JobWaiter when done if the key is provided' do
key = Gitlab::JobWaiter.new.key
expect(Gitlab::JobWaiter).to receive(:notify).with(key, job.jid)
job.perform(*args, key)
end
it 'does not notify the JobWaiter when done if no key is provided' do
expect(Gitlab::JobWaiter).not_to receive(:notify)
job.perform(*args)
end
end
context 'when the worker takes arguments' do
let(:args) { [1] }
it_behaves_like 'perform'
end
context 'when the worker takes no arguments' do
let(:args) { [] }
it_behaves_like 'perform'
end
end
end