test/middleware/sidekiq_test.rb in chillout-0.8.6 vs test/middleware/sidekiq_test.rb in chillout-0.8.7
- old
+ new
@@ -22,22 +22,51 @@
def perform
Chillout.creations = MOCK_CREATIONS
end
end
- def test_enqueues_and_clears_creations
+ def test_enqueues_stats_and_clears_creations
@client.expects(:enqueue).with(FakeJob::MOCK_CREATIONS)
+ @client.expects(:enqueue).with do |measurement|
+ SidekiqJobMeasurement === measurement &&
+ measurement.success == "true" &&
+ measurement.job_class == "Chillout::Middleware::SidekiqTest::FakeJob"
+ end
Sidekiq::Testing.inline! { FakeJob.perform_async }
assert_nil Chillout.creations
end
class EmptyJob
include Sidekiq::Worker
def perform; end
end
- def test_does_nothing_when_no_creations
+ def test_enqueues_stats_only_when_no_creations
+ @client.expects(:enqueue).with do |measurement|
+ SidekiqJobMeasurement === measurement
+ end
Sidekiq::Testing.inline! { EmptyJob.perform_async }
+ assert_nil Chillout.creations
+ end
+
+ class ErrorJob
+ Doh = Class.new(StandardError)
+ include Sidekiq::Worker
+ def perform
+ raise Doh
+ end
+ end
+
+ def test_enqueues_stats_even_on_failure
+ @client.expects(:enqueue).with do |measurement|
+ SidekiqJobMeasurement === measurement &&
+ measurement.success == "false"
+ end
+ Sidekiq::Testing.inline! do
+ assert_raises(ErrorJob::Doh) do
+ ErrorJob.perform_async
+ end
+ end
assert_nil Chillout.creations
end
end
end
\ No newline at end of file