diff --git a/plugins/people_block/test/unit/friends_block_test.rb b/plugins/people_block/test/unit/friends_block_test.rb index 54b435a..a4481ef 100644 --- a/plugins/people_block/test/unit/friends_block_test.rb +++ b/plugins/people_block/test/unit/friends_block_test.rb @@ -153,4 +153,59 @@ class FriendsBlockViewTest < ActionView::TestCase assert_tag_in_string render_block_footer(block), tag: 'a', attributes: {class: 'view-all', href: '/profile/mytestperson/friends' } end + + FACTOR = 1.8 + + # Testing blog page display. It should not present a linear increase in time + # needed to display a blog page with the increase in number of posts. + # + # GOOD BAD + # + # ^ ^ / + # | | / + # | _____ | / + # | / | / + # | / | / + # |/ |/ + # +---------> +---------> + # 0 50 100 0 50 100 + # + should 'not have a linear increase in time to display friends block' do + owner = fast_create(Person) + owner.boxes<< Box.new + block = FriendsBlock.create!(:box => owner.boxes.first) + + ActionView::Base.any_instance.stubs(:profile_image_link).returns('some name') + ActionView::Base.any_instance.stubs(:block_title).returns("") + + # no people + block.reload + time0 = (Benchmark.measure { 10.times { render_block_content(block) } }) + + # first 50 + 1.upto(50).map do |n| + p = create_user("user #{n}").person + owner.add_friend(p) + end + block.reload + time1 = (Benchmark.measure { 10.times { render_block_content(block) } }) + + # another 50 + 1.upto(50).map do |n| + p = create_user("user #{n}").person + owner.add_friend(p) + end + block.reload + time2 = (Benchmark.measure { 10.times { render_block_content(block) } }) + + # should not scale linearly, i.e. the inclination of the first segment must + # be a lot higher than the one of the segment segment. To compensate for + # small variations due to hardware and/or execution environment, we are + # satisfied if the the inclination of the first segment is at least twice + # the inclination of the second segment. + a1 = (time1.total - time0.total)/50.0 + a2 = (time2.total - time1.total)/50.0 + assert a1 > a2*FACTOR, "#{a1} should be larger than #{a2} by at least a factor of #{FACTOR}" + end + end diff --git a/plugins/people_block/test/unit/members_block_test.rb b/plugins/people_block/test/unit/members_block_test.rb index b15eb41..1c7816f 100644 --- a/plugins/people_block/test/unit/members_block_test.rb +++ b/plugins/people_block/test/unit/members_block_test.rb @@ -306,4 +306,60 @@ class MembersBlockViewTest < ActionView::TestCase assert_select '[href=/profile/mytestuser/members#admins-tab]' end end + + FACTOR = 1.8 + + # Testing blog page display. It should not present a linear increase in time + # needed to display a blog page with the increase in number of posts. + # + # GOOD BAD + # + # ^ ^ / + # | | / + # | _____ | / + # | / | / + # | / | / + # |/ |/ + # +---------> +---------> + # 0 50 100 0 50 100 + # + should 'not have a linear increase in time to display members block' do + owner = fast_create(Community) + owner.boxes<< Box.new + block = MembersBlock.create!(:box => owner.boxes.first) + + ActionView::Base.any_instance.stubs(:profile_image_link).returns('some name') + ActionView::Base.any_instance.stubs(:block_title).returns("") + + # no people + block.reload + time0 = (Benchmark.measure { 10.times { render_block_content(block) } }) + + 1.upto(50).map do |n| + p = create_user("user #{n}").person + owner.add_member(p) + end + + # first 50 + block.reload + time1 = (Benchmark.measure { 10.times { render_block_content(block) } }) + + 1.upto(50).map do |n| + p = create_user("user 1#{n}").person + owner.add_member(p) + end + block.reload + # another 50 + time2 = (Benchmark.measure { 10.times { render_block_content(block) } }) + + # should not scale linearly, i.e. the inclination of the first segment must + # be a lot higher than the one of the segment segment. To compensate for + # small variations due to hardware and/or execution environment, we are + # satisfied if the the inclination of the first segment is at least twice + # the inclination of the second segment. + a1 = (time1.total - time0.total)/50.0 + a2 = (time2.total - time1.total)/50.0 + assert a1 > a2*FACTOR, "#{a1} should be larger than #{a2} by at least a factor of #{FACTOR}" + end + end diff --git a/plugins/people_block/test/unit/people_block_test.rb b/plugins/people_block/test/unit/people_block_test.rb index 433214f..4de9470 100644 --- a/plugins/people_block/test/unit/people_block_test.rb +++ b/plugins/people_block/test/unit/people_block_test.rb @@ -145,4 +145,57 @@ class PeopleBlockViewTest < ActionView::TestCase assert_select '[href=/search/people]' end end + + FACTOR = 1.8 + + # Testing blog page display. It should not present a linear increase in time + # needed to display a blog page with the increase in number of posts. + # + # GOOD BAD + # + # ^ ^ / + # | | / + # | _____ | / + # | / | / + # | / | / + # |/ |/ + # +---------> +---------> + # 0 50 100 0 50 100 + # + should 'not have a linear increase in time to display people block' do + owner = fast_create(Environment) + owner.boxes<< Box.new + block = PeopleBlock.create!(:box => owner.boxes.first) + + ActionView::Base.any_instance.stubs(:profile_image_link).returns('some name') + ActionView::Base.any_instance.stubs(:block_title).returns("") + + # no people + block.reload + time0 = (Benchmark.measure { 10.times { render_block_content(block) } }) + + # first 500 + 1.upto(50).map do + fast_create(Person, :environment_id => owner.id) + end + block.reload + time1 = (Benchmark.measure { 10.times { render_block_content(block) } }) + + # another 50 + 1.upto(50).map do + fast_create(Person, :environment_id => owner.id) + end + block.reload + time2 = (Benchmark.measure { 10.times { render_block_content(block) } }) + + # should not scale linearly, i.e. the inclination of the first segment must + # be a lot higher than the one of the segment segment. To compensate for + # small variations due to hardware and/or execution environment, we are + # satisfied if the the inclination of the first segment is at least twice + # the inclination of the second segment. + a1 = (time1.total - time0.total)/50.0 + a2 = (time2.total - time1.total)/50.0 + assert a1 > a2*FACTOR, "#{a1} should be larger than #{a2} by at least a factor of #{FACTOR}" + end + end diff --git a/plugins/people_block/views/blocks/people_base.html.erb b/plugins/people_block/views/blocks/people_base.html.erb index ea7e484..a4d24ef 100644 --- a/plugins/people_block/views/blocks/people_base.html.erb +++ b/plugins/people_block/views/blocks/people_base.html.erb @@ -3,9 +3,9 @@ <%= block_title(block.view_title) %>
- <% unless block.profiles.count == 0 %> + <% unless block.profile_count == 0 %>