Skip to content

Commit 9954700

Browse files
committed
Fix unmemoized method
1 parent 242fd15 commit 9954700

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

app/models/solid_queue/queue.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def size
4141
end
4242

4343
def latency
44-
@latency = begin
44+
@latency ||= begin
4545
now = Time.current
4646
oldest_enqueued_at = ReadyExecution.queued_as(name).minimum(:created_at) || now
4747

test/unit/queue_test.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,20 @@ class QueueTest < ActiveSupport::TestCase
5454
assert_equal 0, @default_queue.latency
5555
end
5656

57+
test "returns memoized latency after the first call" do
58+
travel_to 5.minutes.from_now
59+
60+
assert_in_delta 5.minutes.to_i, @background_queue.latency, 1.second.to_i
61+
62+
travel_to 10.minutes.from_now
63+
64+
assert_in_delta 5.minutes.to_i, latency, 1.second.to_i
65+
end
66+
5767
test "return human latency on each queue" do
5868
travel_to 5.minutes.from_now
5969

60-
assert_match /5 minutes/, @background_queue.human_latency
61-
assert_match /0 seconds/, @default_queue.human_latency
70+
assert_match (/5 minutes/), @background_queue.human_latency
71+
assert_match (/0 seconds/), @default_queue.human_latency
6272
end
6373
end

0 commit comments

Comments
 (0)