File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
6373end
You can’t perform that action at this time.
0 commit comments