diff --git a/lib/sessions.rb b/lib/sessions.rb index c8d0c6e31..b5704ee82 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -448,11 +448,21 @@ returns end end +=begin + +remove all session and spool messages + + Sessions.cleanup + +=end + def self.cleanup - path = "#{@path}/spool/" - FileUtils.rm_rf path - path = "#{@path}/tmp/" - FileUtils.rm_rf path + Dir.foreach(@path) do |entry| + next if entry == '.' + next if entry == '..' + FileUtils.rm_rf entry + end + true end def self.spool_create(data) diff --git a/test/test_helper.rb b/test/test_helper.rb index 4b151afbe..a003338b7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -42,6 +42,9 @@ class ActiveSupport::TestCase # clear cache Cache.clear + # remove all session messages + Sessions.cleanup + # remove background jobs Delayed::Job.destroy_all Trigger.destroy_all diff --git a/test/unit/session_basic_ticket_test.rb b/test/unit/session_basic_ticket_test.rb index 664a90fdd..072c9e1a4 100644 --- a/test/unit/session_basic_ticket_test.rb +++ b/test/unit/session_basic_ticket_test.rb @@ -70,8 +70,11 @@ class SessionBasicTicketTest < ActiveSupport::TestCase Sessions::Backend::TicketOverviewList.reset(user.id) result1 = client1.push assert(result1, 'check ticket_overview_index - recall 7') - travel_back + travel 10.seconds + Sessions.destroy_idle_sessions(3) + + travel_back end end diff --git a/test/unit/session_collections_test.rb b/test/unit/session_collections_test.rb index 397fec68c..c5dc200c2 100644 --- a/test/unit/session_collections_test.rb +++ b/test/unit/session_collections_test.rb @@ -130,6 +130,10 @@ class SessionCollectionsTest < ActiveSupport::TestCase assert(result2.empty?, 'check collections - recall') result3 = collection_client3.push assert(result3.empty?, 'check collections - recall') + + travel 10.seconds + Sessions.destroy_idle_sessions(3) + travel_back end @@ -175,9 +179,9 @@ class SessionCollectionsTest < ActiveSupport::TestCase UserInfo.current_user_id = 2 agent1 = User.create_or_update( - login: 'sessions-assets-1', + login: "sessions-assets-1-#{rand(99_999)}", firstname: 'Session', - lastname: "activity stream #{rand(99_999)}", + lastname: "sessions assets #{rand(99_999)}", email: 'sessions-assets1@example.com', password: 'agentpw', active: true, @@ -204,6 +208,9 @@ class SessionCollectionsTest < ActiveSupport::TestCase assert(data[:collection][:Group][groups.first.id]) assert_nil(data[:assets][:Group]) + travel 10.seconds + Sessions.destroy_idle_sessions(3) + travel_back end diff --git a/test/unit/session_enhanced_test.rb b/test/unit/session_enhanced_test.rb index 073b8382e..f191b5f40 100644 --- a/test/unit/session_enhanced_test.rb +++ b/test/unit/session_enhanced_test.rb @@ -155,7 +155,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase # check if session still exists after idle cleanup sleep 4 - client_ids = Sessions.destroy_idle_sessions(3) + client_ids = Sessions.destroy_idle_sessions(2) # check client sessions assert(!Sessions.session_exists?(client_id1), 'check if session is removed')