From d81a3722e4a0481f6271686e851bb9cb939dcd9f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 25 Feb 2015 23:17:34 +0100 Subject: [PATCH] Improved speed of test by switching from min to sec for idle param. --- lib/sessions.rb | 4 ++-- script/websocket-server.rb | 6 +++--- test/unit/session_enhanced_test.rb | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/sessions.rb b/lib/sessions.rb index 64bc64c37..4950aebcc 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -165,11 +165,11 @@ returns =end - def self.destory_idle_sessions(idle_time_in_min = 4) + def self.destory_idle_sessions(idle_time_in_sec = 240) list_of_closed_sessions = [] clients = Sessions.list clients.each { |client_id, client| - if !client[:meta] || !client[:meta][:last_ping] || ( client[:meta][:last_ping].to_i + ( 60 * idle_time_in_min ) ) < Time.now.to_i + if !client[:meta] || !client[:meta][:last_ping] || ( client[:meta][:last_ping].to_i + idle_time_in_sec ) < Time.now.to_i list_of_closed_sessions.push client_id Sessions.destory( client_id ) end diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 749261950..a81a07266 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -293,11 +293,11 @@ EventMachine.run { def check_unused_connections log 'notice', "check unused idle connections..." - idle_time_in_min = 4 + idle_time_in_sec = 4 * 60 # close unused web socket sessions @clients.each { |client_id, client| - if ( client[:last_ping] + ( 60 * idle_time_in_min ) ) < Time.now + if ( client[:last_ping] + idle_time_in_sec ) < Time.now log 'notice', "closing idle websocket connection", client_id # remember to not use this connection anymore @@ -313,7 +313,7 @@ EventMachine.run { } # close unused ajax long polling sessions - clients = Sessions.destory_idle_sessions(idle_time_in_min) + clients = Sessions.destory_idle_sessions(idle_time_in_sec) clients.each { |client_id| log 'notice', "closing idle long polling connection", client_id } diff --git a/test/unit/session_enhanced_test.rb b/test/unit/session_enhanced_test.rb index 43f9389f3..4aa0f37d5 100644 --- a/test/unit/session_enhanced_test.rb +++ b/test/unit/session_enhanced_test.rb @@ -64,17 +64,17 @@ class SessionEnhancedTest < ActiveSupport::TestCase # check if session still exists after idle cleanup sleep 1 - Sessions.destory_idle_sessions(1) + Sessions.destory_idle_sessions(5) assert( Sessions.session_exists?(client_id1), "check if session exists after 1 sec" ) assert( Sessions.session_exists?(client_id2), "check if session exists after 1 sec" ) assert( Sessions.session_exists?(client_id3), "check if session exists after 1 sec" ) # check if session still exists after idle cleanup with touched sessions - sleep 62 + sleep 6 Sessions.touch(client_id1) Sessions.touch(client_id2) Sessions.touch(client_id3) - Sessions.destory_idle_sessions(1) + Sessions.destory_idle_sessions(5) assert( Sessions.session_exists?(client_id1), "check if session exists after touch" ) assert( Sessions.session_exists?(client_id2), "check if session exists after touch" ) assert( Sessions.session_exists?(client_id3), "check if session exists after touch" ) @@ -155,15 +155,15 @@ class SessionEnhancedTest < ActiveSupport::TestCase assert( Sessions.thread_client_exists?(client_id3), "check if client is running" ) # check if session still exists after idle cleanup - sleep 62 - client_ids = Sessions.destory_idle_sessions(1) + sleep 6 + client_ids = Sessions.destory_idle_sessions(5) # check client sessions assert( !Sessions.session_exists?(client_id1), "check if session is removed" ) assert( !Sessions.session_exists?(client_id2), "check if session is removed" ) assert( !Sessions.session_exists?(client_id3), "check if session is removed" ) - sleep 28 + sleep 6 # check client threads assert( !Sessions.thread_client_exists?(client_id1), "check if client is running" ) @@ -279,8 +279,8 @@ class SessionEnhancedTest < ActiveSupport::TestCase check_if_collection_reset_message_exists(client_id2, collections, 'update') # check if session still exists after idle cleanup - sleep 62 - client_ids = Sessions.destory_idle_sessions(1) + sleep 6 + client_ids = Sessions.destory_idle_sessions(5) # check client sessions assert( !Sessions.session_exists?(client_id1_0), "check if session is removed" )