require 'job_uniqueness/spec_helper' RSpec.shared_context "lock strategy specs" do |strategy:| include_context 'with TestWorker' before(:each) { TestWorker.unique_job_options[:strategy] = strategy } let(:context1) { CanvasSync::JobUniqueness::LockContext.new({ jid: 'j1', queue: 'default', job_clazz: 'TestWorker'}) } let(:context2) { CanvasSync::JobUniqueness::LockContext.new({ jid: 'j2', queue: 'default', job_clazz: 'TestWorker'}) } let(:process_one) { described_class.new(context1) } let(:process_two) { described_class.new(context2) } end RSpec.shared_examples "a lock implementation" do it "is unlocked when done" do process_one.on_enqueue {} did_lock = process_one.locked? process_one.on_perform {} did_lock ||= process_one.locked? expect(did_lock).to be_truthy process_one.batch_callback(:success, nil) expect(process_one).not_to be_locked end end