Skip to content

Commit

Permalink
Update liniting warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
miry committed Nov 20, 2022
1 parent 29658a0 commit 5d2afa4
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions test/lru_hash_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ def test_set_cleans_resources_if_last_error_has_expired
lru_hash = LRUHash.new(max_size: 0, min_time: 1)
lru_hash.set("b", create_circuit_breaker("b", true, false, 2))

sleep 3
sleep(3)
lru_hash.set("d", create_circuit_breaker("d"))

assert_equal(["d"], lru_hash.values.map(&:name))
assert_equal(1, lru_hash.size)
end
Expand All @@ -83,7 +84,7 @@ def test_set_cleans_resources_if_minimum_time_is_reached
lru_hash.set("b", create_circuit_breaker("b", false))
lru_hash.set("c", create_circuit_breaker("c", false))

sleep 2
sleep(2)
lru_hash.set("d", create_circuit_breaker("d"))

assert_equal(["a", "d"], lru_hash.values.map(&:name))
Expand Down Expand Up @@ -142,8 +143,9 @@ def test_clean_instrumentation
refute_nil(payload[:elapsed])
end

sleep 3
sleep(3)
lru_hash.set("d", create_circuit_breaker("d"))

assert(notified, "No notifications has been emitted")
ensure
Semian.unsubscribe(subscriber)
Expand Down Expand Up @@ -181,21 +183,25 @@ def test_monotonically_increasing
lru_hash.set("a", create_circuit_breaker("a"))
lru_hash.set("b", create_circuit_breaker("b"))
lru_hash.set("c", create_circuit_breaker("c"))
assert_equal ["a", "b", "c"], lru_hash.values.map(&:name)

sleep 1
assert_equal(["a", "b", "c"], lru_hash.values.map(&:name))

sleep(1)
lru_hash.get("b")
assert_monotonic.call(lru_hash)
assert_equal ["a", "c", "b"], lru_hash.values.map(&:name)

assert_equal(["a", "c", "b"], lru_hash.values.map(&:name))

lru_hash.set("d", create_circuit_breaker("d"))
assert_monotonic.call(lru_hash)
assert_equal ["a", "c", "b", "d"], lru_hash.values.map(&:name)

sleep 2
assert_equal(["a", "c", "b", "d"], lru_hash.values.map(&:name))

sleep(2)
lru_hash.set("e", create_circuit_breaker("e"))
assert_monotonic.call(lru_hash)
assert_equal ["b", "d", "e"], lru_hash.values.map(&:name)

assert_equal(["b", "d", "e"], lru_hash.values.map(&:name))
ensure
Semian.unsubscribe(subscriber)
end
Expand All @@ -207,11 +213,12 @@ def test_max_size
lru_hash.set("c", create_circuit_breaker("c"))

assert_equal(3, lru_hash.size)
assert_equal ["a", "b", "c"], lru_hash.values.map(&:name)
assert_equal(["a", "b", "c"], lru_hash.values.map(&:name))

sleep 1
sleep(1)
lru_hash.set("d", create_circuit_breaker("d"))
assert_equal ["d"], lru_hash.values.map(&:name)

assert_equal(["d"], lru_hash.values.map(&:name))
end

def test_max_size_overflow
Expand All @@ -220,22 +227,22 @@ def test_max_size_overflow
lru_hash.set("b", create_circuit_breaker("b"))

assert_equal(2, lru_hash.size)
assert_equal ["a", "b"], lru_hash.values.map(&:name)
assert_equal(["a", "b"], lru_hash.values.map(&:name))

sleep 2
sleep(2)

# [a, b] are older than the min_time, but the hash isn't full, so
# there's no garbage collection.
lru_hash.set("c", create_circuit_breaker("c"))

assert_equal(3, lru_hash.size)
assert_equal ["a", "b", "c"], lru_hash.values.map(&:name)
assert_equal(["a", "b", "c"], lru_hash.values.map(&:name))

# [a, b] are beyond the min_time, but [c] isn't.
lru_hash.set("d", create_circuit_breaker("d"))

assert_equal(2, lru_hash.size)
assert_equal ["c", "d"], lru_hash.values.map(&:name)
assert_equal(["c", "d"], lru_hash.values.map(&:name))
end

private
Expand Down

0 comments on commit 5d2afa4

Please sign in to comment.