From 4fc9ea2393195450be8de7f9aae4fded38e9d4e4 Mon Sep 17 00:00:00 2001 From: Mattias Putman Date: Thu, 7 Mar 2013 12:28:34 +0100 Subject: [PATCH 1/2] Failing to construct identical lock with certain arguments (test) --- test/lock_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/lock_test.rb b/test/lock_test.rb index 5e4a25c..4013db9 100644 --- a/test/lock_test.rb +++ b/test/lock_test.rb @@ -42,6 +42,14 @@ def test_lock assert_equal 1, Resque.redis.llen('queue:lock_test') end + def test_lock_arguments + client_arguments = :test + client_lock = Job.lock(client_arguments) + job_arguments = Resque.decode(Resque.encode(client_arguments)) + job_lock = Job.lock(job_arguments) + assert_equal client_lock, job_lock + end + def test_deadlock now = Time.now.to_i From bc2c7564ad578b0d21f722f8c7de3bce32715895 Mon Sep 17 00:00:00 2001 From: Mattias Putman Date: Thu, 7 Mar 2013 12:29:51 +0100 Subject: [PATCH 2/2] use Resque.encode instead of to_s for stringifying arguments --- lib/resque/plugins/lock.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/resque/plugins/lock.rb b/lib/resque/plugins/lock.rb index dccfff2..ef789f2 100644 --- a/lib/resque/plugins/lock.rb +++ b/lib/resque/plugins/lock.rb @@ -53,7 +53,7 @@ def lock_timeout # passed the same arguments as `perform`, that is, your job's # payload. def lock(*args) - "lock:#{name}-#{args.to_s}" + "lock:#{name}-#{Resque.encode(args)}" end # See the documentation for SETNX http://redis.io/commands/setnx for an