thin 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/CHANGELOG +8 -0
  2. data/README.md +83 -0
  3. data/Rakefile +9 -32
  4. data/example/vlad.rake +1 -1
  5. data/lib/rack/adapter/loader.rb +0 -16
  6. data/lib/thin.rb +22 -24
  7. data/lib/thin/backends/base.rb +3 -1
  8. data/lib/thin/connection.rb +9 -8
  9. data/lib/thin/daemonizing.rb +3 -1
  10. data/lib/thin/logging.rb +1 -1
  11. data/lib/thin/runner.rb +36 -36
  12. data/lib/thin/server.rb +13 -0
  13. data/lib/thin/version.rb +3 -3
  14. metadata +5 -91
  15. data/README +0 -69
  16. data/benchmark/abc +0 -51
  17. data/benchmark/benchmarker.rb +0 -80
  18. data/benchmark/runner +0 -82
  19. data/spec/backends/swiftiply_client_spec.rb +0 -66
  20. data/spec/backends/tcp_server_spec.rb +0 -33
  21. data/spec/backends/unix_server_spec.rb +0 -37
  22. data/spec/command_spec.rb +0 -25
  23. data/spec/configs/cluster.yml +0 -9
  24. data/spec/configs/single.yml +0 -9
  25. data/spec/connection_spec.rb +0 -107
  26. data/spec/controllers/cluster_spec.rb +0 -267
  27. data/spec/controllers/controller_spec.rb +0 -129
  28. data/spec/controllers/service_spec.rb +0 -50
  29. data/spec/daemonizing_spec.rb +0 -200
  30. data/spec/headers_spec.rb +0 -40
  31. data/spec/logging_spec.rb +0 -52
  32. data/spec/perf/request_perf_spec.rb +0 -50
  33. data/spec/perf/response_perf_spec.rb +0 -19
  34. data/spec/perf/server_perf_spec.rb +0 -39
  35. data/spec/rack/loader_spec.rb +0 -42
  36. data/spec/rack/rails_adapter_spec.rb +0 -173
  37. data/spec/rails_app/app/controllers/application.rb +0 -10
  38. data/spec/rails_app/app/controllers/simple_controller.rb +0 -19
  39. data/spec/rails_app/app/helpers/application_helper.rb +0 -3
  40. data/spec/rails_app/app/views/simple/index.html.erb +0 -15
  41. data/spec/rails_app/config/boot.rb +0 -109
  42. data/spec/rails_app/config/environment.rb +0 -64
  43. data/spec/rails_app/config/environments/development.rb +0 -18
  44. data/spec/rails_app/config/environments/production.rb +0 -19
  45. data/spec/rails_app/config/environments/test.rb +0 -22
  46. data/spec/rails_app/config/initializers/inflections.rb +0 -10
  47. data/spec/rails_app/config/initializers/mime_types.rb +0 -5
  48. data/spec/rails_app/config/routes.rb +0 -35
  49. data/spec/rails_app/public/404.html +0 -30
  50. data/spec/rails_app/public/422.html +0 -30
  51. data/spec/rails_app/public/500.html +0 -30
  52. data/spec/rails_app/public/dispatch.cgi +0 -10
  53. data/spec/rails_app/public/dispatch.fcgi +0 -24
  54. data/spec/rails_app/public/dispatch.rb +0 -10
  55. data/spec/rails_app/public/favicon.ico +0 -0
  56. data/spec/rails_app/public/images/rails.png +0 -0
  57. data/spec/rails_app/public/index.html +0 -277
  58. data/spec/rails_app/public/javascripts/application.js +0 -2
  59. data/spec/rails_app/public/javascripts/controls.js +0 -963
  60. data/spec/rails_app/public/javascripts/dragdrop.js +0 -972
  61. data/spec/rails_app/public/javascripts/effects.js +0 -1120
  62. data/spec/rails_app/public/javascripts/prototype.js +0 -4225
  63. data/spec/rails_app/public/robots.txt +0 -5
  64. data/spec/rails_app/script/about +0 -3
  65. data/spec/rails_app/script/console +0 -3
  66. data/spec/rails_app/script/destroy +0 -3
  67. data/spec/rails_app/script/generate +0 -3
  68. data/spec/rails_app/script/performance/benchmarker +0 -3
  69. data/spec/rails_app/script/performance/profiler +0 -3
  70. data/spec/rails_app/script/performance/request +0 -3
  71. data/spec/rails_app/script/plugin +0 -3
  72. data/spec/rails_app/script/process/inspector +0 -3
  73. data/spec/rails_app/script/process/reaper +0 -3
  74. data/spec/rails_app/script/process/spawner +0 -3
  75. data/spec/rails_app/script/runner +0 -3
  76. data/spec/rails_app/script/server +0 -3
  77. data/spec/request/mongrel_spec.rb +0 -39
  78. data/spec/request/parser_spec.rb +0 -254
  79. data/spec/request/persistent_spec.rb +0 -35
  80. data/spec/request/processing_spec.rb +0 -50
  81. data/spec/response_spec.rb +0 -102
  82. data/spec/runner_spec.rb +0 -168
  83. data/spec/server/builder_spec.rb +0 -44
  84. data/spec/server/pipelining_spec.rb +0 -110
  85. data/spec/server/robustness_spec.rb +0 -34
  86. data/spec/server/stopping_spec.rb +0 -55
  87. data/spec/server/swiftiply.yml +0 -6
  88. data/spec/server/swiftiply_spec.rb +0 -32
  89. data/spec/server/tcp_spec.rb +0 -47
  90. data/spec/server/threaded_spec.rb +0 -27
  91. data/spec/server/unix_socket_spec.rb +0 -26
  92. data/spec/server_spec.rb +0 -100
  93. data/spec/spec_helper.rb +0 -234
  94. data/tasks/announce.rake +0 -22
  95. data/tasks/deploy.rake +0 -13
  96. data/tasks/email.erb +0 -27
  97. data/tasks/gem.rake +0 -65
  98. data/tasks/rdoc.rake +0 -25
  99. data/tasks/site.rake +0 -15
  100. data/tasks/spec.rake +0 -43
  101. data/tasks/stats.rake +0 -28
