<commit_before>require File.join(File.dirname(__FILE__), "helpers")
require "sensu/transport/rabbitmq"
require "sensu/logger"

describe "Sensu::Transport::RabbitMQ" do
  include Helpers

  before do
    @transport = Sensu::Transport::RabbitMQ.new
    @transport.logger = Sensu::Logger.get(:log_level => :fatal)
  end

  it "provides a transport API" do
    expect(@transport).to respond_to(:on_error, :before_reconnect, :after_reconnect,
                                     :connect, :reconnect, :connected?, :close,
                                     :publish, :subscribe, :unsubscribe,
                                     :acknowledge, :ack, :stats)
  end

  it "can publish and subscribe" do
    async_wrapper do
      @transport.connect
      callback = Proc.new do |message|
        expect(message).to eq("msg")
        timer(0.5) do
          async_done
        end
      end
      @transport.subscribe("direct", "foo", "baz", {}, &callback)
      @transport.subscribe("direct", "bar", "baz", {}, &callback)
      timer(1) do
        @transport.publish("direct", "foo", "msg") do |info|
          expect(info).to be_kind_of(Hash)
          expect(info).to be_empty
        end
      end
    end
  end

  it "can open a connection using a hostname" do
    async_wrapper do
      @transport.connect(:host => "localhost")
      timer(1) do
        expect(@transport.connected?).to be(true)
        async_done
      end
    end
  end

  it "can unsubscribe from queues and close the connection" do
    async_wrapper do
      @transport.connect
      @transport.subscribe("direct", "bar") do |info, message|
        true
      end
      timer(1) do
        @transport.unsubscribe do
          @transport.close
          expect(@transport.connected?).to be(false)
          async_done
        end<commit_msg>[dns-resolv] increased hostname connect spec wait time<commit_after>require File.join(File.dirname(__FILE__), "helpers")
require "sensu/transport/rabbitmq"
require "sensu/logger"

describe "Sensu::Transport::RabbitMQ" do
  include Helpers

  before do
    @transport = Sensu::Transport::RabbitMQ.new
    @transport.logger = Sensu::Logger.get(:log_level => :fatal)
  end

  it "provides a transport API" do
    expect(@transport).to respond_to(:on_error, :before_reconnect, :after_reconnect,
                                     :connect, :reconnect, :connected?, :close,
                                     :publish, :subscribe, :unsubscribe,
                                     :acknowledge, :ack, :stats)
  end

  it "can publish and subscribe" do
    async_wrapper do
      @transport.connect
      callback = Proc.new do |message|
        expect(message).to eq("msg")
        timer(0.5) do
          async_done
        end
      end
      @transport.subscribe("direct", "foo", "baz", {}, &callback)
      @transport.subscribe("direct", "bar", "baz", {}, &callback)
      timer(1) do
        @transport.publish("direct", "foo", "msg") do |info|
          expect(info).to be_kind_of(Hash)
          expect(info).to be_empty
        end
      end
    end
  end

  it "can open a connection using a hostname" do
    async_wrapper do
      @transport.connect(:host => "localhost")
      timer(2) do
        expect(@transport.connected?).to be(true)
        async_done
      end
    end
  end

  it "can unsubscribe from queues and close the connection" do
    async_wrapper do
      @transport.connect
      @transport.subscribe("direct", "bar") do |info, message|
        true
      end
      timer(1) do
        @transport.unsubscribe do
          @transport.close
          expect(@transport.connected?).to be(false)
          async_done
        end
{'fraction_non_alphanumeric': 0.11268758526603001, 'fraction_numerical': 0.002728512960436562, 'mean_word_length': 2.25, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1033126', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1045, 'n_words': 273}