Sha256: dad04becff12e41ea1522e89f45840eb6e6bb91543da8cae4c57a188ee7a7b05

Contents?: true

Size: 998 Bytes

Versions: 2

Compression:

Stored size: 998 Bytes

Contents

# For Gem.ruby, and almost certainly already loaded
require 'rubygems'

module TestNode
  def self.start
    @pid = Process.spawn Gem.ruby, File.expand_path("../../test_node.rb", __FILE__)
    unless @pid
      STDERR.print "ERROR: Couldn't start test node. Do you have Redis installed?"
      exit 1
    end
  end

  def self.wait_until_ready
    STDERR.print "Waiting for test node to start up..."

    socket = nil
    30.times do
      begin
        socket = TCPSocket.open(TEST_NODE[:addr], TEST_NODE[:port])
        break if socket
      rescue Errno::ECONNREFUSED
        STDERR.print "."
        sleep 1
      end
    end

    if socket
      STDERR.puts " done!"
      socket.close
    else
      STDERR.puts " FAILED!"
      raise "couldn't connect to test node!"
    end
  end

  def self.stop
    unless @pid
      STDERR.print "ERROR: Test node was never started!"
      exit 1
    end
    Process.kill 9, @pid
  rescue Errno::ESRCH
  ensure
    Process.wait @pid rescue nil
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
dcell-0.16.1 spec/support/helpers.rb
stn-dcell-0.16.0 spec/support/helpers.rb