Fixed unit tests.

This commit is contained in:
Martin Edenhofer 2014-07-14 01:29:29 +02:00
parent 335f6fa42b
commit 1a8a9047b7
4 changed files with 48 additions and 6 deletions

View file

@ -31,6 +31,7 @@ returns
# get agent overviews
role = data[:current_user].is_role( 'Agent' )
return if !role
Overview.where( :role_id => role.id, :active => true )
end
@ -56,6 +57,7 @@ returns
def self.list (data)
overviews = self.all(data)
return if !overviews
# build up attributes hash
overview_selected = nil

View file

@ -465,6 +465,7 @@ returns
@@client_threads[client_id] = nil
puts "close client (#{client_id}) thread"
}
sleep 0.5
end
}
@ -506,7 +507,7 @@ returns
begin
Sessions::Client.new(client_id)
rescue => e
puts "thread_client exited with error #{ e.inspect }"
puts "thread_client #{client_id} exited with error #{ e.inspect }"
puts e.backtrace.join("\n ")
sleep 10
begin

View file

@ -34,6 +34,14 @@ class Sessions::Client
# init new backends
if user_id_last_run != user.id
user_id_last_run = user.id
# release old objects
backend_pool.each {|pool|
pool = nil
}
# create new pool
backend_pool = []
backends.each {|backend|
item = backend.constantize.new(user, self, @client_id)

View file

@ -19,6 +19,8 @@ class SessionEnhancedTest < ActiveSupport::TestCase
:roles => roles,
:groups => groups,
)
agent1.roles = roles
agent1.save
agent2 = User.create_or_update(
:login => 'session-agent-2',
:firstname => 'Session',
@ -29,6 +31,8 @@ class SessionEnhancedTest < ActiveSupport::TestCase
:roles => roles,
:groups => groups,
)
agent2.roles = roles
agent2.save
agent3 = User.create_or_update(
:login => 'session-agent-3',
:firstname => 'Session',
@ -39,6 +43,8 @@ class SessionEnhancedTest < ActiveSupport::TestCase
:roles => roles,
:groups => groups,
)
agent3.roles = roles
agent3.save
# create sessions
client_id1 = '1234'
@ -174,6 +180,8 @@ class SessionEnhancedTest < ActiveSupport::TestCase
:roles => roles,
:groups => groups,
)
agent1.roles = roles
agent1.save
agent2 = User.create_or_update(
:login => 'session-agent-2',
:firstname => 'Session',
@ -184,6 +192,9 @@ class SessionEnhancedTest < ActiveSupport::TestCase
:roles => roles,
:groups => groups,
)
agent2.roles = roles
agent2.save
org = Organization.create( :name => 'SomeOrg::' + rand(999999).to_s, :active => true )
# create sessions
client_id1_0 = '1234-1'
@ -220,6 +231,26 @@ class SessionEnhancedTest < ActiveSupport::TestCase
check_if_collection_reset_message_exists(client_id1_1, collections, 'init')
check_if_collection_reset_message_exists(client_id2, collections, 'init')
collections = {
'Group' => nil,
'Organization' => nil,
'User' => nil,
}
check_if_collection_reset_message_exists(client_id1_0, collections, 'init2')
check_if_collection_reset_message_exists(client_id1_1, collections, 'init2')
check_if_collection_reset_message_exists(client_id2, collections, 'init2')
sleep 20
collections = {
'Group' => nil,
'Organization' => nil,
'User' => nil,
}
check_if_collection_reset_message_exists(client_id1_0, collections, 'init3')
check_if_collection_reset_message_exists(client_id1_1, collections, 'init3')
check_if_collection_reset_message_exists(client_id2, collections, 'init3')
# change collection
group = Group.first
group.touch
@ -249,25 +280,25 @@ class SessionEnhancedTest < ActiveSupport::TestCase
def check_if_collection_reset_message_exists(client_id, collections_orig, type)
messages = Sessions.queue(client_id)
puts "cid: #{client_id}"
#puts "cid: #{client_id}"
#puts "m: #{messages.inspect}"
collections_result = {}
messages.each {|message|
#puts ""
#puts "message: #{message.inspect}"
if message['event'] == 'resetCollection'
puts "rc: "
#puts "rc: "
if message['data']
message['data'].each {|key, value|
puts "rc: #{key}"
#puts "rc: #{key}"
collections_result[key] = true
}
end
end
}
puts "c: #{collections_result.inspect}"
#puts "c: #{collections_result.inspect}"
collections_orig.each {|key, value|
assert_equal( collections_orig[key], collections_result[key], "collection message for #{key} #{type}-check" )
assert_equal( collections_orig[key], collections_result[key], "collection message for #{key} #{type}-check (client_id #{client_id})" )
}
end
end