Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update sidekiq/testing to execute almost all of the client api, fixes #…

…713

This should ensure tests reproduce a maximum amount of the implementation details that you'll see in production.
  • Loading branch information...
commit 07a2781ac08b2f7addc758c0d43db2b4ba5d5e80 1 parent 5019436
@mperham authored
Showing with 31 additions and 13 deletions.
  1. +5 −3 Changes.md
  2. +14 −6 lib/sidekiq/testing.rb
  3. +12 −4 test/test_testing.rb
View
8 Changes.md
@@ -1,11 +1,13 @@
2.9.0
-----------
-- Raise an error within workers which don't finish within the hard
+- Update 'sidekiq/testing' to work with any Sidekiq::Client call. It
+ also serializes the arguments as using Redis would. [#713]
+- Raise a Sidekiq::Shutdown error within workers which don't finish within the hard
timeout. This is to prevent unwanted database transaction commits. [#377]
- Lazy load Redis connection pool, you no longer need to specify
-anything in Passenger or Unicorn's after_fork callback [#794]
-- Provides ability to hook onto failure after max retries failed. [jkassemi, #780]
+ anything in Passenger or Unicorn's after_fork callback [#794]
+- Add optional Worker#retries_exhausted hook after max retries failed. [jkassemi, #780]
- Fix bug in pagination link to last page [pitr, #774]
- Upstart scripts for multiple Sidekiq instances [dariocravero, #763]
- Use select via pipes instead of poll to catch signals [mrnugget, #761]
View
20 lib/sidekiq/testing.rb
@@ -1,4 +1,18 @@
module Sidekiq
+
+ class Client
+ class << self
+ alias_method :raw_push_old, :raw_push
+
+ def raw_push(payloads)
+ payloads.each do |job|
+ job['class'].constantize.jobs << Sidekiq.load_json(Sidekiq.dump_json(job))
+ end
+ true
+ end
+ end
+ end
+
module Worker
##
# The Sidekiq testing infrastructure overrides perform_async
@@ -56,12 +70,6 @@ module Worker
# Then I should receive a welcome email to "foo@example.com"
#
module ClassMethods
- alias_method :client_push_old, :client_push
-
- def client_push(opts)
- jobs << opts
- opts.object_id
- end
# Jobs queued for this worker
def jobs
View
16 test/test_testing.rb
@@ -53,10 +53,10 @@ def bar(str)
after do
# Undo override
- Sidekiq::Worker::ClassMethods.class_eval do
- remove_method :client_push
- alias_method :client_push, :client_push_old
- remove_method :client_push_old
+ (class << Sidekiq::Client; self; end).class_eval do
+ remove_method :raw_push
+ alias_method :raw_push, :raw_push_old
+ remove_method :raw_push_old
end
end
@@ -109,6 +109,14 @@ def self.foo(x)
StoredWorker.drain
end
assert_equal 0, StoredWorker.jobs.size
+
+ end
+
+ it 'round trip serializes the job arguments' do
+ assert StoredWorker.perform_async(:mike)
+ job = StoredWorker.jobs.first
+ assert_equal "mike", job['args'].first
+ StoredWorker.clear
end
class FirstWorker
Please sign in to comment.
Something went wrong with that request. Please try again.