Commit f70987ccde6f14d4ac17c29cd2d3cd4d8b4f6846

Authored by Antonio Terceiro
1 parent 301ce771

Adding a performance test for blog display

This way we won't introduce performance bottlenecks there anymore.

(ActionItem1617)
Showing 1 changed file with 64 additions and 0 deletions   Show diff stats
test/integration/performance_test.rb 0 → 100644
... ... @@ -0,0 +1,64 @@
  1 +require "#{File.dirname(__FILE__)}/../test_helper"
  2 +require 'benchmark'
  3 +
  4 +class PerformanceTest < ActionController::IntegrationTest
  5 +
  6 + all_fixtures
  7 +
  8 + # Testing blog page display. It should not present a linear increase in time
  9 + # needed to display a blog page with the increase in number of posts.
  10 + #
  11 + # GOOD BAD
  12 + #
  13 + # ^ ^ /
  14 + # | | /
  15 + # | _____ | /
  16 + # | / | /
  17 + # | / | /
  18 + # |/ |/
  19 + # +---------> +--------->
  20 + # 0 50 100 0 50 100
  21 + #
  22 + should 'not have a linear increase in time to display a blog page' do
  23 + person = create_profile('clueless')
  24 +
  25 + # no posts
  26 + time0 = (Benchmark.measure { get '/clueless/blog' })
  27 +
  28 + # first 50
  29 + create_posts(person)
  30 + time1 = (Benchmark.measure { get '/clueless/blog' })
  31 +
  32 + # another 50
  33 + create_posts(person)
  34 + time2 = (Benchmark.measure { get '/clueless/blog' })
  35 +
  36 + # should not scale linearly, i.e. the inclination of the first segment must
  37 + # be a lot higher than the one of the segment segment. To compensate for
  38 + # small variations due to hardware and/or execution environment, we are
  39 + # satisfied if the the inclination of the first segment is at least twice
  40 + # the inclination of the second segment.
  41 + a1 = (time1.total - time0.total)/50.0
  42 + a2 = (time2.total - time1.total)/50.0
  43 + assert a1 > a2*2, "#{a1} should be larger than #{a2} by at least a factor of 2"
  44 + end
  45 +
  46 + protected
  47 +
  48 + def create_profile(name)
  49 + person = create_user(name).person
  50 + Blog.create(:name => "Blog", :profile => person)
  51 + person
  52 + end
  53 +
  54 + def create_posts(profile)
  55 + postnumber = profile.articles.count
  56 + blog = profile.blog
  57 + 50.times do |i|
  58 + postnumber += 1
  59 + TinyMceArticle.create!(:profile => profile, :parent => blog, :name => "post number #{postnumber}")
  60 + end
  61 + end
  62 +
  63 +end
  64 +
... ...