Sha256: 270e833470a621f7c08ffd6ca1946e81f3951eeb93cfcc40033226d08234d70d

Contents?: true

Size: 1.69 KB

Versions: 11

Compression:

Stored size: 1.69 KB

Contents

require File.dirname(__FILE__) + '/../test_helper'

class BacklogsControllerTest < Test::Unit::TestCase
  PORT = 4000
  
  def setup
    @server_thread = IO.popen("script/server -e test -p #{PORT}")
    Thread.start do
      loop do
        lines = @server_thread.readline
        #puts lines
      end
    end
    sleep 4
  end
  
  def teardown
    if @server_thread
      Process.kill("TERM", @server_thread.pid)
    end
  end
  
  def test_lots_of_requests
    runs = 3
    no_of_threads = 2
    hits_per_thread = 5
    
    duration = with_timing("First") {get_burn_down_chart}
    first_hit_limit = 12
    assert duration <= first_hit_limit, "Request took #{duration} seconds.  Should be less than #{first_hit_limit} seconds."
    
    runs.times do |run_no|
      duration = with_timing((run_no+1)*no_of_threads*hits_per_thread, no_of_threads*hits_per_thread) do
        threads = (1..no_of_threads).map do |i| 
          Thread.new do 
            hits_per_thread.times {get_burn_down_chart}
          end
        end
        threads.each {|thread| thread.join}
      end
      maximum_duration = 6.0 * no_of_threads * hits_per_thread
      assert duration <= maximum_duration, "Performance to low.  Expected #{maximum_duration} or less, took #{duration}."
    end
  end
  
  private
  
  def with_timing title = "Time", count = 1
    start = Time.now
    yield
    stop = Time.now
    duration = stop-start
    puts "#{title}: #{'%.1f' % duration}s, #{(count/duration).to_i if count}/s"
    duration
  end
  
  def get_burn_down_chart
    path = '/parties/burn_down_chart/1'
    Net::HTTP::start('localhost', port = PORT) do |http|
      response = http.get path
      assert response.body =~ /^.PNG/
    end
  end
  
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
backlog-0.13.1 test/performance/test_threaded.rb
backlog-0.14.0 test/performance/test_threaded.rb
backlog-0.14.2 test/performance/test_threaded.rb
backlog-0.14.3 test/performance/test_threaded.rb
backlog-0.14.1 test/performance/test_threaded.rb
backlog-0.14.4 test/performance/test_threaded.rb
backlog-0.15.0 test/performance/test_threaded.rb
backlog-0.15.1 test/performance/test_threaded.rb
backlog-0.16.0 test/performance/test_threaded.rb
backlog-0.17.0 test/performance/test_threaded.rb
backlog-0.17.1 test/performance/test_threaded.rb