diff --git a/lib/puma/cli.rb b/lib/puma/cli.rb index ace37038..48bd66ac 100644 --- a/lib/puma/cli.rb +++ b/lib/puma/cli.rb @@ -178,11 +178,11 @@ module Puma o.on '-t', '--threads INT', "min:max threads to use (default 0:16)" do |arg| min, max = arg.split(":") if max - @options[:min_threads] = min.to_i - @options[:max_threads] = max.to_i + @options[:min_threads] = min + @options[:max_threads] = max else @options[:min_threads] = 0 - @options[:max_threads] = arg.to_i + @options[:max_threads] = arg end end diff --git a/lib/puma/thread_pool.rb b/lib/puma/thread_pool.rb index 3b686c32..843912b2 100644 --- a/lib/puma/thread_pool.rb +++ b/lib/puma/thread_pool.rb @@ -20,8 +20,8 @@ module Puma @spawned = 0 @waiting = 0 - @min = min - @max = max + @min = Integer(min) + @max = Integer(max) @block = block @extra = extra @@ -34,7 +34,7 @@ module Puma @auto_trim = nil @mutex.synchronize do - min.times { spawn_thread } + @min.times { spawn_thread } end end diff --git a/lib/rack/handler/puma.rb b/lib/rack/handler/puma.rb index 55affbab..2193361d 100644 --- a/lib/rack/handler/puma.rb +++ b/lib/rack/handler/puma.rb @@ -31,8 +31,8 @@ module Rack puts "* Listening on tcp://#{options[:Host]}:#{options[:Port]}" server.add_tcp_listener options[:Host], options[:Port] - server.min_threads = Integer(min) - server.max_threads = Integer(max) + server.min_threads = min + server.max_threads = max yield server if block_given? begin diff --git a/test/test_thread_pool.rb b/test/test_thread_pool.rb index 7e6d0cc9..5fc203f8 100644 --- a/test/test_thread_pool.rb +++ b/test/test_thread_pool.rb @@ -32,6 +32,16 @@ class TestThreadPool < Test::Unit::TestCase assert_equal 1, pool.spawned end + def test_converts_pool_sizes + pool = new_pool('0', '1') + + assert_equal 0, pool.spawned + + pool << 1 + + assert_equal 1, pool.spawned + end + def test_append_queues_on_max finish = false pool = new_pool(0, 1) { Thread.pass until finish }