Improved timings.

This commit is contained in:
Martin Edenhofer 2016-05-21 17:40:40 +02:00
parent 4c55ca4121
commit 22f9f59a9a
3 changed files with 86 additions and 86 deletions

View file

@ -81,10 +81,10 @@ class CacheTest < ActiveSupport::TestCase
key: 'some valueöäüß2', key: 'some valueöäüß2',
}, },
param: { param: {
expires_in: 5.seconds, expires_in: 3.seconds,
} }
}, },
sleep: 10, sleep: 5,
verify: { verify: {
key: '123', key: '123',
data: nil data: nil
@ -93,10 +93,10 @@ class CacheTest < ActiveSupport::TestCase
] ]
tests.each { |test| tests.each { |test|
if test[:set] if test[:set]
Cache.write( test[:set], test[:set][:data] ) Cache.write(test[:set], test[:set][:data])
end end
if test[:delete] if test[:delete]
Cache.delete( test[:delete][:key] ) Cache.delete(test[:delete][:key])
end end
if test[:cleanup] if test[:cleanup]
Cache.clear Cache.clear
@ -105,17 +105,17 @@ class CacheTest < ActiveSupport::TestCase
sleep test[:sleep] sleep test[:sleep]
end end
if test[:verify] if test[:verify]
cache = Cache.get( test[:verify] ) cache = Cache.get(test[:verify])
assert_equal( cache, test[:verify][:data], 'verify' ) assert_equal(cache, test[:verify][:data], 'verify')
end end
} }
end end
# verify if second cache write overwrite first one # verify if second cache write overwrite first one
test 'cache reset' do test 'cache reset' do
Cache.write( 'some_reset_key', 123 ) Cache.write('some_reset_key', 123)
Cache.write( 'some_reset_key', 12_356 ) Cache.write('some_reset_key', 12_356)
cache = Cache.get( 'some_reset_key' ) cache = Cache.get('some_reset_key')
assert_equal( cache, 12_356, 'verify' ) assert_equal(cache, 12_356, 'verify')
end end
end end

View file

@ -71,51 +71,51 @@ class OrganizationRefObjectTouchTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
assert( ticket, 'ticket created' ) assert(ticket, 'ticket created')
assert_equal( ticket.customer.id, customer1.id ) assert_equal(ticket.customer.id, customer1.id )
assert_equal( ticket.organization.id, organization1.id ) assert_equal(ticket.organization.id, organization1.id )
sleep 6 sleep 4
organization1.name = 'Ref Object Update Org 1/1' organization1.name = 'Ref Object Update Org 1/1'
organization1.save organization1.save
# check if ticket and customer has been touched # check if ticket and customer has been touched
ticket = Ticket.find(ticket.id) ticket = Ticket.find(ticket.id)
if ticket.updated_at > 4.seconds.ago if ticket.updated_at > 2.seconds.ago
assert( true, 'ticket.updated_at has been updated' ) assert(true, 'ticket.updated_at has been updated')
else else
assert( false, 'ticket.updated_at has not been updated' ) assert(false, 'ticket.updated_at has not been updated')
end end
customer1 = User.find(customer1.id) customer1 = User.find(customer1.id)
if customer1.updated_at > 4.seconds.ago if customer1.updated_at > 2.seconds.ago
assert( true, 'customer1.updated_at has been updated' ) assert(true, 'customer1.updated_at has been updated')
else else
assert( false, 'customer1.updated_at has not been updated' ) assert(false, 'customer1.updated_at has not been updated')
end end
sleep 6 sleep 4
customer2.organization_id = organization1.id customer2.organization_id = organization1.id
customer2.save customer2.save
# check if customer1 and organization has been touched # check if customer1 and organization has been touched
customer1 = User.find(customer1.id) customer1 = User.find(customer1.id)
if customer1.updated_at > 4.seconds.ago if customer1.updated_at > 2.seconds.ago
assert( true, 'customer1.updated_at has been updated' ) assert(true, 'customer1.updated_at has been updated')
else else
assert( false, 'customer1.updated_at has not been updated' ) assert(false, 'customer1.updated_at has not been updated')
end end
organization1 = Organization.find(organization1.id) organization1 = Organization.find(organization1.id)
if organization1.updated_at > 4.seconds.ago if organization1.updated_at > 2.seconds.ago
assert( true, 'organization1.updated_at has been updated' ) assert(true, 'organization1.updated_at has been updated')
else else
assert( false, 'organization1.updated_at has not been updated' ) assert(false, 'organization1.updated_at has not been updated')
end end
delete = ticket.destroy delete = ticket.destroy
assert( delete, 'ticket destroy' ) assert(delete, 'ticket destroy')
end end
end end

