From 22f9f59a9a3501a366a63c461d7f3951c9da67dc Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 21 May 2016 17:40:40 +0200 Subject: [PATCH] Improved timings. --- test/unit/cache_test.rb | 20 +-- .../organization_ref_object_touch_test.rb | 36 +++--- test/unit/recent_view_test.rb | 116 +++++++++--------- 3 files changed, 86 insertions(+), 86 deletions(-) diff --git a/test/unit/cache_test.rb b/test/unit/cache_test.rb index cee7d292e..926d5f57d 100644 --- a/test/unit/cache_test.rb +++ b/test/unit/cache_test.rb @@ -81,10 +81,10 @@ class CacheTest < ActiveSupport::TestCase key: 'some valueöäüß2', }, param: { - expires_in: 5.seconds, + expires_in: 3.seconds, } }, - sleep: 10, + sleep: 5, verify: { key: '123', data: nil @@ -93,10 +93,10 @@ class CacheTest < ActiveSupport::TestCase ] tests.each { |test| if test[:set] - Cache.write( test[:set], test[:set][:data] ) + Cache.write(test[:set], test[:set][:data]) end if test[:delete] - Cache.delete( test[:delete][:key] ) + Cache.delete(test[:delete][:key]) end if test[:cleanup] Cache.clear @@ -105,17 +105,17 @@ class CacheTest < ActiveSupport::TestCase sleep test[:sleep] end if test[:verify] - cache = Cache.get( test[:verify] ) - assert_equal( cache, test[:verify][:data], 'verify' ) + cache = Cache.get(test[:verify]) + assert_equal(cache, test[:verify][:data], 'verify') end } end # verify if second cache write overwrite first one test 'cache reset' do - Cache.write( 'some_reset_key', 123 ) - Cache.write( 'some_reset_key', 12_356 ) - cache = Cache.get( 'some_reset_key' ) - assert_equal( cache, 12_356, 'verify' ) + Cache.write('some_reset_key', 123) + Cache.write('some_reset_key', 12_356) + cache = Cache.get('some_reset_key') + assert_equal(cache, 12_356, 'verify') end end diff --git a/test/unit/organization_ref_object_touch_test.rb b/test/unit/organization_ref_object_touch_test.rb index 5071fd04c..dd599326d 100644 --- a/test/unit/organization_ref_object_touch_test.rb +++ b/test/unit/organization_ref_object_touch_test.rb @@ -71,51 +71,51 @@ class OrganizationRefObjectTouchTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - assert( ticket, 'ticket created' ) - assert_equal( ticket.customer.id, customer1.id ) - assert_equal( ticket.organization.id, organization1.id ) + assert(ticket, 'ticket created') + assert_equal(ticket.customer.id, customer1.id ) + assert_equal(ticket.organization.id, organization1.id ) - sleep 6 + sleep 4 organization1.name = 'Ref Object Update Org 1/1' organization1.save # check if ticket and customer has been touched ticket = Ticket.find(ticket.id) - if ticket.updated_at > 4.seconds.ago - assert( true, 'ticket.updated_at has been updated' ) + if ticket.updated_at > 2.seconds.ago + assert(true, 'ticket.updated_at has been updated') else - assert( false, 'ticket.updated_at has not been updated' ) + assert(false, 'ticket.updated_at has not been updated') end customer1 = User.find(customer1.id) - if customer1.updated_at > 4.seconds.ago - assert( true, 'customer1.updated_at has been updated' ) + if customer1.updated_at > 2.seconds.ago + assert(true, 'customer1.updated_at has been updated') else - assert( false, 'customer1.updated_at has not been updated' ) + assert(false, 'customer1.updated_at has not been updated') end - sleep 6 + sleep 4 customer2.organization_id = organization1.id customer2.save # check if customer1 and organization has been touched customer1 = User.find(customer1.id) - if customer1.updated_at > 4.seconds.ago - assert( true, 'customer1.updated_at has been updated' ) + if customer1.updated_at > 2.seconds.ago + assert(true, 'customer1.updated_at has been updated') else - assert( false, 'customer1.updated_at has not been updated' ) + assert(false, 'customer1.updated_at has not been updated') end organization1 = Organization.find(organization1.id) - if organization1.updated_at > 4.seconds.ago - assert( true, 'organization1.updated_at has been updated' ) + if organization1.updated_at > 2.seconds.ago + assert(true, 'organization1.updated_at has been updated') else - assert( false, 'organization1.updated_at has not been updated' ) + assert(false, 'organization1.updated_at has not been updated') end delete = ticket.destroy - assert( delete, 'ticket destroy' ) + assert(delete, 'ticket destroy') end end diff --git a/test/unit/recent_view_test.rb b/test/unit/recent_view_test.rb index 6ed3e2500..fe3b5345a 100644 --- a/test/unit/recent_view_test.rb +++ b/test/unit/recent_view_test.rb @@ -14,46 +14,46 @@ class RecentViewTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - assert( ticket1, 'ticket created' ) + assert(ticket1, 'ticket created') ticket2 = Ticket.create( title: 'RecentViewTest 2 some title äöüß', - group: Group.lookup( name: 'Users'), + group: Group.lookup(name: 'Users'), customer_id: 2, - state: Ticket::State.lookup( name: 'new' ), - priority: Ticket::Priority.lookup( name: '2 normal' ), + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) - assert( ticket2, 'ticket created' ) + assert(ticket2, 'ticket created') user1 = User.find(2) RecentView.user_log_destroy(user1) - RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) + RecentView.log(ticket1.class.to_s, ticket1.id, user1) sleep 1 - RecentView.log( ticket2.class.to_s, ticket2.id, user1 ) + RecentView.log(ticket2.class.to_s, ticket2.id, user1) sleep 1 - RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) + RecentView.log(ticket1.class.to_s, ticket1.id, user1) sleep 1 - RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) + RecentView.log(ticket1.class.to_s, ticket1.id, user1) - list = RecentView.list( user1 ) - assert( list[0]['o_id'], ticket1.id ) - assert( list[0]['object'], 'Ticket' ) + list = RecentView.list(user1) + assert(list[0]['o_id'], ticket1.id) + assert(list[0]['object'], 'Ticket') - assert( list[1]['o_id'], ticket1.id ) - assert( list[1]['object'], 'Ticket' ) + assert(list[1]['o_id'], ticket1.id) + assert(list[1]['object'], 'Ticket') - assert( list[2]['o_id'], ticket2.id ) - assert( list[2]['object'], 'Ticket' ) + assert(list[2]['o_id'], ticket2.id) + assert(list[2]['object'], 'Ticket') - assert( list[3]['o_id'], ticket1.id ) - assert( list[3]['object'], 'Ticket' ) + assert(list[3]['o_id'], ticket1.id) + assert(list[3]['object'], 'Ticket') ticket1.destroy ticket2.destroy - list = RecentView.list( user1 ) - assert( !list[0], 'check if recent view list is empty' ) + list = RecentView.list(user1) + assert(!list[0], 'check if recent view list is empty') end test 'existing tests' do @@ -61,34 +61,34 @@ class RecentViewTest < ActiveSupport::TestCase # log entry of not existing object RecentView.user_log_destroy(user) - RecentView.log( 'ObjectNotExisting', 1, user ) + RecentView.log('ObjectNotExisting', 1, user) # check if list is empty - list = RecentView.list( user ) - assert( !list[0], 'check if recent view list is empty' ) + list = RecentView.list(user) + assert(!list[0], 'check if recent view list is empty') # log entry of not existing record RecentView.user_log_destroy(user) - RecentView.log( 'User', 99_999_999, user ) + RecentView.log('User', 99_999_999, user) # check if list is empty - list = RecentView.list( user ) - assert( !list[0], 'check if recent view list is empty' ) + list = RecentView.list(user) + assert(!list[0], 'check if recent view list is empty') # log entry of not existing model with permission check RecentView.user_log_destroy(user) - RecentView.log( 'Overview', 99_999_999, user ) + RecentView.log('Overview', 99_999_999, user) # check if list is empty - list = RecentView.list( user ) - assert( !list[0], 'check if recent view list is empty' ) + list = RecentView.list(user) + assert(!list[0], 'check if recent view list is empty') end test 'permission tests' do customer = User.find(2) - groups = Group.where( name: 'Users' ) - roles = Role.where( name: 'Agent' ) + groups = Group.where(name: 'Users') + roles = Role.where(name: 'Agent') agent = User.create_or_update( login: 'recent-viewed-agent@example.com', firstname: 'RecentViewed', @@ -111,72 +111,72 @@ class RecentViewTest < ActiveSupport::TestCase # no access for customer ticket1 = Ticket.create( title: 'RecentViewTest 1 some title äöüß', - group: Group.lookup( name: 'WithoutAccess'), + group: Group.lookup(name: 'WithoutAccess'), customer_id: 1, - state: Ticket::State.lookup( name: 'new' ), - priority: Ticket::Priority.lookup( name: '2 normal' ), + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) - assert( ticket1, 'ticket created' ) + assert(ticket1, 'ticket created') # log entry of not existing object RecentView.user_log_destroy(customer) - RecentView.log( ticket1.class.to_s, ticket1.id, customer ) + RecentView.log(ticket1.class.to_s, ticket1.id, customer) # check if list is empty - list = RecentView.list( customer ) - assert( !list[0], 'check if recent view list is empty' ) + list = RecentView.list(customer) + assert(!list[0], 'check if recent view list is empty') # log entry of not existing object RecentView.user_log_destroy(agent) - RecentView.log( ticket1.class.to_s, ticket1.id, agent ) + RecentView.log(ticket1.class.to_s, ticket1.id, agent) # check if list is empty - list = RecentView.list( agent ) - assert( !list[0], 'check if recent view list is empty' ) + list = RecentView.list(agent) + assert(!list[0], 'check if recent view list is empty') # access for customer via customer id ticket1 = Ticket.create( title: 'RecentViewTest 1 some title äöüß', - group: Group.lookup( name: 'WithoutAccess'), + group: Group.lookup(name: 'WithoutAccess'), customer_id: 2, - state: Ticket::State.lookup( name: 'new' ), - priority: Ticket::Priority.lookup( name: '2 normal' ), + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) - assert( ticket1, 'ticket created' ) + assert(ticket1, 'ticket created') # log entry RecentView.user_log_destroy(customer) - RecentView.log( ticket1.class.to_s, ticket1.id, customer ) + RecentView.log(ticket1.class.to_s, ticket1.id, customer) # check if list is empty - list = RecentView.list( customer ) - assert( list[0]['o_id'], ticket1.id ) - assert( list[0]['object'], 'Ticket' ) - assert( !list[1], 'check if recent view list is empty' ) + list = RecentView.list(customer) + assert(list[0]['o_id'], ticket1.id) + assert(list[0]['object'], 'Ticket') + assert(!list[1], 'check if recent view list is empty') # log entry organization = Organization.find(1) RecentView.user_log_destroy(customer) - RecentView.log( organization.class.to_s, organization.id, customer ) + RecentView.log(organization.class.to_s, organization.id, customer) # check if list is empty - list = RecentView.list( customer ) - assert( !list[0], 'check if recent view list is empty' ) + list = RecentView.list(customer) + assert(!list[0], 'check if recent view list is empty') # log entry organization = Organization.find(1) RecentView.user_log_destroy(agent) - RecentView.log( organization.class.to_s, organization.id, agent ) + RecentView.log(organization.class.to_s, organization.id, agent) # check if list is empty - list = RecentView.list( agent ) - assert( list[0]['o_id'], organization.id ) - assert( list[0]['object'], 'Organization' ) - assert( !list[1], 'check if recent view list is empty' ) + list = RecentView.list(agent) + assert(list[0]['o_id'], organization.id) + assert(list[0]['object'], 'Organization') + assert(!list[1], 'check if recent view list is empty') end end