Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enqueue_at_with_queue内でenqueueでなくenqueue_toでエンキュー #5

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/resque_unit_without_mock/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions lib/resque_unit_without_mock/scheduler_assertions.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
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,
"#{klass} should have been queued in #{Resque.enqueue_ats(queue)} before #{expected_timestamp}"
)
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,
Expand Down
14 changes: 13 additions & 1 deletion test/resque_unit_without_mock/scheduler_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Loading