Sha256: 639ed7164fc873f83127141f4be7a90d53f5090f761acb44956b4093a83c6c35

Contents?: true

Size: 1.52 KB

Versions: 6

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'
require 'litmus_paper/agent_check_server'

describe LitmusPaper::AgentCheckServer do
  pid = nil

  before :all do
    if ! Kernel.system("bundle exec litmus-agent-check -s passing_test:9191,test:9192 -c spec/support/test.config -w 10 -D")
      fail('Unable to start server')
    end
    port_open = false
    while ! port_open do
      begin
        TCPSocket.new('localhost', 9191)
      rescue StandardError => e
        sleep 0.1
        next
      end
      port_open = true
    end
  end

  after :all do
    Process.kill(:TERM, File.read('/tmp/litmus-agent-check.pid').to_i)
  end

  describe "The agent-check text protocol" do
    it "returns the health from a passing test" do
      TCPSocket.open('localhost', 9191) do |s|
        s.gets.should match(/ready\tup\t\d+%\r\n/)
      end
    end
    it "returns the health from a failing test" do
      TCPSocket.open('localhost', 9192) do |s|
        s.gets.should match(/down\t0%\r\n/)
      end
    end
  end

  describe "server" do
    it "has the configured number of children running" do
      pid = File.read('/tmp/litmus-agent-check.pid').to_i
      children = `ps --no-headers --ppid #{pid}|wc -l`
      children.strip.to_i == 10
    end
  end

  describe "server" do
    it "if a child dies you get a new one" do
      pid = File.read('/tmp/litmus-agent-check.pid').to_i
      Kernel.system("kill -9 $(ps --no-headers --ppid #{pid} -o pid=|tail -1)")
      sleep 0.5
      children = `ps --no-headers --ppid #{pid}|wc -l`
      children.strip.to_i == 10
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
litmus_paper-1.2.0 spec/litmus_paper/agent_check_server_spec.rb
litmus_paper-1.1.1 spec/litmus_paper/agent_check_server_spec.rb
litmus_paper-1.1.0 spec/litmus_paper/agent_check_server_spec.rb
litmus_paper-1.0.0 spec/litmus_paper/agent_check_server_spec.rb
litmus_paper-0.9.9 spec/litmus_paper/agent_check_server_spec.rb
litmus_paper-0.9.7 spec/litmus_paper/agent_check_server_spec.rb