module Tochtli::Test::Integration
Public Instance Methods
after_teardown()
click to toggle source
Calls superclass method
# File lib/tochtli/test/integration.rb, line 28 def after_teardown begin @controller_manager.stop if @controller_manager rescue Timeout::Error warn "Unable to stop controller manager: #{$!} [#{$!.class}]" end super end
before_setup()
click to toggle source
Calls superclass method
# File lib/tochtli/test/integration.rb, line 12 def before_setup super @logger = Tochtli.logger @logger.level = Logger::DEBUG @client = Tochtli::RabbitClient.new(nil, @logger) @connection = @client.rabbit_connection @controller_manager = Tochtli::ControllerManager.instance @controller_manager.stop # restart all controllers - some can be started with functional tests on test connections @controller_manager.setup(connection: @connection, logger: @logger) @controller_manager.start(:all) # Reply support @mutex = Mutex.new @cv = ConditionVariable.new end
Private Instance Methods
publish(message, options={})
click to toggle source
# File lib/tochtli/test/integration.rb, line 39 def publish(message, options={}) @reply = nil timeout = options.fetch(:timeout, 1.0) @reply_message_class = options[:expect] @reply_handler = options[:reply_handler] if @reply_message_class || @reply_handler handler = @reply_handler || method(:synchronous_reply_handler) if handler.is_a?(Proc) @client.reply_queue.register_message_handler message, &handler else @client.reply_queue.register_message_handler message, handler, timeout end end @client.publish message if @reply_message_class && !@reply_handler synchronous_timeout_handler(message, timeout) end end
synchronous_reply_handler(reply)
click to toggle source
# File lib/tochtli/test/integration.rb, line 61 def synchronous_reply_handler(reply) assert_kind_of @reply_message_class, reply, "Unexpected reply" @mutex.synchronize do @reply = reply @cv.signal end end
synchronous_timeout_handler(message, timeout)
click to toggle source
# File lib/tochtli/test/integration.rb, line 69 def synchronous_timeout_handler(message, timeout) @mutex.synchronize { @cv.wait(@mutex, timeout) unless @reply } raise "Reply on #{message.class.name} timeout" unless @reply raise @reply.message if @reply.is_a?(Tochtli::ErrorMessage) @reply end