1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/test/exception_handler.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

50 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require_relative "helper"
require "sidekiq/component"
require "stringio"
require "logger"
ExceptionHandlerTestException = Class.new(StandardError)
TEST_EXCEPTION = ExceptionHandlerTestException.new("Something didn't work!")
class Thing
include Sidekiq::Component
attr_reader :config
def initialize(config)
@config = config
end
def invoke_exception(args)
raise TEST_EXCEPTION
rescue ExceptionHandlerTestException => e
handle_exception(e, args)
end
end
describe Sidekiq::Component do
describe "with mock logger" do
before do
@config = reset!
end
it "logs the exception to Sidekiq.logger" do
output = capture_logging(@config) do
Thing.new(@config).invoke_exception(a: 1)
end
assert_match(/"a":1/, output, "didn't include the context")
assert_match(/Something didn't work!/, output, "didn't include the exception message")
assert_match(/test\/exception_handler.rb/, output, "didn't include the backtrace")
end
describe "when the exception does not have a backtrace" do
it "does not fail" do
exception = ExceptionHandlerTestException.new
assert_nil exception.backtrace
Thing.new(@config).handle_exception exception
end
end
end
end