Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Moved code into test_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
bhb committed Jan 6, 2011
1 parent 682d10a commit 286594f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 61 deletions.
61 changes: 0 additions & 61 deletions test/rack-perftools-profiler_test.rb
Original file line number Diff line number Diff line change
@@ -1,66 +1,5 @@
require 'test_helper'

ITERATIONS = case RUBY_VERSION
when /1\.9\.1/
350_000 # Ruby 1.9.1 is that we need to add extra iterations to get profiling data
else
35_000
end

# From the Rack spec (http://rack.rubyforge.org/doc/files/SPEC.html) :
# The Body must respond to each and must only yield String values. The Body should not be an instance of String.
# ... The Body commonly is an Array of Strings, the application instance itself, or a File-like object.

class RackResponseBody
include Test::Unit::Assertions

def initialize(body)
assert !body.instance_of?(String)
@body = body
end

def to_s
str = ""
@body.each do |part|
str << part
end
str
end

end

class TestApp

def call(env)
case env['PATH_INFO']
when /method1/
ITERATIONS.times do
self.class.new.method1
end
GC.start
when /method2/
ITERATIONS.times do
self.class.new.method2
end
GC.start
end
[200, {}, ['Done']]
end

def method1
100.times do
1+2+3+4+5
end
end

def method2
100.times do
1+2+3+4+5
end
end

end

class RackPerftoolsProfilerTest < Test::Unit::TestCase
include Rack::PerftoolsProfiler

Expand Down
61 changes: 61 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,64 @@

class Test::Unit::TestCase
end

ITERATIONS = case RUBY_VERSION
when /1\.9\.1/
350_000 # Ruby 1.9.1 is that we need to add extra iterations to get profiling data
else
35_000
end

# From the Rack spec (http://rack.rubyforge.org/doc/files/SPEC.html) :
# The Body must respond to each and must only yield String values. The Body should not be an instance of String.
# ... The Body commonly is an Array of Strings, the application instance itself, or a File-like object.

class RackResponseBody
include Test::Unit::Assertions

def initialize(body)
assert !body.instance_of?(String)
@body = body
end

def to_s
str = ""
@body.each do |part|
str << part
end
str
end

end

class TestApp

def call(env)
case env['PATH_INFO']
when /method1/
ITERATIONS.times do
self.class.new.method1
end
GC.start
when /method2/
ITERATIONS.times do
self.class.new.method2
end
GC.start
end
[200, {}, ['Done']]
end

def method1
100.times do
1+2+3+4+5
end
end

def method2
100.times do
1+2+3+4+5
end
end

end

0 comments on commit 286594f

Please sign in to comment.