thin 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/README.md +83 -0
- data/Rakefile +9 -32
- data/example/vlad.rake +1 -1
- data/lib/rack/adapter/loader.rb +0 -16
- data/lib/thin.rb +22 -24
- data/lib/thin/backends/base.rb +3 -1
- data/lib/thin/connection.rb +9 -8
- data/lib/thin/daemonizing.rb +3 -1
- data/lib/thin/logging.rb +1 -1
- data/lib/thin/runner.rb +36 -36
- data/lib/thin/server.rb +13 -0
- data/lib/thin/version.rb +3 -3
- metadata +5 -91
- data/README +0 -69
- data/benchmark/abc +0 -51
- data/benchmark/benchmarker.rb +0 -80
- data/benchmark/runner +0 -82
- data/spec/backends/swiftiply_client_spec.rb +0 -66
- data/spec/backends/tcp_server_spec.rb +0 -33
- data/spec/backends/unix_server_spec.rb +0 -37
- data/spec/command_spec.rb +0 -25
- data/spec/configs/cluster.yml +0 -9
- data/spec/configs/single.yml +0 -9
- data/spec/connection_spec.rb +0 -107
- data/spec/controllers/cluster_spec.rb +0 -267
- data/spec/controllers/controller_spec.rb +0 -129
- data/spec/controllers/service_spec.rb +0 -50
- data/spec/daemonizing_spec.rb +0 -200
- data/spec/headers_spec.rb +0 -40
- data/spec/logging_spec.rb +0 -52
- data/spec/perf/request_perf_spec.rb +0 -50
- data/spec/perf/response_perf_spec.rb +0 -19
- data/spec/perf/server_perf_spec.rb +0 -39
- data/spec/rack/loader_spec.rb +0 -42
- data/spec/rack/rails_adapter_spec.rb +0 -173
- data/spec/rails_app/app/controllers/application.rb +0 -10
- data/spec/rails_app/app/controllers/simple_controller.rb +0 -19
- data/spec/rails_app/app/helpers/application_helper.rb +0 -3
- data/spec/rails_app/app/views/simple/index.html.erb +0 -15
- data/spec/rails_app/config/boot.rb +0 -109
- data/spec/rails_app/config/environment.rb +0 -64
- data/spec/rails_app/config/environments/development.rb +0 -18
- data/spec/rails_app/config/environments/production.rb +0 -19
- data/spec/rails_app/config/environments/test.rb +0 -22
- data/spec/rails_app/config/initializers/inflections.rb +0 -10
- data/spec/rails_app/config/initializers/mime_types.rb +0 -5
- data/spec/rails_app/config/routes.rb +0 -35
- data/spec/rails_app/public/404.html +0 -30
- data/spec/rails_app/public/422.html +0 -30
- data/spec/rails_app/public/500.html +0 -30
- data/spec/rails_app/public/dispatch.cgi +0 -10
- data/spec/rails_app/public/dispatch.fcgi +0 -24
- data/spec/rails_app/public/dispatch.rb +0 -10
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/public/images/rails.png +0 -0
- data/spec/rails_app/public/index.html +0 -277
- data/spec/rails_app/public/javascripts/application.js +0 -2
- data/spec/rails_app/public/javascripts/controls.js +0 -963
- data/spec/rails_app/public/javascripts/dragdrop.js +0 -972
- data/spec/rails_app/public/javascripts/effects.js +0 -1120
- data/spec/rails_app/public/javascripts/prototype.js +0 -4225
- data/spec/rails_app/public/robots.txt +0 -5
- data/spec/rails_app/script/about +0 -3
- data/spec/rails_app/script/console +0 -3
- data/spec/rails_app/script/destroy +0 -3
- data/spec/rails_app/script/generate +0 -3
- data/spec/rails_app/script/performance/benchmarker +0 -3
- data/spec/rails_app/script/performance/profiler +0 -3
- data/spec/rails_app/script/performance/request +0 -3
- data/spec/rails_app/script/plugin +0 -3
- data/spec/rails_app/script/process/inspector +0 -3
- data/spec/rails_app/script/process/reaper +0 -3
- data/spec/rails_app/script/process/spawner +0 -3
- data/spec/rails_app/script/runner +0 -3
- data/spec/rails_app/script/server +0 -3
- data/spec/request/mongrel_spec.rb +0 -39
- data/spec/request/parser_spec.rb +0 -254
- data/spec/request/persistent_spec.rb +0 -35
- data/spec/request/processing_spec.rb +0 -50
- data/spec/response_spec.rb +0 -102
- data/spec/runner_spec.rb +0 -168
- data/spec/server/builder_spec.rb +0 -44
- data/spec/server/pipelining_spec.rb +0 -110
- data/spec/server/robustness_spec.rb +0 -34
- data/spec/server/stopping_spec.rb +0 -55
- data/spec/server/swiftiply.yml +0 -6
- data/spec/server/swiftiply_spec.rb +0 -32
- data/spec/server/tcp_spec.rb +0 -47
- data/spec/server/threaded_spec.rb +0 -27
- data/spec/server/unix_socket_spec.rb +0 -26
- data/spec/server_spec.rb +0 -100
- data/spec/spec_helper.rb +0 -234
- data/tasks/announce.rake +0 -22
- data/tasks/deploy.rake +0 -13
- data/tasks/email.erb +0 -27
- data/tasks/gem.rake +0 -65
- data/tasks/rdoc.rake +0 -25
- data/tasks/site.rake +0 -15
- data/tasks/spec.rake +0 -43
- data/tasks/stats.rake +0 -28
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Backends::SwiftiplyClient do
|
4
|
-
before do
|
5
|
-
@backend = Backends::SwiftiplyClient.new('0.0.0.0', 3333)
|
6
|
-
@backend.server = mock('server', :null_object => true)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should connect" do
|
10
|
-
EventMachine.run do
|
11
|
-
@backend.connect
|
12
|
-
EventMachine.stop
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should disconnect" do
|
17
|
-
EventMachine.run do
|
18
|
-
@backend.connect
|
19
|
-
@backend.disconnect
|
20
|
-
EventMachine.stop
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe SwiftiplyConnection do
|
26
|
-
before do
|
27
|
-
@connection = SwiftiplyConnection.new(nil)
|
28
|
-
@connection.backend = Backends::SwiftiplyClient.new('0.0.0.0', 3333)
|
29
|
-
@connection.backend.server = mock('server', :null_object => true)
|
30
|
-
end
|
31
|
-
|
32
|
-
it do
|
33
|
-
@connection.should be_persistent
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should send handshake on connection_completed" do
|
37
|
-
@connection.should_receive(:send_data).with('swiftclient000000000d0500')
|
38
|
-
@connection.connection_completed
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should reconnect on unbind" do
|
42
|
-
@connection.backend.stub!(:running?).and_return(true)
|
43
|
-
@connection.stub!(:rand).and_return(0) # Make sure we don't wait
|
44
|
-
|
45
|
-
@connection.should_receive(:reconnect).with('0.0.0.0', 3333)
|
46
|
-
|
47
|
-
EventMachine.run do
|
48
|
-
@connection.unbind
|
49
|
-
EventMachine.add_timer(0) { EventMachine.stop }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should not reconnect when not running" do
|
54
|
-
@connection.backend.stub!(:running?).and_return(false)
|
55
|
-
EventMachine.should_not_receive(:add_timer)
|
56
|
-
@connection.unbind
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should have a host_ip" do
|
60
|
-
@connection.send(:host_ip).should == [0, 0, 0, 0]
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should generate swiftiply_handshake based on key" do
|
64
|
-
@connection.send(:swiftiply_handshake, 'key').should == 'swiftclient000000000d0503key'
|
65
|
-
end
|
66
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Backends::TcpServer do
|
4
|
-
before do
|
5
|
-
@backend = Backends::TcpServer.new('0.0.0.0', 3333)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should not use epoll" do
|
9
|
-
@backend.no_epoll = true
|
10
|
-
EventMachine.should_not_receive(:epoll)
|
11
|
-
@backend.config
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should use epoll" do
|
15
|
-
EventMachine.should_receive(:epoll)
|
16
|
-
@backend.config
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should connect" do
|
20
|
-
EventMachine.run do
|
21
|
-
@backend.connect
|
22
|
-
EventMachine.stop
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should disconnect" do
|
27
|
-
EventMachine.run do
|
28
|
-
@backend.connect
|
29
|
-
@backend.disconnect
|
30
|
-
EventMachine.stop
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Backends::UnixServer do
|
4
|
-
before do
|
5
|
-
@backend = Backends::UnixServer.new('/tmp/thin-test.sock')
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should connect" do
|
9
|
-
EventMachine.run do
|
10
|
-
@backend.connect
|
11
|
-
EventMachine.stop
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should disconnect" do
|
16
|
-
EventMachine.run do
|
17
|
-
@backend.connect
|
18
|
-
@backend.disconnect
|
19
|
-
EventMachine.stop
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should remove socket file on close" do
|
24
|
-
@backend.close
|
25
|
-
File.exist?('/tmp/thin-test.sock').should be_false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe UnixConnection do
|
30
|
-
before do
|
31
|
-
@connection = UnixConnection.new(nil)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should return 127.0.0.1 as remote_address" do
|
35
|
-
@connection.remote_address.should == '127.0.0.1'
|
36
|
-
end
|
37
|
-
end
|
data/spec/command_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Command do
|
4
|
-
before do
|
5
|
-
Command.script = 'thin'
|
6
|
-
@command = Command.new(:start, :port => 3000, :daemonize => true, :log => 'hi.log',
|
7
|
-
:require => %w(rubygems thin), :no_epoll => true)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should shellify command' do
|
11
|
-
out = @command.shellify
|
12
|
-
out.should include('--port=3000', '--daemonize', '--log="hi.log"', 'thin start --')
|
13
|
-
out.should_not include('--pid')
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should shellify Array argument to multiple parameters' do
|
17
|
-
out = @command.shellify
|
18
|
-
out.should include('--require="rubygems"', '--require="thin"')
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should convert _ to - in option name' do
|
22
|
-
out = @command.shellify
|
23
|
-
out.should include('--no-epoll')
|
24
|
-
end
|
25
|
-
end
|
data/spec/configs/cluster.yml
DELETED
data/spec/configs/single.yml
DELETED
data/spec/connection_spec.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Connection do
|
4
|
-
before do
|
5
|
-
@connection = Connection.new(mock('EM', :null_object => true))
|
6
|
-
@connection.post_init
|
7
|
-
@connection.backend = mock("backend", :ssl? => false)
|
8
|
-
@connection.app = proc do |env|
|
9
|
-
[200, {}, ['']]
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should parse on receive_data" do
|
14
|
-
@connection.request.should_receive(:parse).with('GET')
|
15
|
-
@connection.receive_data('GET')
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should close connection on InvalidRequest error in receive_data" do
|
19
|
-
@connection.request.stub!(:parse).and_raise(InvalidRequest)
|
20
|
-
@connection.should_receive(:close_connection)
|
21
|
-
@connection.receive_data('')
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should process when parsing complete" do
|
25
|
-
@connection.request.should_receive(:parse).and_return(true)
|
26
|
-
@connection.should_receive(:process)
|
27
|
-
@connection.receive_data('GET')
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should process" do
|
31
|
-
@connection.process
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should rescue error in process" do
|
35
|
-
@connection.app.should_receive(:call).and_raise(StandardError)
|
36
|
-
@connection.process
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should rescue Timeout error in process" do
|
40
|
-
@connection.app.should_receive(:call).and_raise(Timeout::Error.new("timeout error not rescued"))
|
41
|
-
@connection.process
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should not return HTTP_X_FORWARDED_FOR as remote_address" do
|
45
|
-
@connection.request.env['HTTP_X_FORWARDED_FOR'] = '1.2.3.4'
|
46
|
-
@connection.stub!(:socket_address).and_return("127.0.0.1")
|
47
|
-
@connection.remote_address.should == "127.0.0.1"
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should return nil on error retreiving remote_address" do
|
51
|
-
@connection.stub!(:get_peername).and_raise(RuntimeError)
|
52
|
-
@connection.remote_address.should be_nil
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should return nil on nil get_peername" do
|
56
|
-
@connection.stub!(:get_peername).and_return(nil)
|
57
|
-
@connection.remote_address.should be_nil
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should return nil on empty get_peername" do
|
61
|
-
@connection.stub!(:get_peername).and_return('')
|
62
|
-
@connection.remote_address.should be_nil
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should return remote_address" do
|
66
|
-
@connection.stub!(:get_peername).and_return(Socket.pack_sockaddr_in(3000, '127.0.0.1'))
|
67
|
-
@connection.remote_address.should == '127.0.0.1'
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should not be persistent" do
|
71
|
-
@connection.should_not be_persistent
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should be persistent when response is and allowed" do
|
75
|
-
@connection.response.stub!(:persistent?).and_return(true)
|
76
|
-
@connection.can_persist!
|
77
|
-
@connection.should be_persistent
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should not be persistent when response is but not allowed" do
|
81
|
-
@connection.response.persistent!
|
82
|
-
@connection.should_not be_persistent
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should set request env as rack.multithread" do
|
86
|
-
EventMachine.should_receive(:defer)
|
87
|
-
|
88
|
-
@connection.threaded = true
|
89
|
-
@connection.process
|
90
|
-
|
91
|
-
@connection.request.env["rack.multithread"].should == true
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should set as threaded when app.deferred? is true" do
|
95
|
-
@connection.app.should_receive(:deferred?).and_return(true)
|
96
|
-
@connection.should be_threaded
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should not set as threaded when app.deferred? is false" do
|
100
|
-
@connection.app.should_receive(:deferred?).and_return(false)
|
101
|
-
@connection.should_not be_threaded
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should not set as threaded when app do not respond to deferred?" do
|
105
|
-
@connection.should_not be_threaded
|
106
|
-
end
|
107
|
-
end
|
@@ -1,267 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
include Controllers
|
3
|
-
|
4
|
-
describe Cluster, "with host and port" do
|
5
|
-
before do
|
6
|
-
@cluster = Cluster.new(:chdir => '/rails_app',
|
7
|
-
:address => '0.0.0.0',
|
8
|
-
:port => 3000,
|
9
|
-
:servers => 3,
|
10
|
-
:timeout => 10,
|
11
|
-
:log => 'thin.log',
|
12
|
-
:pid => 'thin.pid'
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should include port number in file names' do
|
17
|
-
@cluster.send(:include_server_number, 'thin.log', 3000).should == 'thin.3000.log'
|
18
|
-
@cluster.send(:include_server_number, 'thin.pid', 3000).should == 'thin.3000.pid'
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should call each server' do
|
22
|
-
calls = []
|
23
|
-
@cluster.send(:with_each_server) do |port|
|
24
|
-
calls << port
|
25
|
-
end
|
26
|
-
calls.should == [3000, 3001, 3002]
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should start on each port' do
|
30
|
-
Command.should_receive(:run).with(:start, options_for_port(3000))
|
31
|
-
Command.should_receive(:run).with(:start, options_for_port(3001))
|
32
|
-
Command.should_receive(:run).with(:start, options_for_port(3002))
|
33
|
-
|
34
|
-
@cluster.start
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should stop on each port' do
|
38
|
-
Command.should_receive(:run).with(:stop, options_for_port(3000))
|
39
|
-
Command.should_receive(:run).with(:stop, options_for_port(3001))
|
40
|
-
Command.should_receive(:run).with(:stop, options_for_port(3002))
|
41
|
-
|
42
|
-
@cluster.stop
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
def options_for_port(port)
|
47
|
-
{ :daemonize => true, :log => "thin.#{port}.log", :timeout => 10, :address => "0.0.0.0", :port => port, :pid => "thin.#{port}.pid", :chdir => "/rails_app" }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe Cluster, "with UNIX socket" do
|
52
|
-
before do
|
53
|
-
@cluster = Cluster.new(:chdir => '/rails_app',
|
54
|
-
:socket => '/tmp/thin.sock',
|
55
|
-
:address => '0.0.0.0',
|
56
|
-
:port => 3000,
|
57
|
-
:servers => 3,
|
58
|
-
:timeout => 10,
|
59
|
-
:log => 'thin.log',
|
60
|
-
:pid => 'thin.pid'
|
61
|
-
)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should include socket number in file names' do
|
65
|
-
@cluster.send(:include_server_number, 'thin.sock', 0).should == 'thin.0.sock'
|
66
|
-
@cluster.send(:include_server_number, 'thin', 0).should == 'thin.0'
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should exclude :address and :port options" do
|
70
|
-
@cluster.options.should_not have_key(:address)
|
71
|
-
@cluster.options.should_not have_key(:port)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'should call each server' do
|
75
|
-
calls = []
|
76
|
-
@cluster.send(:with_each_server) do |n|
|
77
|
-
calls << n
|
78
|
-
end
|
79
|
-
calls.should == [0, 1, 2]
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should start each server' do
|
83
|
-
Command.should_receive(:run).with(:start, options_for_socket(0))
|
84
|
-
Command.should_receive(:run).with(:start, options_for_socket(1))
|
85
|
-
Command.should_receive(:run).with(:start, options_for_socket(2))
|
86
|
-
|
87
|
-
@cluster.start
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should stop each server' do
|
91
|
-
Command.should_receive(:run).with(:stop, options_for_socket(0))
|
92
|
-
Command.should_receive(:run).with(:stop, options_for_socket(1))
|
93
|
-
Command.should_receive(:run).with(:stop, options_for_socket(2))
|
94
|
-
|
95
|
-
@cluster.stop
|
96
|
-
end
|
97
|
-
|
98
|
-
|
99
|
-
private
|
100
|
-
def options_for_socket(number)
|
101
|
-
{ :daemonize => true, :log => "thin.#{number}.log", :timeout => 10, :socket => "/tmp/thin.#{number}.sock", :pid => "thin.#{number}.pid", :chdir => "/rails_app" }
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe Cluster, "controlling only one server" do
|
106
|
-
before do
|
107
|
-
@cluster = Cluster.new(:chdir => '/rails_app',
|
108
|
-
:address => '0.0.0.0',
|
109
|
-
:port => 3000,
|
110
|
-
:servers => 3,
|
111
|
-
:timeout => 10,
|
112
|
-
:log => 'thin.log',
|
113
|
-
:pid => 'thin.pid',
|
114
|
-
:only => 3001
|
115
|
-
)
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'should call only specified server' do
|
119
|
-
calls = []
|
120
|
-
@cluster.send(:with_each_server) do |n|
|
121
|
-
calls << n
|
122
|
-
end
|
123
|
-
calls.should == [3001]
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should start only specified server" do
|
127
|
-
Command.should_receive(:run).with(:start, options_for_port(3001))
|
128
|
-
|
129
|
-
@cluster.start
|
130
|
-
end
|
131
|
-
|
132
|
-
private
|
133
|
-
def options_for_port(port)
|
134
|
-
{ :daemonize => true, :log => "thin.#{port}.log", :timeout => 10, :address => "0.0.0.0", :port => port, :pid => "thin.#{port}.pid", :chdir => "/rails_app" }
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe Cluster, "controlling only one server with UNIX socket" do
|
139
|
-
before do
|
140
|
-
@cluster = Cluster.new(:chdir => '/rails_app',
|
141
|
-
:socket => '/tmp/thin.sock',
|
142
|
-
:address => '0.0.0.0',
|
143
|
-
:port => 3000,
|
144
|
-
:servers => 3,
|
145
|
-
:timeout => 10,
|
146
|
-
:log => 'thin.log',
|
147
|
-
:pid => 'thin.pid',
|
148
|
-
:only => 1
|
149
|
-
)
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'should call only specified server' do
|
153
|
-
calls = []
|
154
|
-
@cluster.send(:with_each_server) do |n|
|
155
|
-
calls << n
|
156
|
-
end
|
157
|
-
calls.should == [1]
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
describe Cluster, "controlling only one server, by sequence number" do
|
162
|
-
before do
|
163
|
-
@cluster = Cluster.new(:chdir => '/rails_app',
|
164
|
-
:address => '0.0.0.0',
|
165
|
-
:port => 3000,
|
166
|
-
:servers => 3,
|
167
|
-
:timeout => 10,
|
168
|
-
:log => 'thin.log',
|
169
|
-
:pid => 'thin.pid',
|
170
|
-
:only => 1
|
171
|
-
)
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'should call only specified server' do
|
175
|
-
calls = []
|
176
|
-
@cluster.send(:with_each_server) do |n|
|
177
|
-
calls << n
|
178
|
-
end
|
179
|
-
calls.should == [3001]
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should start only specified server" do
|
183
|
-
Command.should_receive(:run).with(:start, options_for_port(3001))
|
184
|
-
|
185
|
-
@cluster.start
|
186
|
-
end
|
187
|
-
|
188
|
-
private
|
189
|
-
def options_for_port(port)
|
190
|
-
{ :daemonize => true, :log => "thin.#{port}.log", :timeout => 10, :address => "0.0.0.0", :port => port, :pid => "thin.#{port}.pid", :chdir => "/rails_app" }
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
describe Cluster, "with Swiftiply" do
|
195
|
-
before do
|
196
|
-
@cluster = Cluster.new(:chdir => '/rails_app',
|
197
|
-
:address => '0.0.0.0',
|
198
|
-
:port => 3000,
|
199
|
-
:servers => 3,
|
200
|
-
:timeout => 10,
|
201
|
-
:log => 'thin.log',
|
202
|
-
:pid => 'thin.pid',
|
203
|
-
:swiftiply => true
|
204
|
-
)
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'should call each server' do
|
208
|
-
calls = []
|
209
|
-
@cluster.send(:with_each_server) do |n|
|
210
|
-
calls << n
|
211
|
-
end
|
212
|
-
calls.should == [0, 1, 2]
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'should start each server' do
|
216
|
-
Command.should_receive(:run).with(:start, options_for_swiftiply(0))
|
217
|
-
Command.should_receive(:run).with(:start, options_for_swiftiply(1))
|
218
|
-
Command.should_receive(:run).with(:start, options_for_swiftiply(2))
|
219
|
-
|
220
|
-
@cluster.start
|
221
|
-
end
|
222
|
-
|
223
|
-
it 'should stop each server' do
|
224
|
-
Command.should_receive(:run).with(:stop, options_for_swiftiply(0))
|
225
|
-
Command.should_receive(:run).with(:stop, options_for_swiftiply(1))
|
226
|
-
Command.should_receive(:run).with(:stop, options_for_swiftiply(2))
|
227
|
-
|
228
|
-
@cluster.stop
|
229
|
-
end
|
230
|
-
|
231
|
-
private
|
232
|
-
def options_for_swiftiply(number)
|
233
|
-
{ :address => '0.0.0.0', :port => 3000, :daemonize => true, :log => "thin.#{number}.log", :timeout => 10, :pid => "thin.#{number}.pid", :chdir => "/rails_app", :swiftiply => true }
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe Cluster, "rolling restart" do
|
238
|
-
before do
|
239
|
-
@cluster = Cluster.new(:chdir => '/rails_app',
|
240
|
-
:address => '0.0.0.0',
|
241
|
-
:port => 3000,
|
242
|
-
:servers => 2,
|
243
|
-
:timeout => 10,
|
244
|
-
:log => 'thin.log',
|
245
|
-
:pid => 'thin.pid',
|
246
|
-
:onebyone => true,
|
247
|
-
:wait => 30
|
248
|
-
)
|
249
|
-
end
|
250
|
-
|
251
|
-
it "should restart servers one by one" do
|
252
|
-
Command.should_receive(:run).with(:stop, options_for_port(3000))
|
253
|
-
Command.should_receive(:run).with(:start, options_for_port(3000))
|
254
|
-
@cluster.should_receive(:wait_until_server_started).with(3000)
|
255
|
-
|
256
|
-
Command.should_receive(:run).with(:stop, options_for_port(3001))
|
257
|
-
Command.should_receive(:run).with(:start, options_for_port(3001))
|
258
|
-
@cluster.should_receive(:wait_until_server_started).with(3001)
|
259
|
-
|
260
|
-
@cluster.restart
|
261
|
-
end
|
262
|
-
|
263
|
-
private
|
264
|
-
def options_for_port(port)
|
265
|
-
{ :daemonize => true, :log => "thin.#{port}.log", :timeout => 10, :address => "0.0.0.0", :port => port, :pid => "thin.#{port}.pid", :chdir => "/rails_app" }
|
266
|
-
end
|
267
|
-
end
|