Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
julik committed Feb 28, 2024
1 parent 296f70a commit a843f6a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/pecorino/adapters/memory_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ def state(key:, capacity:, leak_rate:)
# Adds tokens to the leaky bucket. The return value is a tuple of two
# values: the current level (Float) and whether the bucket is now at capacity (Boolean)
def add_tokens(key:, capacity:, leak_rate:, n_tokens:)
add_tokens_with_lock(key, capacity, leak_rate, n_tokens, _conditionally = false)
add_tokens_with_lock(key, capacity, leak_rate, n_tokens, _conditionally = false)
end

# Adds tokens to the leaky bucket conditionally. If there is capacity, the tokens will
# be added. If there isn't - the fillup will be rejected. The return value is a triplet of
# the current level (Float), whether the bucket is now at capacity (Boolean)
# and whether the fillup was accepted (Boolean)
def add_tokens_conditionally(key:, capacity:, leak_rate:, n_tokens:)
add_tokens_with_lock(key, capacity, leak_rate, n_tokens, _conditionally = true)
add_tokens_with_lock(key, capacity, leak_rate, n_tokens, _conditionally = true)
end

# Sets a timed block for the given key - this is used when a throttle fires. The return value
Expand Down
2 changes: 1 addition & 1 deletion lib/pecorino/adapters/redis_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def blocked_until(key:)

def with_redis
if @redis_pool.respond_to?(:with)
@redis_pool.with {|conn| yield(conn) }
@redis_pool.with { |conn| yield(conn) }
else
yield @redis_pool
end
Expand Down
4 changes: 2 additions & 2 deletions test/adapters/adapter_test_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ def test_set_block_sets_a_block
def test_set_block_does_not_set_block_in_the_past
key = random_key
assert_nil adapter.blocked_until(key: key)
assert_raise(ArgumentError) { adapter.set_block(key: key, block_for: -20) }
assert_raise(ArgumentError) { adapter.set_block(key: key, block_for: -20) }
assert_nil adapter.blocked_until(key: key)
end

def test_set_block_does_not_set_block_which_would_expire_immediately
key = random_key
assert_nil adapter.blocked_until(key: key)
assert_raise(ArgumentError) { adapter.set_block(key: key, block_for: 0) }
assert_raise(ArgumentError) { adapter.set_block(key: key, block_for: 0) }
assert_nil adapter.blocked_until(key: key)
end

Expand Down

0 comments on commit a843f6a

Please sign in to comment.