@@ -1,129 +0,0 @@
1
- require 'spec_helper'
2
- require 'ostruct'
3
- include Controllers
4
-
5
- describe Controller, 'start' do
6
- before do
7
- @controller = Controller.new(:address => '0.0.0.0',
8
- :port => 3000,
9
- :pid => 'thin.pid',
10
- :log => 'thin.log',
11
- :timeout => 60,
12
- :max_conns => 2000,
13
- :max_persistent_conns => 1000,
14
- :adapter => 'rails')
15
-
16
- @server = OpenStruct.new
17
- @adapter = OpenStruct.new
18
-
19
- Server.should_receive(:new).with('0.0.0.0', 3000, @controller.options).and_return(@server)
20
- @server.should_receive(:config)
21
- Rack::Adapter::Rails.stub!(:new).and_return(@adapter)
22
- end
23
-
24
- it "should configure server" do
25
- @controller.start
26
-
27
- @server.app.should == @adapter
28
- @server.pid_file.should == 'thin.pid'
29
- @server.log_file.should == 'thin.log'
30
- @server.maximum_connections.should == 2000
31
- @server.maximum_persistent_connections.should == 1000
32
- end
33
-
34
- it "should start as daemon" do
35
- @controller.options[:daemonize] = true
36
- @controller.options[:user] = true
37
- @controller.options[:group] = true
38
-
39
- @server.should_receive(:daemonize)
40
- @server.should_receive(:change_privilege)
41
-
42
- @controller.start
43
- end
44
-
45
- it "should configure Rails adapter" do
46
- Rack::Adapter::Rails.should_receive(:new).with(@controller.options.merge(:root => nil))
47
-
48
- @controller.start
49
- end
50
-
51
- it "should mount app under :prefix" do
52
- @controller.options[:prefix] = '/app'
53
- @controller.start
54
-
55
- @server.app.class.should == Rack::URLMap
56
- end
57
-
58
- it "should mount Stats adapter under :stats" do
59
- @controller.options[:stats] = '/stats'
60
- @controller.start
61
-
62
- @server.app.class.should == Stats::Adapter
63
- end
64
-
65
- it "should load app from Rack config" do
66
- @controller.options[:rackup] = File.dirname(__FILE__) + '/../../example/config.ru'
67
- @controller.start
68
-
69
- @server.app.class.should == Proc
70
- end
71
-
72
- it "should load app from ruby file" do
73
- @controller.options[:rackup] = File.dirname(__FILE__) + '/../../example/myapp.rb'
74
- @controller.start
75
-
76
- @server.app.should == Myapp
77
- end
78
-
79
- it "should throwup if rackup is not a .ru or .rb file" do
80
- proc do
81
- @controller.options[:rackup] = File.dirname(__FILE__) + '/../../example/myapp.foo'
82
- @controller.start
83
- end.should raise_error(RuntimeError, /please/)
84
- end
85
-
86
- it "should set server as threaded" do
87
- @controller.options[:threaded] = true
88
- @controller.start
89
-
90
- @server.threaded.should be_true
91
- end
92
-
93
- it "should set RACK_ENV" do
94
- @controller.options[:rackup] = File.dirname(__FILE__) + '/../../example/config.ru'
95
- @controller.options[:environment] = "lolcat"
96
- @controller.start
97
-
98
- ENV['RACK_ENV'].should == "lolcat"
99
- end
100
-
101
- end
102
-
103
- describe Controller do
104
- before do
105
- @controller = Controller.new(:pid => 'thin.pid', :timeout => 10)
106
- @controller.stub!(:wait_for_file)
107
- end
108
-
109
- it "should stop" do
110
- Server.should_receive(:kill).with('thin.pid', 10)
111
- @controller.stop
112
- end
113
-
114
- it "should restart" do
115
- Server.should_receive(:restart).with('thin.pid')
116
- @controller.restart
117
- end
118
-
119
- it "should write configuration file" do
120
- silence_stream(STDOUT) do
121
- Controller.new(:config => 'test.yml', :port => 5000, :address => '127.0.0.1').config
122
- end
123
-
124
- File.read('test.yml').should include('port: 5000', 'address: 127.0.0.1')
125
- File.read('test.yml').should_not include('config: ')
126
-
127
- File.delete('test.yml')
128
- end
129
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
- include Controllers
3
-
4
- describe Service do
5
- before(:all) do
6
- silence_warnings do
7
- Service::INITD_PATH = 'tmp/sandbox' + Service::INITD_PATH
8
- Service::DEFAULT_CONFIG_PATH = 'tmp/sandbox' + Service::DEFAULT_CONFIG_PATH
9
- end
10
- end
11
-
12
- before do
13
- Thin.stub!(:linux?).and_return(true)
14
- FileUtils.mkdir_p 'tmp/sandbox'
15
-
16
- @service = Service.new(:all => 'spec/configs')
17
- end
18
-
19
- it "should call command for each config file" do
20
- Command.should_receive(:run).with(:start, :config => 'spec/configs/cluster.yml', :daemonize => true)
21
- Command.should_receive(:run).with(:start, :config => 'spec/configs/single.yml', :daemonize => true)
22
-
23
- @service.start
24
- end
25
-
26
- it "should create /etc/init.d/thin file when calling install" do
27
- @service.install
28
-
29
- File.exist?(Service::INITD_PATH).should be_true
30
- File.read(Service::INITD_PATH).should include('CONFIG_PATH=tmp/sandbox/etc/thin',
31
- 'SCRIPT_NAME=tmp/sandbox/etc/init.d/thin',
32
- 'DAEMON=' + Command.script)
33
- end
34
-
35
- it "should create /etc/thin dir when calling install" do
36
- @service.install
37
-
38
- File.directory?(Service::DEFAULT_CONFIG_PATH).should be_true
39
- end
40
-
41
- it "should include specified path in /etc/init.d/thin script" do
42
- @service.install('tmp/sandbox/usr/thin')
43
-
44
- File.read(Service::INITD_PATH).should include('CONFIG_PATH=tmp/sandbox/usr/thin')
45
- end
46
-
47
- after do
48
- FileUtils.rm_rf 'tmp/sandbox'
49
- end
50
- end
@@ -1,200 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class TestServer
4
- include Logging # Daemonizable should include this?
5
- include Daemonizable
6
-
7
- def stop
8
- end
9
-
10
- def name
11
- 'Thin test server'
12
- end
13
- end
14
-
15
- describe 'Daemonizing' do
16
- before :all do
17
- @logfile = File.dirname(__FILE__) + '/../log/daemonizing_test.log'
18
- @pidfile = 'test.pid'
19
- File.delete(@logfile) if File.exist?(@logfile)
20
- File.delete(@pidfile) if File.exist?(@pidfile)
21
- end
22
-
23
- before :each do
24
- @server = TestServer.new
25
- @server.log_file = @logfile
26
- @server.pid_file = @pidfile
27
- @pid = nil
28
- end
29
-
30
- it 'should have a pid file' do
31
- @server.should respond_to(:pid_file)
32
- @server.should respond_to(:pid_file=)
33
- end
34
-
35
- it 'should create a pid file' do
36
- @pid = fork do
37
- @server.daemonize
38
- sleep 1
39
- end
40
-
41
- sleep 1
42
- Process.wait(@pid)
43
- File.exist?(@server.pid_file).should be_true
44
- @pid = @server.pid
45
-
46
- proc { sleep 0.1 while File.exist?(@server.pid_file) }.should take_less_then(5)
47
- end
48
-
49
- it 'should redirect stdio to a log file' do
50
- @pid = fork do
51
- @server.log_file = 'daemon_test.log'
52
- @server.daemonize
53
-
54
- puts "simple puts"
55
- STDERR.puts "STDERR.puts"
56
- STDOUT.puts "STDOUT.puts"
57
- end
58
- Process.wait(@pid)
59
- # Wait for the file to close and magical stuff to happen
60
- proc { sleep 0.1 until File.exist?('daemon_test.log') }.should take_less_then(3)
61
- sleep 0.5
62
-
63
- @pid = @server.pid
64
-
65
- log = File.read('daemon_test.log')
66
- log.should include('simple puts', 'STDERR.puts', 'STDOUT.puts')
67
-
68
- File.delete 'daemon_test.log'
69
- end
70
-
71
- it 'should change privilege' do
72
- @pid = fork do
73
- @server.daemonize
74
- @server.change_privilege('root', 'admin')
75
- end
76
- Process.wait(@pid)
77
- $?.should be_a_success
78
- end
79
-
80
- it 'should kill process in pid file' do
81
- @pid = fork do
82
- @server.daemonize
83
- loop { sleep 3 }
84
- end
85
-
86
- server_should_start_in_less_then 3
87
-
88
- @pid = @server.pid
89
-
90
- timeout(10) do
91
- silence_stream STDOUT do
92
- TestServer.kill(@server.pid_file, 1)
93
- end
94
- end
95
-
96
- File.exist?(@server.pid_file).should be_false
97
- end
98
-
99
- it 'should force kill process in pid file' do
100
- @pid = fork do
101
- @server.daemonize
102
- loop { sleep 3 }
103
- end
104
-
105
- server_should_start_in_less_then 3
106
-
107
- @pid = @server.pid
108
-
109
- timeout(10) do
110
- silence_stream STDOUT do
111
- TestServer.kill(@server.pid_file, 0)
112
- end
113
- end
114
-
115
- File.exist?(@server.pid_file).should be_false
116
- end
117
-
118
- it 'should send kill signal if timeout' do
119
- @pid = fork do
120
- @server.should_receive(:stop) # pretend we cannot handle the INT signal
121
- @server.daemonize
122
- sleep 5
123
- end
124
-
125
- server_should_start_in_less_then 10
126
-
127
- @pid = @server.pid
128
-
129
- silence_stream STDOUT do
130
- TestServer.kill(@server.pid_file, 1)
131
- end
132
-
133
- sleep 1
134
-
135
- File.exist?(@server.pid_file).should be_false
136
- Process.running?(@pid).should be_false
137
- end
138
-
139
- it "should restart" do
140
- @pid = fork do
141
- @server.on_restart {}
142
- @server.daemonize
143
- sleep 5
144
- end
145
-
146
- server_should_start_in_less_then 10
147
-
148
- @pid = @server.pid
149
-
150
- silence_stream STDOUT do
151
- TestServer.restart(@server.pid_file)
152
- end
153
-
154
- proc { sleep 0.1 while File.exist?(@server.pid_file) }.should take_less_then(10)
155
- end
156
-
157
- it "should ignore if no restart block specified" do
158
- TestServer.restart(@server.pid_file)
159
- end
160
-
161
- it "should not restart when not running" do
162
- silence_stream STDOUT do
163
- TestServer.restart(@server.pid_file)
164
- end
165
- end
166
-
167
- it "should exit and raise if pid file already exist" do
168
- @pid = fork do
169
- @server.daemonize
170
- sleep 5
171
- end
172
- server_should_start_in_less_then 10
173
-
174
- @pid = @server.pid
175
-
176
- proc { @server.daemonize }.should raise_error(PidFileExist)
177
-
178
- File.exist?(@server.pid_file).should be_true
179
- end
180
-
181
- it "should should delete pid file if stale" do
182
- # Create a file w/ a PID that does not exist
183
- File.open(@server.pid_file, 'w') { |f| f << 999999999 }
184
-
185
- @server.send(:remove_stale_pid_file)
186
-
187
- File.exist?(@server.pid_file).should be_false
188
- end
189
-
190
- after do
191
- Process.kill(9, @pid.to_i) if @pid && Process.running?(@pid.to_i)
192
- Process.kill(9, @server.pid) if @server.pid && Process.running?(@server.pid)
193
- File.delete(@server.pid_file) rescue nil
194
- end
195
-
196
- private
197
- def server_should_start_in_less_then(sec=10)
198
- proc { sleep 0.1 until File.exist?(@server.pid_file) }.should take_less_then(10)
199
- end
200
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Headers do
4
- before do
5
- @headers = Headers.new
6
- end
7
-
8
- it 'should allow duplicate on some fields' do
9
- @headers['Set-Cookie'] = 'twice'
10
- @headers['Set-Cookie'] = 'is cooler the once'
11
-
12
- @headers.to_s.should == "Set-Cookie: twice\r\nSet-Cookie: is cooler the once\r\n"
13
- end
14
-
15
- it 'should overwrite value on non duplicate fields' do
16
- @headers['Host'] = 'this is unique'
17
- @headers['Host'] = 'so is this'
18
-
19
- @headers.to_s.should == "Host: this is unique\r\n"
20
- end
21
-
22
- it 'should output to string' do
23
- @headers['Host'] = 'localhost:3000'
24
- @headers['Set-Cookie'] = 'twice'
25
- @headers['Set-Cookie'] = 'is cooler the once'
26
-
27
- @headers.to_s.should == "Host: localhost:3000\r\nSet-Cookie: twice\r\nSet-Cookie: is cooler the once\r\n"
28
- end
29
-
30
- it 'should ignore nil values' do
31
- @headers['Something'] = nil
32
- @headers.to_s.should_not include('Something: ')
33
- end
34
-
35
- it 'should format Time values correctly' do
36
- time = Time.now
37
- @headers['Modified-At'] = time
38
- @headers.to_s.should include("Modified-At: #{time.httpdate}")
39
- end
40
- end
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class TestLogging
4
- include Logging
5
- end
6
-
7
- describe Logging do
8
- before do
9
- Logging.silent = false
10
- @object = TestLogging.new
11
- end
12
-
13
- it "should output debug when set to true" do
14
- Logging.debug = true
15
- @object.should_receive(:puts)
16
- @object.debug 'hi'
17
- end
18
-
19
- it "should output trace when set to true" do
20
- Logging.trace = true
21
- @object.should_receive(:puts)
22
- @object.trace 'hi'
23
- end
24
-
25
- it "should not output when silenced" do
26
- Logging.silent = true
27
- @object.should_not_receive(:puts)
28
- @object.log 'hi'
29
- end
30
-
31
- it "should not output when silenced as instance method" do
32
- @object.silent = true
33
-
34
- @object.should_not_receive(:puts)
35
- @object.log 'hi'
36
- end
37
-
38
- it "should be usable as module functions" do
39
- Logging.silent = true
40
- Logging.log "hi"
41
- end
42
-
43
- it "should print errors to STDERR" do
44
- error = mock(:error, :backtrace => Array("PC LOAD LETTER"))
45
- STDERR.should_receive(:print).with(/PC LOAD LETTER/)
46
- @object.log_error(error)
47
- end
48
-
49
- after do
50
- Logging.silent = true
51
- end
52
- end