From eca03b245aec423054cdb1e3247251de3cc040a4 Mon Sep 17 00:00:00 2001 From: hsato23 <129734919+hsato23@users.noreply.github.com> Date: Wed, 23 Oct 2024 09:52:03 +0900 Subject: [PATCH 1/2] =?UTF-8?q?enqueue=5Fat=5Fwith=5Fqueue=E5=86=85?= =?UTF-8?q?=E3=81=A7enqueue=E3=81=A7=E3=81=AA=E3=81=8Fenqueue=5Fto?= =?UTF-8?q?=E3=81=A7=E3=82=A8=E3=83=B3=E3=82=AD=E3=83=A5=E3=83=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/resque_unit_without_mock/scheduler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/resque_unit_without_mock/scheduler.rb b/lib/resque_unit_without_mock/scheduler.rb index 459f212..b2076c4 100644 --- a/lib/resque_unit_without_mock/scheduler.rb +++ b/lib/resque_unit_without_mock/scheduler.rb @@ -17,7 +17,7 @@ def enqueue_at_with_queue(queue, timestamp, klass, *args) @@enqueue_ats ||= {} @@enqueue_ats[queue] ||= [] @@enqueue_ats[queue] << { timestamp: timestamp, klass: klass, args: args } - Resque.enqueue(klass, *args) + Resque.enqueue_to(queue, klass, *args) end def enqueue_ats(queue) From 5f227e2b061e6c51c1940ce9e6915ce1d886e6c4 Mon Sep 17 00:00:00 2001 From: hsato23 <129734919+hsato23@users.noreply.github.com> Date: Wed, 23 Oct 2024 09:53:46 +0900 Subject: [PATCH 2/2] =?UTF-8?q?assert=5Fqueued=5Fat=5Fwith=5Fqueue?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler_assertions.rb | 12 +++++++++--- .../scheduler_assertions_test.rb | 14 +++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/resque_unit_without_mock/scheduler_assertions.rb b/lib/resque_unit_without_mock/scheduler_assertions.rb index 170cc8e..e6a4e12 100644 --- a/lib/resque_unit_without_mock/scheduler_assertions.rb +++ b/lib/resque_unit_without_mock/scheduler_assertions.rb @@ -1,6 +1,13 @@ module ResqueUnitWithoutMock::SchedulerAssertions def assert_queued_at(expected_timestamp, klass) - queue = Resque.queue_for(klass) + assert_queued_at_with_queue(Resque.queue_for(klass), expected_timestamp, klass) + end + + def assert_not_queued_at(expected_timestamp, klass) + assert_not_queued_at_with_queue(Resque.queue_for(klass), expected_timestamp, klass) + end + + def assert_queued_at_with_queue(queue, expected_timestamp, klass) result = Resque.enqueue_ats(queue).detect { |hash| hash[:timestamp] <= expected_timestamp && hash[:klass] == klass } assert( result, @@ -8,8 +15,7 @@ def assert_queued_at(expected_timestamp, klass) ) end - def assert_not_queued_at(expected_timestamp, klass) - queue = Resque.queue_for(klass) + def assert_not_queued_at_with_queue(queue, expected_timestamp, klass) result = Resque.enqueue_ats(queue).detect { |hash| hash[:timestamp] <= expected_timestamp && hash[:klass] == klass } assert( !result, diff --git a/test/resque_unit_without_mock/scheduler_assertions_test.rb b/test/resque_unit_without_mock/scheduler_assertions_test.rb index 45c5840..0795e56 100644 --- a/test/resque_unit_without_mock/scheduler_assertions_test.rb +++ b/test/resque_unit_without_mock/scheduler_assertions_test.rb @@ -30,7 +30,7 @@ def test_assert_queued_at assert_queued_at(Time.new(2011,11,11,0,0,3), PrintJob) end - def test_assert_queued_at_with_queue + def test_assert_queued_at_with_class_defined_queue # |=> queued!! # | |\\|\\\\\\\\ # 1 2 3 @@ -41,4 +41,16 @@ def test_assert_queued_at_with_queue assert_queued_at(Time.new(2011,11,11,0,0,2), PrintJob) assert_queued_at(Time.new(2011,11,11,0,0,3), PrintJob) end + + def test_assert_queued_at_with_queue + # |=> queued!! + # | |\\|\\\\\\\\ + # 1 2 3 + assert_not_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,2), PrintJob) + assert_not_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,3), PrintJob) + Resque.enqueue_at_with_queue(:urgent, Time.new(2011,11,11,0,0,2), PrintJob) + assert_not_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,1), PrintJob) + assert_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,2), PrintJob) + assert_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,3), PrintJob) + end end