1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/test/testing_inline.rb
Mike Perham 29dca70e24
Introduce Sidekiq::Capsule (#5487)
* Initial work on Sidekiq::Config

* Initial work on Sidekiq::Config

* reduce dependencies in deploy marks

* bare sidekiq and webapp

* Modify runtime to work with Capsules

* Cleanup

* Rename test files to remove test_ prefix

* Update test suite and standard rules to be more compliant

* Move constant definition outside code, per standard formatting

* Loads of changes for introduction of Capsules

* Remove Redis adapter abstraction

* update capsule overview

* Ensure Sidekiq.redis uses the correct pool for jobs running within a Capsule

* Use default_capsule for safety

* Slow down the beat to halve its Redis overhead

* move config fixtures into cfg/

* Add capsule middleware test

* use accessor
2022-08-25 10:15:11 -07:00

61 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require_relative "helper"
class InlineError < RuntimeError; end
class ParameterIsNotString < RuntimeError; end
class InlineWorker
include Sidekiq::Job
def perform(pass)
raise ArgumentError, "no jid" unless jid
raise InlineError unless pass
end
end
class InlineWorkerWithTimeParam
include Sidekiq::Job
def perform(time)
raise ParameterIsNotString unless time.is_a?(String) || time.is_a?(Numeric)
end
end
describe "Sidekiq::Testing.inline" do
before do
require "sidekiq/testing/inline"
Sidekiq::Testing.inline!
end
after do
Sidekiq::Testing.disable!
end
it "stubs the async call when in testing mode" do
assert InlineWorker.perform_async(true)
assert_raises InlineError do
InlineWorker.perform_async(false)
end
end
it "stubs the enqueue call when in testing mode" do
assert Sidekiq::Client.enqueue(InlineWorker, true)
assert_raises InlineError do
Sidekiq::Client.enqueue(InlineWorker, false)
end
end
it "stubs the push_bulk call when in testing mode" do
assert Sidekiq::Client.push_bulk({"class" => InlineWorker, "args" => [[true], [true]]})
assert_raises InlineError do
Sidekiq::Client.push_bulk({"class" => InlineWorker, "args" => [[true], [false]]})
end
end
it "should relay parameters through json" do
assert Sidekiq::Client.enqueue(InlineWorkerWithTimeParam, Time.now.to_f)
end
end