Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Middleware tests

  • Loading branch information...
commit 19d2c99b62e21f4dc32381787705a1245cb17e42 1 parent 3241a0e
@mhfs authored
View
6 lib/sidekiq/failures.rb
@@ -11,8 +11,6 @@ module Failures
Sidekiq::Web.register Sidekiq::Failures::WebExtension
Sidekiq::Web.tabs << "Failures"
-Sidekiq.configure_server do |config|
- config.server_middleware do |chain|
- chain.add Sidekiq::Failures::Middleware
- end
+Sidekiq.server_middleware do |chain|
+ chain.add Sidekiq::Failures::Middleware
end
View
2  lib/sidekiq/failures/middleware.rb
@@ -14,7 +14,7 @@ def call(worker, msg, queue)
:queue => queue
}
- Sidekiq.redis {|conn| conn.rpush(:failed, Sidekiq.dump_json(data)) }
+ Sidekiq.redis { |conn| conn.rpush(:failed, Sidekiq.dump_json(data)) }
raise
end
View
41 test/middleware_test.rb
@@ -0,0 +1,41 @@
+require "test_helper"
+
+module Sidekiq
+ module Failures
+ describe "Middleware" do
+ TestException = Class.new(StandardError)
+
+ before do
+ $invokes = 0
+ boss = MiniTest::Mock.new
+ @processor = ::Sidekiq::Processor.new(boss)
+ Sidekiq.redis = REDIS
+ Sidekiq.redis { |c| c.flushdb }
+ end
+
+ class MockWorker
+ include Sidekiq::Worker
+ sidekiq_options :retry => false
+
+ def perform(args)
+ $invokes += 1
+ raise TestException.new("failed!")
+ end
+ end
+
+ it 'record failures' do
+ msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['myarg'] })
+
+ Sidekiq.redis { |conn| assert_equal 0, conn.llen('failed') || 0 }
+
+ assert_raises TestException do
+ @processor.process(msg, 'default')
+ end
+
+ Sidekiq.redis { |conn| assert_equal 1, conn.llen('failed') || 0 }
+
+ assert_equal 1, $invokes
+ end
+ end
+ end
+end
View
5 test/test_helper.rb
@@ -5,6 +5,11 @@
require "rack/test"
require "sidekiq"
+require "sidekiq/processor"
+
require "sidekiq-failures"
+Celluloid.logger = nil
+Sidekiq.logger.level = Logger::ERROR
+
REDIS = Sidekiq::RedisConnection.create(:url => "redis://localhost/15", :namespace => 'sidekiq_failures_test')
Please sign in to comment.
Something went wrong with that request. Please try again.