View file

@ -14,46 +14,46 @@ class RecentViewTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
assert( ticket1, 'ticket created' ) assert(ticket1, 'ticket created')
ticket2 = Ticket.create( ticket2 = Ticket.create(
title: 'RecentViewTest 2 some title äöüß', title: 'RecentViewTest 2 some title äöüß',
group: Group.lookup( name: 'Users'), group: Group.lookup(name: 'Users'),
customer_id: 2, customer_id: 2,
state: Ticket::State.lookup( name: 'new' ), state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup( name: '2 normal' ), priority: Ticket::Priority.lookup(name: '2 normal'),
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
assert( ticket2, 'ticket created' ) assert(ticket2, 'ticket created')
user1 = User.find(2) user1 = User.find(2)
RecentView.user_log_destroy(user1) 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 sleep 1
RecentView.log( ticket2.class.to_s, ticket2.id, user1 ) RecentView.log(ticket2.class.to_s, ticket2.id, user1)
sleep 1 sleep 1
RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) RecentView.log(ticket1.class.to_s, ticket1.id, user1)
sleep 1 sleep 1
RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) RecentView.log(ticket1.class.to_s, ticket1.id, user1)
list = RecentView.list( user1 ) list = RecentView.list(user1)
assert( list[0]['o_id'], ticket1.id ) assert(list[0]['o_id'], ticket1.id)
assert( list[0]['object'], 'Ticket' ) assert(list[0]['object'], 'Ticket')
assert( list[1]['o_id'], ticket1.id ) assert(list[1]['o_id'], ticket1.id)
assert( list[1]['object'], 'Ticket' ) assert(list[1]['object'], 'Ticket')
assert( list[2]['o_id'], ticket2.id ) assert(list[2]['o_id'], ticket2.id)
assert( list[2]['object'], 'Ticket' ) assert(list[2]['object'], 'Ticket')
assert( list[3]['o_id'], ticket1.id ) assert(list[3]['o_id'], ticket1.id)
assert( list[3]['object'], 'Ticket' ) assert(list[3]['object'], 'Ticket')
ticket1.destroy ticket1.destroy
ticket2.destroy ticket2.destroy
list = RecentView.list( user1 ) list = RecentView.list(user1)
assert( !list[0], 'check if recent view list is empty' ) assert(!list[0], 'check if recent view list is empty')
end end
test 'existing tests' do test 'existing tests' do
@ -61,34 +61,34 @@ class RecentViewTest < ActiveSupport::TestCase
# log entry of not existing object # log entry of not existing object
RecentView.user_log_destroy(user) RecentView.user_log_destroy(user)
RecentView.log( 'ObjectNotExisting', 1, user ) RecentView.log('ObjectNotExisting', 1, user)
# check if list is empty # check if list is empty
list = RecentView.list( user ) list = RecentView.list(user)
assert( !list[0], 'check if recent view list is empty' ) assert(!list[0], 'check if recent view list is empty')
# log entry of not existing record # log entry of not existing record
RecentView.user_log_destroy(user) RecentView.user_log_destroy(user)
RecentView.log( 'User', 99_999_999, user ) RecentView.log('User', 99_999_999, user)
# check if list is empty # check if list is empty
list = RecentView.list( user ) list = RecentView.list(user)
assert( !list[0], 'check if recent view list is empty' ) assert(!list[0], 'check if recent view list is empty')
# log entry of not existing model with permission check # log entry of not existing model with permission check
RecentView.user_log_destroy(user) RecentView.user_log_destroy(user)
RecentView.log( 'Overview', 99_999_999, user ) RecentView.log('Overview', 99_999_999, user)
# check if list is empty # check if list is empty
list = RecentView.list( user ) list = RecentView.list(user)
assert( !list[0], 'check if recent view list is empty' ) assert(!list[0], 'check if recent view list is empty')
end end
test 'permission tests' do test 'permission tests' do
customer = User.find(2) customer = User.find(2)
groups = Group.where( name: 'Users' ) groups = Group.where(name: 'Users')
roles = Role.where( name: 'Agent' ) roles = Role.where(name: 'Agent')
agent = User.create_or_update( agent = User.create_or_update(
login: 'recent-viewed-agent@example.com', login: 'recent-viewed-agent@example.com',
firstname: 'RecentViewed', firstname: 'RecentViewed',
@ -111,72 +111,72 @@ class RecentViewTest < ActiveSupport::TestCase
# no access for customer # no access for customer
ticket1 = Ticket.create( ticket1 = Ticket.create(
title: 'RecentViewTest 1 some title äöüß', title: 'RecentViewTest 1 some title äöüß',
group: Group.lookup( name: 'WithoutAccess'), group: Group.lookup(name: 'WithoutAccess'),
customer_id: 1, customer_id: 1,
state: Ticket::State.lookup( name: 'new' ), state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup( name: '2 normal' ), priority: Ticket::Priority.lookup(name: '2 normal'),
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
assert( ticket1, 'ticket created' ) assert(ticket1, 'ticket created')
# log entry of not existing object # log entry of not existing object
RecentView.user_log_destroy(customer) 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 # check if list is empty
list = RecentView.list( customer ) list = RecentView.list(customer)
assert( !list[0], 'check if recent view list is empty' ) assert(!list[0], 'check if recent view list is empty')
# log entry of not existing object # log entry of not existing object
RecentView.user_log_destroy(agent) 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 # check if list is empty
list = RecentView.list( agent ) list = RecentView.list(agent)
assert( !list[0], 'check if recent view list is empty' ) assert(!list[0], 'check if recent view list is empty')
# access for customer via customer id # access for customer via customer id
ticket1 = Ticket.create( ticket1 = Ticket.create(
title: 'RecentViewTest 1 some title äöüß', title: 'RecentViewTest 1 some title äöüß',
group: Group.lookup( name: 'WithoutAccess'), group: Group.lookup(name: 'WithoutAccess'),
customer_id: 2, customer_id: 2,
state: Ticket::State.lookup( name: 'new' ), state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup( name: '2 normal' ), priority: Ticket::Priority.lookup(name: '2 normal'),
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
assert( ticket1, 'ticket created' ) assert(ticket1, 'ticket created')
# log entry # log entry
RecentView.user_log_destroy(customer) 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 # check if list is empty
list = RecentView.list( customer ) list = RecentView.list(customer)
assert( list[0]['o_id'], ticket1.id ) assert(list[0]['o_id'], ticket1.id)
assert( list[0]['object'], 'Ticket' ) assert(list[0]['object'], 'Ticket')
assert( !list[1], 'check if recent view list is empty' ) assert(!list[1], 'check if recent view list is empty')
# log entry # log entry
organization = Organization.find(1) organization = Organization.find(1)
RecentView.user_log_destroy(customer) 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 # check if list is empty
list = RecentView.list( customer ) list = RecentView.list(customer)
assert( !list[0], 'check if recent view list is empty' ) assert(!list[0], 'check if recent view list is empty')
# log entry # log entry
organization = Organization.find(1) organization = Organization.find(1)
RecentView.user_log_destroy(agent) 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 # check if list is empty
list = RecentView.list( agent ) list = RecentView.list(agent)
assert( list[0]['o_id'], organization.id ) assert(list[0]['o_id'], organization.id)
assert( list[0]['object'], 'Organization' ) assert(list[0]['object'], 'Organization')
assert( !list[1], 'check if recent view list is empty' ) assert(!list[1], 'check if recent view list is empty')
end end
end end