diff --git a/spec/lite_spec_helper.rb b/spec/lite_spec_helper.rb index 3ec491c01e..82824c54b5 100644 --- a/spec/lite_spec_helper.rb +++ b/spec/lite_spec_helper.rb @@ -19,7 +19,14 @@ require 'support/spec_config' require 'mrss/lite_constraints' -require "support/session_registry" + +if Gem::Version.new(Mongo::VERSION) < Gem::Version.new('2.18.0.alpha') + require "mrss/session_registry_legacy" +else + require "mrss/session_registry" +end + +Mrss.patch_mongo_for_session_registry unless SpecConfig.instance.ci? begin diff --git a/spec/mongoid/query_cache_spec.rb b/spec/mongoid/query_cache_spec.rb index 454d6dd7f0..80d32cfc1f 100644 --- a/spec/mongoid/query_cache_spec.rb +++ b/spec/mongoid/query_cache_spec.rb @@ -17,11 +17,11 @@ # occur only within the scope of these tests. # # Other session leaks will be detected and addressed as part of RUBY-2391. - SessionRegistry.instance.clear_registry + Mrss::SessionRegistry.instance.clear_registry end after do - SessionRegistry.instance.verify_sessions_ended! + Mrss::SessionRegistry.instance.verify_sessions_ended! end let(:reset_legacy_qc_warning) do diff --git a/spec/shared b/spec/shared index dc4bbe242a..9b452a0ecd 160000 --- a/spec/shared +++ b/spec/shared @@ -1 +1 @@ -Subproject commit dc4bbe242a6022f707eb0a661dee5ead7e5849a3 +Subproject commit 9b452a0ecd0556e20cebc354fcfc44c911f0545d diff --git a/spec/support/session_registry.rb b/spec/support/session_registry.rb deleted file mode 100644 index 32f8aad1bb..0000000000 --- a/spec/support/session_registry.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'singleton' - -module Mongo - class Client - alias :get_session_without_tracking :get_session - - def get_session(options = {}) - get_session_without_tracking(options).tap do |session| - SessionRegistry.instance.register(session) - end - end - end - - class Session - alias :end_session_without_tracking :end_session - - def end_session - SessionRegistry.instance.unregister(self) - end_session_without_tracking - end - end -end - - -class SessionRegistry - include Singleton - - def initialize - @registry = {} - end - - def register(session) - @registry[session.session_id] = session if session - end - - def unregister(session) - @registry.delete(session.session_id) - end - - def verify_sessions_ended! - unless @registry.empty? - sessions = @registry.map { |_, session| session } - raise "Session registry contains live sessions: #{sessions.join(', ')}" - end - end - - def clear_registry - @registry = {} - end -end