test/support/test_handler.rb in m2r-2.0.2 vs test/support/test_handler.rb in m2r-2.1.0.pre

- old
+ new

@@ -1,55 +1,72 @@ +require 'thread' require 'm2r/handler' class TestHandler < M2R::Handler attr_reader :called_methods - def initialize(connection, parser) + def initialize(connection_factory, parser) super + @mutex = Mutex.new @called_methods = [] + Thread.current[:called_methods] = [] end def on_wait() - unless @called_methods.empty? + unless Thread.current[:called_methods].empty? stop return end - @called_methods << :wait + called_method :wait end def on_request(request) - @called_methods << :request + called_method :request end def process(request) - @called_methods << :process + called_method :process return "response" end def on_disconnect(request) - @called_methods << :disconnect + called_method :disconnect end def on_upload_start(request) - @called_methods << :start + called_method :start end def on_upload_done(request) - @called_methods << :done + called_method :done end def after_process(request, response) - @called_methods << :after + called_method :after return response end def after_reply(request, response) - @called_methods << :reply + called_method :reply end def after_all(request, response) - @called_methods << :all + called_method :all end def on_error(request, response, error) - @called_methods << :error + called_method :error end + + def on_interrupted + called_method :interrupted + end + + private + + def called_method(mth) + Thread.current[:called_methods] << mth + @mutex.synchronize do + @called_methods << mth + end + end + end