public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Improve specs stability.
Use benchmark_unit for perf specs.
Kill daemon processes in daemonizing specs.
Add error message before running spec if missing required gem.
macournoyer (author)
Sun Jan 20 13:48:48 -0800 2008
commit  d50a45e3eff6c028d9e298f49b2cd8167f8bb501
tree    a9c84b89061828cf5281c13af82a7fc01b00d7c6
parent  b698fe8f2512a85ed95bfa2922d7d1dc77f1e83c
...
1
 
2
3
4
...
1
2
3
4
5
0
@@ -1,4 +1,5 @@
0
 == 0.5.5 Pony release
0
+ * Improve specs stability.
0
  * Move request body to a Tempfile if too big (> 112 MB)
0
  * Remove useless check for max header size in Request (already done in the parser)
0
 
...
8
9
10
11
 
...
8
9
10
 
11
0
@@ -8,4 +8,4 @@ require 'lib/thin'
0
 
0
 Dir['tasks/**/*.rake'].each { |rake| load rake }
0
 
0
-task :default => [:compile, :spec]
0
+task :default => :spec
...
26
27
28
29
 
30
31
32
...
26
27
28
 
29
30
31
32
0
@@ -26,7 +26,7 @@ module Thin
0
     end
0
     
0
     def pid
0
- File.exist?(pid_file) ? open(pid_file).read : nil
0
+ File.exist?(pid_file) ? open(pid_file).read.to_i : nil
0
     end
0
     
0
     # Turns the current script into a daemon process that detaches from the console.
...
89
90
91
 
92
93
94
...
89
90
91
92
93
94
95
0
@@ -89,5 +89,6 @@ describe 'Daemonizing' do
0
   
0
   after do
0
     Process.kill(9, @pid.to_i) if @pid && Process.running?(@pid.to_i)
0
+ Process.kill(9, @server.pid) if @server.pid && Process.running?(@server.pid)
0
   end
0
 end
0
\ No newline at end of file
...
209
210
211
212
213
 
 
214
215
216
...
226
227
228
229
 
230
231
232
...
209
210
211
 
 
212
213
214
215
216
...
226
227
228
 
229
230
231
232
0
@@ -209,8 +209,8 @@ EOS
0
     proc { R("GET / HTTP/1.1\r\n#{big_headers}\r\n") }.should raise_error(InvalidRequest)
0
   end
0
   
0
- it "should be faster then #{max_parsing_time = 0.2} ms" do
0
- body = <<-EOS.chomp
0
+ it "should be faster then #{max_parsing_time = 0.0002} RubySeconds" do
0
+ body = <<-EOS.chomp.gsub("\n", "\r\n")
0
 POST /postit HTTP/1.1
0
 Host: localhost:3000
0
 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9
0
@@ -226,7 +226,7 @@ Content-Length: 37
0
 hi=there&name=marc&email=macournoyer@gmail.com
0
 EOS
0
     
0
- proc { R(body, true) }.should be_faster_then(max_parsing_time)
0
+ proc { R(body) }.should be_faster_then(max_parsing_time)
0
   end
0
   
0
   it 'should be comparable to Mongrel parser' do
...
52
53
54
55
 
56
57
58
...
52
53
54
 
55
56
57
58
0
@@ -52,7 +52,7 @@ describe Response do
0
     out.should include("\r\n\r\n<html></html>")
0
   end
0
   
0
- it "should be faster then #{max_parsing_time = 0.07} ms" do
0
+ it "should be faster then #{max_parsing_time = 0.00011} ms" do
0
     @response.body << <<-EOS
0
 <html><head><title>Dir listing</title></head>
0
 <body><h1>Listing stuff</h1><ul>
...
49
50
51
52
 
53
54
55
56
57
 
 
58
59
60
...
49
50
51
 
52
53
54
55
 
 
56
57
58
59
60
0
@@ -49,12 +49,12 @@ describe Server do
0
     post('/', :big => big).size.should == big.size + 4
0
   end
0
   
0
- it "should handle GET in less then #{get_request_time = 5} ms" do
0
+ it "should handle GET in less then #{get_request_time = 0.004} RubySecond" do
0
     proc { get('/') }.should be_faster_then(get_request_time)
0
   end
0
   
0
- it "should handle POST in less then #{post_request_time = 6} ms" do
0
- proc { post('/', :file => 'X' * 1000) }.should be_faster_then(get_request_time)
0
+ it "should handle POST in less then #{post_request_time = 0.007} RubySecond" do
0
+ proc { post('/', :file => 'X' * 1000) }.should be_faster_then(post_request_time)
0
   end
0
   
0
   after do
...
4
5
6
 
7
8
9
...
31
32
33
34
35
36
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
39
40
41
 
42
43
44
...
4
5
6
7
8
9
10
...
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
0
@@ -4,6 +4,7 @@ require 'spec'
0
 require 'benchmark'
0
 require 'timeout'
0
 require 'fileutils'
0
+require 'benchmark_unit'
0
 
0
 include Thin
0
 
0
@@ -31,14 +32,33 @@ module Matchers
0
       @max_time = max_time
0
     end
0
 
0
- def matches?(target)
0
- @target = target
0
- @time = Benchmark.measure { @target.call }.real * 1000
0
- @time <= @max_time
0
+ # Base on benchmark_unit/assertions#compare_benchmarks
0
+ def matches?(proc)
0
+ @time, multiplier = 0, 1
0
+
0
+ while (@time < 0.01) do
0
+ @time = Benchmark::Unit.measure do
0
+ multiplier.times &proc
0
+ end
0
+ multiplier *= 10
0
+ end
0
+
0
+ multiplier /= 10
0
+
0
+ iterations = (Benchmark::Unit::CLOCK_TARGET / @time).to_i * multiplier
0
+ iterations = 1 if iterations < 1
0
+
0
+ total = Benchmark::Unit.measure do
0
+ iterations.times &proc
0
+ end
0
+
0
+ @time = total / iterations
0
+
0
+ @time < @max_time
0
     end
0
     
0
     def failure_message(less_more=:less)
0
- "took #{@time} ms, should take #{less_more} then #{@max_time} ms"
0
+ "took <#{@time.inspect} RubySeconds>, should take #{less_more} than #{@max_time} RubySeconds."
0
     end
0
 
0
     def negative_failure_message
...
22
23
24
25
 
26
27
28
...
22
23
24
 
25
26
27
28
0
@@ -22,7 +22,7 @@ spec = Gem::Specification.new do |s|
0
   end
0
 
0
   s.files = %w(COPYING CHANGELOG README Rakefile) +
0
- Dir.glob("{benchmark,bin,doc,example,lib,spec}/**/*") +
0
+ Dir.glob("{benchmark,bin,doc,example,lib,spec,tasks}/**/*") +
0
                             Dir.glob("ext/**/*.{h,c,rb,rl}")
0
   
0
   if WIN
...
12
13
14
 
 
 
 
 
 
 
 
 
 
 
15
16
...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
0
@@ -12,4 +12,15 @@ else
0
   Spec::Rake::SpecTask.new('spec') do |t|
0
     t.spec_files = FileList['spec/**/*_spec.rb']
0
   end
0
+
0
+ task :check_spec_gems do
0
+ begin
0
+ require 'spec'
0
+ require 'benchmark_unit'
0
+ rescue LoadError
0
+ abort "To run specs, install rspec and benchmark_unit gems"
0
+ end
0
+ end
0
+
0
+ task :spec => [:check_spec_gems, :compile]
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.