1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
[ServerEngine::MultiThreadServer, ServerEngine::MultiProcessServer].each do |impl_class|
# MultiProcessServer uses fork(2) internally, then it doesn't support Windows.
describe impl_class do
include_context 'test server and worker'
it 'scale up' do
pending "Windows environment does not support fork" if ServerEngine.windows? && impl_class == ServerEngine::MultiProcessServer
config = {workers: 2, log_stdout: false, log_stderr: false}
s = impl_class.new(TestWorker) { config.dup }
t = Thread.new { s.main }
begin
wait_for_fork
test_state(:worker_run).should == 2
config[:workers] = 3
s.reload
wait_for_restart
test_state(:worker_run).should == 3
test_state(:worker_stop).should == 0
ensure
s.stop(true)
t.join
end
test_state(:worker_stop).should == 3
end
it 'scale down' do
pending "Windows environment does not support fork" if ServerEngine.windows? && impl_class == ServerEngine::MultiProcessServer
config = {workers: 2, log_stdout: false, log_stderr: false}
s = impl_class.new(TestWorker) { config.dup }
t = Thread.new { s.main }
begin
wait_for_fork
test_state(:worker_run).should == 2
config[:workers] = 1
s.restart(true)
wait_for_restart
test_state(:worker_run).should == 3
test_state(:worker_stop).should == 2
ensure
s.stop(true)
t.join
end
test_state(:worker_stop).should == 3
end
end
end
|