test/test_evdispatch.rb in evdispatch-0.1.5 vs test/test_evdispatch.rb in evdispatch-0.2.0
- old
+ new
@@ -1,16 +1,24 @@
require File.dirname(__FILE__) + '/test_helper.rb'
class TestEvdispatch < Test::Unit::TestCase
+ def is_linux?
+ !(`uname`.grep(/linux/i)).empty?
+ end
+
def test_object_test
# start up the test server
- pid = fork do
- require File.dirname(__FILE__) + '/../ext/revdispatch/server'
- start_test_server
+ if is_linux?
+ pid = fork do
+ require File.dirname(__FILE__) + '/../ext/revdispatch/server'
+ start_test_server
+ end
+ sleep 1
+ else
+ STDERR.puts "make sure '#{File.dirname(__FILE__) + '/../ext/revdispatch/server'} start' is running..."
end
- sleep 1 unless ARGV[0] == 'r'
d = Evdispatch::Loop.new
# start the event loop thread
d.start
@@ -20,18 +28,18 @@
ObjectSpace.garbage_collect
10.times do
begin
start_count = ObjectSpace.each_object { }
- duration = run_trial(d, 10)
+ duration = run_trial(d, 100)
new_count = ObjectSpace.each_object { }
puts "10 trials: #{duration} seconds, new objects #{new_count - start_count}, #{new_count} - #{start_count}"
end
begin
start_count = ObjectSpace.each_object { }
- duration = run_trial(d, 100)
+ duration = run_trial(d, 200)
new_count = ObjectSpace.each_object { }
puts "100 trials: #{duration} seconds, new objects #{new_count - start_count}, #{new_count} - #{start_count}"
end
end
@@ -48,11 +56,11 @@
puts "After garbage collection objects: #{count}"
# sometime later you can stop the event loop
d.stop
ensure
- Process.kill('HUP', pid) unless ARGV[0] == 'r'
+ Process.kill('HUP', pid) if is_linux?
end
def request_bytes_from( d, base, amount, range )
ids = []
amount.times do|i|
@@ -74,10 +82,10 @@
def run_trial( d, trials )
ebbbase = "http://127.0.0.1:4044/"
timer = Time.now
ids = request_bytes_from( d, ebbbase, trials, 1000 )
- ids += request_delay_from( d, ebbbase, trials, 1 )
+ #ids += request_delay_from( d, ebbbase, trials, 1 )
# wait for each response
puts "expecting #{ids.size} responses..."
ids.each do|id|
response = d.response( id )