Improved speed of tests by own ttl method parameter.
This commit is contained in:
parent
b625a6563a
commit
5d2db33534
11 changed files with 76 additions and 73 deletions
|
@ -1,10 +1,11 @@
|
|||
class Sessions::Backend::ActivityStream
|
||||
|
||||
def initialize( user, client = nil, client_id = nil )
|
||||
@user = user
|
||||
@client = client
|
||||
@client_id = client_id
|
||||
@last_change = nil
|
||||
def initialize( user, client = nil, client_id = nil, ttl = 30 )
|
||||
@user = user
|
||||
@client = client
|
||||
@client_id = client_id
|
||||
@ttl = ttl
|
||||
@last_change = nil
|
||||
end
|
||||
|
||||
def load
|
||||
|
@ -38,7 +39,7 @@ class Sessions::Backend::ActivityStream
|
|||
return if timeout
|
||||
|
||||
# set new timeout
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => 0.5.minutes } )
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => @ttl.seconds } )
|
||||
|
||||
data = self.load
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
class Sessions::Backend::Collections
|
||||
|
||||
def initialize( user, client, client_id )
|
||||
def initialize( user, client, client_id, ttl = 10 )
|
||||
@user = user
|
||||
@client = client
|
||||
@client_id = client_id
|
||||
@ttl = ttl
|
||||
@backends = self.backend
|
||||
end
|
||||
|
||||
|
@ -35,7 +36,7 @@ class Sessions::Backend::Collections
|
|||
next if file.classify == 'Sessions::Backend::Collections::Base'
|
||||
#puts "LOAD #{file.classify}---"
|
||||
#next if file == ''
|
||||
backend = file.classify.constantize.new(@user, @client, @client_id)
|
||||
backend = file.classify.constantize.new(@user, @client, @client_id, @ttl)
|
||||
if backend
|
||||
backends.push backend
|
||||
end
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
class Sessions::Backend::Collections::Base
|
||||
class << self; attr_accessor :model, :is_role, :is_not_role end
|
||||
|
||||
def initialize( user, client = nil, client_id = nil )
|
||||
def initialize( user, client = nil, client_id = nil, ttl )
|
||||
@user = user
|
||||
@client = client
|
||||
@client_id = client_id
|
||||
@ttl = ttl
|
||||
@last_change = nil
|
||||
end
|
||||
|
||||
|
@ -41,7 +42,7 @@ class Sessions::Backend::Collections::Base
|
|||
return if timeout
|
||||
|
||||
# set new timeout
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => 10.seconds } )
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => @ttl.seconds } )
|
||||
|
||||
# check if update has been done
|
||||
last_change = self.class.model.constantize.latest_change
|
||||
|
|
|
@ -2,10 +2,11 @@ require 'rss'
|
|||
|
||||
class Sessions::Backend::Rss
|
||||
|
||||
def initialize( user, client, client_id )
|
||||
@user = user
|
||||
@client = client
|
||||
@client_id = client_id
|
||||
def initialize( user, client, client_id, ttl = 30 )
|
||||
@user = user
|
||||
@client = client
|
||||
@ttl = ttl
|
||||
@client_id = client_id
|
||||
end
|
||||
|
||||
def collection_key
|
||||
|
@ -38,7 +39,7 @@ class Sessions::Backend::Rss
|
|||
return if timeout
|
||||
|
||||
# set new timeout
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => 5.minutes } )
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => @ttl.seconds } )
|
||||
|
||||
data = self.load
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
class Sessions::Backend::TicketCreate
|
||||
def initialize( user, client = nil, client_id = nil )
|
||||
def initialize( user, client = nil, client_id = nil, ttl = 30 )
|
||||
@user = user
|
||||
@client = client
|
||||
@client_id = client_id
|
||||
@ttl = ttl
|
||||
@last_change = nil
|
||||
end
|
||||
|
||||
|
@ -36,7 +37,7 @@ class Sessions::Backend::TicketCreate
|
|||
return if timeout
|
||||
|
||||
# set new timeout
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => 30.seconds } )
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => @ttl.seconds } )
|
||||
|
||||
ticket_create_attributes = self.load
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
class Sessions::Backend::TicketOverviewIndex
|
||||
def initialize( user, client = nil, client_id = nil )
|
||||
def initialize( user, client = nil, client_id = nil, ttl = 5 )
|
||||
@user = user
|
||||
@client = client
|
||||
@client_id = client_id
|
||||
@ttl = ttl
|
||||
@last_change = nil
|
||||
@last_ticket_change = nil
|
||||
end
|
||||
|
@ -36,7 +37,7 @@ class Sessions::Backend::TicketOverviewIndex
|
|||
return if Sessions::CacheIn.get( self.client_key )
|
||||
|
||||
# reset check interval
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => 5.seconds } )
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => @ttl.seconds } )
|
||||
|
||||
# check if min one ticket has changed
|
||||
last_ticket_change = Ticket.latest_change
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
class Sessions::Backend::TicketOverviewList
|
||||
def initialize( user, client = nil, client_id = nil )
|
||||
def initialize( user, client = nil, client_id = nil, ttl = 6 )
|
||||
@user = user
|
||||
@client = client
|
||||
@client_id = client_id
|
||||
@ttl = ttl
|
||||
@last_change = nil
|
||||
@last_ticket_change = nil
|
||||
end
|
||||
|
@ -46,7 +47,7 @@ class Sessions::Backend::TicketOverviewList
|
|||
return if Sessions::CacheIn.get( self.client_key )
|
||||
|
||||
# reset check interval
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => 6.seconds } )
|
||||
Sessions::CacheIn.set( self.client_key, true, { :expires_in => @ttl.seconds } )
|
||||
|
||||
# check if min one ticket has changed
|
||||
last_ticket_change = Ticket.latest_change
|
||||
|
|
|
@ -50,8 +50,8 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
|
||||
UserInfo.current_user_id = 2
|
||||
user = User.lookup(:id => 1)
|
||||
collection_client1 = Sessions::Backend::Collections::Group.new(user, false, '123-1')
|
||||
collection_client2 = Sessions::Backend::Collections::Group.new(user, false, '234-2')
|
||||
collection_client1 = Sessions::Backend::Collections::Group.new(user, false, '123-1', 5)
|
||||
collection_client2 = Sessions::Backend::Collections::Group.new(user, false, '234-2', 5)
|
||||
|
||||
# get whole collections
|
||||
result1 = collection_client1.push
|
||||
|
@ -71,7 +71,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
# change collection
|
||||
group = Group.first
|
||||
group.touch
|
||||
sleep 12
|
||||
sleep 6
|
||||
|
||||
# get whole collections
|
||||
result1 = collection_client1.push
|
||||
|
@ -91,7 +91,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
|
||||
# change collection
|
||||
group = Group.create( :name => 'SomeGroup::' + rand(999999).to_s, :active => true )
|
||||
sleep 12
|
||||
sleep 6
|
||||
|
||||
# get whole collections
|
||||
result1 = collection_client1.push
|
||||
|
@ -102,7 +102,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
assert_equal( result1, result2, "check collections" )
|
||||
|
||||
# check again after create
|
||||
sleep 12
|
||||
sleep 6
|
||||
result1 = collection_client1.push
|
||||
assert( !result1, "check collections - after create - recall" )
|
||||
sleep 1
|
||||
|
@ -112,7 +112,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
|
||||
# change collection
|
||||
group.destroy
|
||||
sleep 12
|
||||
sleep 6
|
||||
|
||||
# get whole collections
|
||||
result1 = collection_client1.push
|
||||
|
@ -123,7 +123,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
assert_equal( result1, result2, "check collections" )
|
||||
|
||||
# check again after destroy
|
||||
sleep 12
|
||||
sleep 6
|
||||
result1 = collection_client1.push
|
||||
assert( !result1, "check collections - after destroy - recall" )
|
||||
sleep 1
|
||||
|
@ -143,8 +143,8 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
user = User.lookup(:id => 1)
|
||||
org = Organization.create( :name => 'SomeOrg1::' + rand(999999).to_s, :active => true )
|
||||
|
||||
collection_client1 = Sessions::Backend::Collections::Organization.new(user, false, '123-1')
|
||||
collection_client2 = Sessions::Backend::Collections::Organization.new(user, false, '234-2')
|
||||
collection_client1 = Sessions::Backend::Collections::Organization.new(user, false, '123-1', 5)
|
||||
collection_client2 = Sessions::Backend::Collections::Organization.new(user, false, '234-2', 5)
|
||||
|
||||
# get whole collections - should be nil, no org exists!
|
||||
result1 = collection_client1.push
|
||||
|
@ -163,7 +163,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
|
||||
# change collection
|
||||
org = Organization.create( :name => 'SomeOrg2::' + rand(999999).to_s, :active => true )
|
||||
sleep 12
|
||||
sleep 6
|
||||
|
||||
# get whole collections
|
||||
result1 = collection_client1.push
|
||||
|
@ -173,7 +173,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
assert( !result2.empty?, "check collections - after create" )
|
||||
assert_equal( result1, result2, "check collections" )
|
||||
|
||||
sleep 12
|
||||
sleep 6
|
||||
|
||||
# next check should be empty
|
||||
result1 = collection_client1.push
|
||||
|
@ -217,19 +217,19 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
|
||||
UserInfo.current_user_id = 2
|
||||
agent1 = User.create_or_update(
|
||||
:login => 'activity-stream-agent-1',
|
||||
:firstname => 'Session',
|
||||
:lastname => 'activity stream ' + rand(99999).to_s,
|
||||
:email => 'activity-stream-agent1@example.com',
|
||||
:password => 'agentpw',
|
||||
:active => true,
|
||||
:roles => roles,
|
||||
:groups => groups,
|
||||
:login => 'activity-stream-agent-1',
|
||||
:firstname => 'Session',
|
||||
:lastname => 'activity stream ' + rand(99999).to_s,
|
||||
:email => 'activity-stream-agent1@example.com',
|
||||
:password => 'agentpw',
|
||||
:active => true,
|
||||
:roles => roles,
|
||||
:groups => groups,
|
||||
)
|
||||
agent1.roles = roles
|
||||
assert( agent1.save, "create/update agent1" )
|
||||
|
||||
as_client1 = Sessions::Backend::ActivityStream.new(agent1, false, '123-1')
|
||||
as_client1 = Sessions::Backend::ActivityStream.new(agent1, false, '123-1', 5)
|
||||
|
||||
# get as stream
|
||||
result1 = as_client1.push
|
||||
|
@ -241,14 +241,14 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
assert( !result1, "check as agent1 - recall" )
|
||||
|
||||
# next check should be empty
|
||||
sleep 31
|
||||
sleep 6
|
||||
result1 = as_client1.push
|
||||
assert( !result1, "check as agent1 - recall 2" )
|
||||
|
||||
agent1.update_attribute( :email, 'activity-stream-agent11@example.com' )
|
||||
ticket = Ticket.create(:title => '12323', :group_id => 1, :priority_id => 1, :state_id => 1, :customer_id => 1 )
|
||||
|
||||
sleep 31
|
||||
sleep 6
|
||||
|
||||
# get as stream
|
||||
result1 = as_client1.push
|
||||
|
@ -259,7 +259,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
|
||||
UserInfo.current_user_id = 2
|
||||
user = User.lookup(:id => 1)
|
||||
ticket_create_client1 = Sessions::Backend::TicketCreate.new(user, false, '123-1')
|
||||
ticket_create_client1 = Sessions::Backend::TicketCreate.new(user, false, '123-1', 5)
|
||||
|
||||
# get as stream
|
||||
result1 = ticket_create_client1.push
|
||||
|
@ -277,7 +277,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
|
||||
Group.create( :name => 'SomeTicketCreateGroup::' + rand(999999).to_s, :active => true )
|
||||
|
||||
sleep 26
|
||||
sleep 6
|
||||
|
||||
# get as stream
|
||||
result1 = ticket_create_client1.push
|
||||
|
|
|
@ -11,14 +11,14 @@ class SessionBasicTicketTest < ActiveSupport::TestCase
|
|||
groups = Group.all
|
||||
|
||||
agent1 = User.create_or_update(
|
||||
:login => 'activity-stream-agent-1',
|
||||
:firstname => 'Session',
|
||||
:lastname => 'activity stream ' + rand(99999).to_s,
|
||||
:email => 'activity-stream-agent1@example.com',
|
||||
:password => 'agentpw',
|
||||
:active => true,
|
||||
:roles => roles,
|
||||
:groups => groups,
|
||||
:login => 'activity-stream-agent-1',
|
||||
:firstname => 'Session',
|
||||
:lastname => 'activity stream ' + rand(99999).to_s,
|
||||
:email => 'activity-stream-agent1@example.com',
|
||||
:password => 'agentpw',
|
||||
:active => true,
|
||||
:roles => roles,
|
||||
:groups => groups,
|
||||
)
|
||||
agent1.roles = roles
|
||||
assert( agent1.save, "create/update agent1" )
|
||||
|
@ -58,14 +58,14 @@ class SessionBasicTicketTest < ActiveSupport::TestCase
|
|||
groups = Group.all
|
||||
|
||||
agent1 = User.create_or_update(
|
||||
:login => 'activity-stream-agent-1',
|
||||
:firstname => 'Session',
|
||||
:lastname => 'activity stream ' + rand(99999).to_s,
|
||||
:email => 'activity-stream-agent1@example.com',
|
||||
:password => 'agentpw',
|
||||
:active => true,
|
||||
:roles => roles,
|
||||
:groups => groups,
|
||||
:login => 'activity-stream-agent-1',
|
||||
:firstname => 'Session',
|
||||
:lastname => 'activity stream ' + rand(99999).to_s,
|
||||
:email => 'activity-stream-agent1@example.com',
|
||||
:password => 'agentpw',
|
||||
:active => true,
|
||||
:roles => roles,
|
||||
:groups => groups,
|
||||
)
|
||||
agent1.roles = roles
|
||||
assert( agent1.save, "create/update agent1" )
|
||||
|
|
|
@ -86,14 +86,13 @@ class SessionCollectionsTest < ActiveSupport::TestCase
|
|||
sleep 1
|
||||
result2 = collection_client2.push
|
||||
assert( result2.empty?, "check collections - recall" )
|
||||
sleep 0.2
|
||||
result3 = collection_client3.push
|
||||
assert( result3.empty?, "check collections - recall" )
|
||||
|
||||
# change collection
|
||||
group = Group.first
|
||||
group.touch
|
||||
sleep 16
|
||||
sleep 11
|
||||
|
||||
# get whole collections
|
||||
result1 = collection_client1.push
|
||||
|
@ -103,14 +102,13 @@ class SessionCollectionsTest < ActiveSupport::TestCase
|
|||
result2 = collection_client2.push
|
||||
assert( result2, "check collections - after touch" )
|
||||
assert( check_if_collection_exists(result2, :Group), "check collections - after touch" )
|
||||
sleep 0.2
|
||||
result3 = collection_client3.push
|
||||
assert( result3, "check collections - after touch" )
|
||||
assert( check_if_collection_exists(result3, :Group), "check collections - after touch" )
|
||||
|
||||
# change collection
|
||||
org = Organization.create( :name => 'SomeOrg::' + rand(999999).to_s, :active => true, :member_ids => [customer1.id] )
|
||||
sleep 16
|
||||
sleep 11
|
||||
|
||||
# get whole collections
|
||||
result1 = collection_client1.push
|
||||
|
@ -120,19 +118,17 @@ class SessionCollectionsTest < ActiveSupport::TestCase
|
|||
result2 = collection_client2.push
|
||||
assert( result2, "check collections - after create" )
|
||||
assert( check_if_collection_exists(result2, :Organization), "check collections - after create" )
|
||||
sleep 0.5
|
||||
result3 = collection_client3.push
|
||||
assert( result3, "check collections - after create" )
|
||||
assert( !check_if_collection_exists(result3, :Organization), "check collections - after create" )
|
||||
assert( check_if_collection_exists(result3, :Organization), "check collections - after create" )
|
||||
|
||||
# next check should be empty
|
||||
sleep 16
|
||||
sleep 11
|
||||
result1 = collection_client1.push
|
||||
assert( result1.empty?, "check collections - recall" )
|
||||
sleep 1
|
||||
result2 = collection_client2.push
|
||||
assert( result2.empty?, "check collections - recall" )
|
||||
sleep 0.2
|
||||
result3 = collection_client3.push
|
||||
assert( result3.empty?, "check collections - recall" )
|
||||
end
|
||||
|
|
|
@ -230,7 +230,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
|||
assert( Sessions.session_exists?(client_id1_0), "check if session exists" )
|
||||
assert( Sessions.session_exists?(client_id1_1), "check if session exists" )
|
||||
assert( Sessions.session_exists?(client_id2), "check if session exists" )
|
||||
sleep 19
|
||||
sleep 11
|
||||
|
||||
# check collections
|
||||
collections = {
|
||||
|
@ -251,7 +251,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
|||
check_if_collection_reset_message_exists(client_id1_1, collections, 'init2')
|
||||
check_if_collection_reset_message_exists(client_id2, collections, 'init2')
|
||||
|
||||
sleep 20
|
||||
sleep 11
|
||||
|
||||
collections = {
|
||||
'Group' => nil,
|
||||
|
@ -266,7 +266,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
|||
group = Group.first
|
||||
group.touch
|
||||
|
||||
sleep 20
|
||||
sleep 11
|
||||
|
||||
# check collections
|
||||
collections = {
|
||||
|
|
Loading…
Reference in a new issue