Skip to content

Commit

Permalink
Merge pull request #82 from askl56/master
Browse files Browse the repository at this point in the history
updated hash syntax to 1.9 ruby symbol syntax
  • Loading branch information
mperham committed Sep 6, 2015
2 parents 0ea14cb + 1e05ee5 commit 84f6eee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/connection_pool.rb
Expand Up @@ -15,7 +15,7 @@
#
# Using optional timeout override (for that single invocation)
#
# @pool.with(:timeout => 2.0) do |redis|
# @pool.with(timeout: 2.0) do |redis|
# redis.lpop('my-list') if redis.llen('my-list') > 0
# end
#
Expand Down
60 changes: 30 additions & 30 deletions test/test_connection_pool.rb
Expand Up @@ -61,7 +61,7 @@ def kill_threads(threads)

def test_basic_multithreaded_usage
pool_size = 5
pool = ConnectionPool.new(:size => pool_size) { NetworkConnection.new }
pool = ConnectionPool.new(size: pool_size) { NetworkConnection.new }

start = Time.new

Expand All @@ -83,7 +83,7 @@ def test_basic_multithreaded_usage
end

def test_timeout
pool = ConnectionPool.new(:timeout => 0, :size => 1) { NetworkConnection.new }
pool = ConnectionPool.new(timeout: 0, size: 1) { NetworkConnection.new }
thread = Thread.new do
pool.with do |net|
net.do_something
Expand All @@ -105,7 +105,7 @@ def test_timeout
end

def test_with
pool = ConnectionPool.new(:timeout => 0, :size => 1) { Object.new }
pool = ConnectionPool.new(timeout: 0, size: 1) { Object.new }

pool.with do
assert_raises Timeout::Error do
Expand All @@ -117,7 +117,7 @@ def test_with
end

def test_with_timeout
pool = ConnectionPool.new(:timeout => 0, :size => 1) { Object.new }
pool = ConnectionPool.new(timeout: 0, size: 1) { Object.new }

assert_raises Timeout::Error do
Timeout.timeout(0.01) do
Expand All @@ -133,7 +133,7 @@ def test_with_timeout
def test_checkout_ignores_timeout
skip("Thread.handle_interrupt not available") unless Thread.respond_to?(:handle_interrupt)

pool = ConnectionPool.new(:timeout => 0, :size => 1) { Object.new }
pool = ConnectionPool.new(timeout: 0, size: 1) { Object.new }
def pool.checkout(options)
sleep 0.015
super
Expand All @@ -157,7 +157,7 @@ def pool.checkout(options)
end

def test_explicit_return
pool = ConnectionPool.new(:timeout => 0, :size => 1) do
pool = ConnectionPool.new(timeout: 0, size: 1) do
mock = Minitest::Mock.new
def mock.disconnect!
raise "should not disconnect upon explicit return"
Expand All @@ -171,7 +171,7 @@ def mock.disconnect!
end

def test_with_timeout_override
pool = ConnectionPool.new(:timeout => 0, :size => 1) { NetworkConnection.new }
pool = ConnectionPool.new(timeout: 0, size: 1) { NetworkConnection.new }

t = Thread.new do
pool.with do |net|
Expand All @@ -186,13 +186,13 @@ def test_with_timeout_override
pool.with { |net| net.do_something }
end

pool.with(:timeout => 2 * NetworkConnection::SLEEP_TIME) do |conn|
pool.with(timeout: 2 * NetworkConnection::SLEEP_TIME) do |conn|
refute_nil conn
end
end

def test_checkin
pool = ConnectionPool.new(:timeout => 0, :size => 1) { NetworkConnection.new }
pool = ConnectionPool.new(timeout: 0, size: 1) { NetworkConnection.new }
conn = pool.checkout

assert_raises Timeout::Error do
Expand All @@ -205,12 +205,12 @@ def test_checkin
end

def test_returns_value
pool = ConnectionPool.new(:timeout => 0, :size => 1) { Object.new }
pool = ConnectionPool.new(timeout: 0, size: 1) { Object.new }
assert_equal 1, pool.with {|o| 1 }
end

def test_checkin_never_checkout
pool = ConnectionPool.new(:timeout => 0, :size => 1) { Object.new }
pool = ConnectionPool.new(timeout: 0, size: 1) { Object.new }

e = assert_raises ConnectionPool::Error do
pool.checkin
Expand All @@ -220,7 +220,7 @@ def test_checkin_never_checkout
end

def test_checkin_no_current_checkout
pool = ConnectionPool.new(:timeout => 0, :size => 1) { Object.new }
pool = ConnectionPool.new(timeout: 0, size: 1) { Object.new }

pool.checkout
pool.checkin
Expand All @@ -231,7 +231,7 @@ def test_checkin_no_current_checkout
end

def test_checkin_twice
pool = ConnectionPool.new(:timeout => 0, :size => 1) { Object.new }
pool = ConnectionPool.new(timeout: 0, size: 1) { Object.new }

pool.checkout
pool.checkout
Expand All @@ -250,7 +250,7 @@ def test_checkin_twice
end

def test_checkout
pool = ConnectionPool.new(:size => 1) { NetworkConnection.new }
pool = ConnectionPool.new(size: 1) { NetworkConnection.new }

conn = pool.checkout

Expand All @@ -260,7 +260,7 @@ def test_checkout
end

def test_checkout_multithread
pool = ConnectionPool.new(:size => 2) { NetworkConnection.new }
pool = ConnectionPool.new(size: 2) { NetworkConnection.new }
conn = pool.checkout

