features/support/test_stomp_server.rb in stomper-2.0.0 vs features/support/test_stomp_server.rb in stomper-2.0.1

- old
+ new

@@ -1,12 +1,17 @@ class TestStompServer + class StopThread < StandardError; end + attr_accessor :session_class attr_reader :session def initialize(version=nil) @port = 61613 - @socket = TCPServer.new(@port) + begin + @socket = TCPServer.new(@port) + rescue Exception => ex + end @session = nil @version = version @session_class = StompSession end @@ -21,18 +26,18 @@ end def stop @session.stop if @session @socket.close rescue nil - @listener.kill rescue nil + @listener.raise(StopThread.new) @listener.join rescue nil end def force_stop @session.force_stop if @session @socket.close rescue nil - @listener.kill rescue nil + @listener.raise(StopThread.new) @listener.join rescue nil end def handle_client(client) @@ -52,14 +57,15 @@ headers = {} version && headers[:version] = version connect_to_client(headers) @serializer.extend_for_protocol('1.1') if version == '1.1' @receive_thread = Thread.new do - while @running + while true begin read_frame rescue Exception => ex + break end end end end @@ -68,10 +74,11 @@ send_frame 'CONNECTED', headers end def force_stop @running = false + @receive_thread.raise(StopThread.new) @client_socket.close rescue nil @receive_thread.join rescue nil end def stop @@ -110,12 +117,15 @@ end end def send_frame cmd, headers={}, body=nil frame = cmd.is_a?(Stomper::Frame) ? cmd : Stomper::Frame.new(cmd, headers, body) - @serializer.write_frame(frame).tap do |f| - @sent_frames << f + begin + @serializer.write_frame(frame).tap do |f| + @sent_frames << f + end + rescue Exception => ex end end end class StompErrorOnConnectSession < StompSession @@ -133,10 +143,14 @@ } } def initialize(version=nil, certs=:default) @port = 61612 - @tcp_socket = TCPServer.new(@port) + begin + @tcp_socket = TCPServer.new(@port) + rescue Exception => ex + retry + end @ssl_context = OpenSSL::SSL::SSLContext.new @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE cert_files = SSL_CERT_FILES[certs] @ssl_context.key = OpenSSL::PKey::RSA.new(File.read(cert_files[:k])) @ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(cert_files[:c]))