Skip to content

Commit

Permalink
Fix unmemoized method
Browse files Browse the repository at this point in the history
  • Loading branch information
andersonkrs committed Dec 1, 2024
1 parent 242fd15 commit 50003ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/solid_queue/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def size
end

def latency
@latency = begin
@latency ||= begin
now = Time.current
oldest_enqueued_at = ReadyExecution.queued_as(name).minimum(:created_at) || now

Expand Down
16 changes: 14 additions & 2 deletions test/unit/queue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,28 @@ class QueueTest < ActiveSupport::TestCase
assert_in_delta 5.minutes.to_i, @background_queue.latency, 1.second.to_i
assert_equal 0, @default_queue.latency

@background_queue = SolidQueue::Queue.find_by_name("background")
@default_queue = SolidQueue::Queue.find_by_name("default")
travel_to 10.minutes.from_now

assert_in_delta 15.minutes.to_i, @background_queue.latency, 1.second.to_i
assert_equal 0, @default_queue.latency
end

test "returns memoized latency after the first call" do
travel_to 5.minutes.from_now

assert_in_delta 5.minutes.to_i, @background_queue.latency, 1.second.to_i

travel_to 10.minutes.from_now

assert_in_delta 5.minutes.to_i, @background_queue.latency, 1.second.to_i
end

test "return human latency on each queue" do
travel_to 5.minutes.from_now

assert_match /5 minutes/, @background_queue.human_latency
assert_match /0 seconds/, @default_queue.human_latency
assert_match (/5 minutes/), @background_queue.human_latency
assert_match (/0 seconds/), @default_queue.human_latency
end
end

0 comments on commit 50003ac

Please sign in to comment.