From 1a8a9047b7c899fa638c20b32e37d4157c7a4438 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 14 Jul 2014 01:29:29 +0200 Subject: [PATCH] Fixed unit tests. --- app/models/ticket/overviews.rb | 2 ++ lib/sessions.rb | 3 ++- lib/sessions/client.rb | 8 ++++++ test/unit/session_enhanced_test.rb | 41 ++++++++++++++++++++++++++---- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/app/models/ticket/overviews.rb b/app/models/ticket/overviews.rb index ebe538e1c..94a79cd50 100644 --- a/app/models/ticket/overviews.rb +++ b/app/models/ticket/overviews.rb @@ -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 diff --git a/lib/sessions.rb b/lib/sessions.rb index 80a422ed5..64cdc5739 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -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 diff --git a/lib/sessions/client.rb b/lib/sessions/client.rb index 985defea0..7d226fdab 100644 --- a/lib/sessions/client.rb +++ b/lib/sessions/client.rb @@ -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) diff --git a/test/unit/session_enhanced_test.rb b/test/unit/session_enhanced_test.rb index 431696e31..50297ecf1 100644 --- a/test/unit/session_enhanced_test.rb +++ b/test/unit/session_enhanced_test.rb @@ -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