t = Thread.new do
Expand All @@ -271,15 +271,15 @@ def test_checkout_multithread
end

def test_checkout_timeout
pool = ConnectionPool.new(:timeout => 0, :size => 0) { Object.new }
pool = ConnectionPool.new(timeout: 0, size: 0) { Object.new }

assert_raises Timeout::Error do
pool.checkout
end
end

def test_checkout_timeout_override
pool = ConnectionPool.new(:timeout => 0, :size => 1) { NetworkConnection.new }
pool = ConnectionPool.new(timeout: 0, size: 1) { NetworkConnection.new }

thread = Thread.new do
pool.with do |net|
Expand All @@ -294,35 +294,35 @@ def test_checkout_timeout_override
pool.checkout
end

assert pool.checkout :timeout => 2 * NetworkConnection::SLEEP_TIME
assert pool.checkout timeout: 2 * NetworkConnection::SLEEP_TIME
end

def test_passthru
pool = ConnectionPool.wrap(:timeout => 2 * NetworkConnection::SLEEP_TIME, :size => 1) { NetworkConnection.new }
pool = ConnectionPool.wrap(timeout: 2 * NetworkConnection::SLEEP_TIME, size: 1) { NetworkConnection.new }
assert_equal 1, pool.do_something
assert_equal 2, pool.do_something
assert_equal 5, pool.do_something_with_block { 3 }
assert_equal 6, pool.with { |net| net.fast }
end

def test_passthru_respond_to
pool = ConnectionPool.wrap(:timeout => 2 * NetworkConnection::SLEEP_TIME, :size => 1) { NetworkConnection.new }
pool = ConnectionPool.wrap(timeout: 2 * NetworkConnection::SLEEP_TIME, size: 1) { NetworkConnection.new }
assert pool.respond_to?(:with)
assert pool.respond_to?(:do_something)
assert pool.respond_to?(:do_magic)
refute pool.respond_to?(:do_lots_of_magic)
end

def test_return_value
pool = ConnectionPool.new(:timeout => 2 * NetworkConnection::SLEEP_TIME, :size => 1) { NetworkConnection.new }
pool = ConnectionPool.new(timeout: 2 * NetworkConnection::SLEEP_TIME, size: 1) { NetworkConnection.new }
result = pool.with do |net|
net.fast
end
assert_equal 1, result
end

def test_heavy_threading
pool = ConnectionPool.new(:timeout => 0.5, :size => 3) { NetworkConnection.new }
pool = ConnectionPool.new(timeout: 0.5, size: 3) { NetworkConnection.new }

threads = Array.new(20) do
Thread.new do
Expand All @@ -336,7 +336,7 @@ def test_heavy_threading
end

def test_reuses_objects_when_pool_not_saturated
pool = ConnectionPool.new(:size => 5) { NetworkConnection.new }
pool = ConnectionPool.new(size: 5) { NetworkConnection.new }

ids = 10.times.map do
pool.with { |c| c.object_id }
Expand All @@ -347,7 +347,7 @@ def test_reuses_objects_when_pool_not_saturated

def test_nested_checkout
recorder = Recorder.new
pool = ConnectionPool.new(:size => 1) { recorder }
pool = ConnectionPool.new(size: 1) { recorder }
pool.with do |r_outer|
@other = Thread.new do |t|
pool.with do |r_other|
Expand All @@ -372,7 +372,7 @@ def test_nested_checkout
def test_shutdown_is_executed_for_all_connections
recorders = []

pool = ConnectionPool.new(:size => 3) do
pool = ConnectionPool.new(size: 3) do
Recorder.new.tap { |r| recorders << r }
end

Expand All @@ -388,7 +388,7 @@ def test_shutdown_is_executed_for_all_connections
end

def test_raises_error_after_shutting_down
pool = ConnectionPool.new(:size => 1) { true }
pool = ConnectionPool.new(size: 1) { true }

pool.shutdown { }

Expand All @@ -400,7 +400,7 @@ def test_raises_error_after_shutting_down
def test_runs_shutdown_block_asynchronously_if_connection_was_in_use
recorders = []

pool = ConnectionPool.new(:size => 3) do
pool = ConnectionPool.new(size: 3) do
Recorder.new.tap { |r| recorders << r }
end

Expand All @@ -422,7 +422,7 @@ def test_runs_shutdown_block_asynchronously_if_connection_was_in_use
end

def test_raises_an_error_if_shutdown_is_called_without_a_block
pool = ConnectionPool.new(:size => 1) { }
pool = ConnectionPool.new(size: 1) { }

assert_raises ArgumentError do
pool.shutdown
Expand All @@ -432,7 +432,7 @@ def test_raises_an_error_if_shutdown_is_called_without_a_block
def test_shutdown_is_executed_for_all_connections_in_wrapped_pool
recorders = []

wrapper = ConnectionPool::Wrapper.new(:size => 3) do
wrapper = ConnectionPool::Wrapper.new(size: 3) do
Recorder.new.tap { |r| recorders << r }
end

Expand Down Expand Up @@ -463,7 +463,7 @@ def test_wrapper_respond_to_eh
end

def test_wrapper_with
wrapper = ConnectionPool::Wrapper.new(:timeout => 0, :size => 1) { Object.new }
wrapper = ConnectionPool::Wrapper.new(timeout: 0, size: 1) { Object.new }

wrapper.with do
assert_raises Timeout::Error do
Expand Down

0 comments on commit 84f6eee

Please sign in to comment.