Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplify middleware testing

  • Loading branch information...
commit 8adba078879d2006efc26c6f8653ea360f6b7eb3 1 parent 5ec8ac0
@mperham mperham authored
View
4 lib/sidekiq/middleware/chain.rb
@@ -64,6 +64,10 @@ def retrieve
entries.map(&:make_new)
end
+ def clear
+ entries.clear
+ end
+
def invoke(*args, &final_action)
chain = retrieve.dup
traverse_chain = lambda do
View
20 test/test_middleware.rb
@@ -6,9 +6,22 @@
class TestMiddleware < MiniTest::Unit::TestCase
describe 'middleware chain' do
before do
+ $errors = []
Sidekiq.redis = REDIS
end
+ it 'handles errors' do
+ handler = Sidekiq::Middleware::Server::ExceptionHandler.new
+
+ assert_raises ArgumentError do
+ handler.call('', { :a => 1 }, 'default') do
+ raise ArgumentError
+ end
+ end
+ assert_equal 1, $errors.size
+ assert_equal({ :a => 1 }, $errors[0][:parameters])
+ end
+
class CustomMiddleware
def initialize(name, recorder)
@name = name
@@ -70,3 +83,10 @@ def call(*args)
end
end
end
+
+class FakeAirbrake
+ def self.notify(ex, hash)
+ $errors << hash
+ end
+end
+Airbrake = FakeAirbrake
View
20 test/test_processor.rb
@@ -28,25 +28,5 @@ def perform(args)
assert_equal 1, $invokes
assert_equal 0, $errors.size
end
-
- it 'handles exceptions' do
- msg = { 'class' => MockWorker.to_s, 'args' => ['boom'] }
- processor = ::Sidekiq::Processor.new(@boss)
- assert_raises RuntimeError do
- processor.process(msg, 'default')
- end
- @boss.verify
- assert_equal 0, $invokes
- assert_equal 1, $errors.size
- assert_equal msg, $errors[0][:parameters]
- end
-
- end
-end
-
-class FakeAirbrake
- def self.notify(ex, hash)
- $errors << hash
end
end
-Airbrake = FakeAirbrake
Please sign in to comment.
Something went wrong with that request. Please try again.