Sha256: fac34f40a7887958c1305ee0d2a559ceffad2ac11317779b50c152f6c67552a7

Contents?: true

Size: 865 Bytes

Versions: 4

Compression:

Stored size: 865 Bytes

Contents

require "tempfile"
require "childprocess"

class RabbitControl

  TIMEOUT = 10

  def initialize
    @tmp     = Tempfile.new("rabbit-control")
    @process = ChildProcess.build("rabbitmq-server")

    @process.io.stdout = @tmp
    @process.io.stderr = @tmp
  end

  def start
    @process.start

    max_time = Time.now + TIMEOUT

    until running?
      if Time.now > max_time
        raise "timed out waiting for rabbitmq-server"
      end
      sleep 0.1
    end

    system "rabbitmqctl list_users 2>&1"
    raise "rabbit error: #{out}" unless $?.success?

    true
  end

  def stop
    @process.stop
    @tmp.close!
  end

  def running?
    @tmp.rewind
    output = @tmp.read
    puts output if $DEBUG
    output =~ /broker running/
  end

end

if __FILE__ == $0
  rabbitctl = RabbitControl.new
  trap("INT") { rabbitctl.stop }
  rabbitctl.start
  sleep
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cukeq-0.0.1.dev5 features/support/rabbit_control.rb
cukeq-0.0.1.dev4 features/support/rabbit_control.rb
cukeq-0.0.1.dev3 features/support/rabbit_control.rb
cukeq-0.0.1.dev2 features/support/rabbit_control.rb