1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Assure worker index always within 0...@options[:workers]

This commit is contained in:
Sudara 2014-01-27 13:13:48 +01:00
parent b01b43d1da
commit fdb4d27967
4 changed files with 41 additions and 4 deletions

View file

@ -7,7 +7,6 @@ module Puma
@phase = 0
@workers = []
@worker_index = 0
@next_check = nil
@phased_state = :idle
@ -99,9 +98,10 @@ module Puma
end
def next_worker_index
i = @worker_index
@worker_index += 1
i
all_positions = 0...@options[:workers]
occupied_positions = @workers.map { |w| w.index }
available_positions = all_positions.to_a - occupied_positions
available_positions.first
end
def all_workers_booted?

View file

@ -14,4 +14,11 @@ else
ERROR=2
fi
if ruby -rubygems t3.rb > /dev/null 2>&1; then
echo "t3 OK"
else
echo "t3 FAIL"
ERROR=3
fi
exit $ERROR

25
test/shell/t3.rb Normal file
View file

@ -0,0 +1,25 @@
system "ruby -rubygems -I../../lib ../../bin/puma -p 10102 -C t3_conf.rb ../hello.ru &"
sleep 5
worker_pid_was_present = File.file? "t3-worker-2-pid"
system "kill `cat t3-worker-2-pid`" # kill off a worker
sleep 2
worker_index_within_number_of_workers = !File.file?("t3-worker-3-pid")
system "kill `cat t3-pid`"
File.unlink "t3-pid" if File.file? "t3-pid"
File.unlink "t3-worker-0-pid" if File.file? "t3-worker-0-pid"
File.unlink "t3-worker-1-pid" if File.file? "t3-worker-1-pid"
File.unlink "t3-worker-2-pid" if File.file? "t3-worker-2-pid"
File.unlink "t3-worker-3-pid" if File.file? "t3-worker-3-pid"
if worker_pid_was_present and worker_index_within_number_of_workers
exit 0
else
exit 1
end

5
test/shell/t3_conf.rb Normal file
View file

@ -0,0 +1,5 @@
pidfile "t3-pid"
workers 3
on_worker_boot do |index|
File.open("t3-worker-#{index}-pid", "w") { |f| f.puts Process.pid }
end