1 # -*- encoding: binary -*-
2 require "./test/rack_unicorn"
6 $stderr.sync = $stdout.sync = true
8 Raindrops::Aggregate::PMQ
10 warn "W: #{e} skipping test"
13 if RUBY_VERSION.to_f < 1.9
15 warn "W: skipping test=#{__FILE__}, only Ruby 1.9 supported for now"
18 class TestLastDataRecvUnicorn < Test::Unit::TestCase
20 @queue = "/test.#{rand}"
21 @host = ENV["UNICORN_TEST_ADDR"] || "127.0.0.1"
22 @sock = TCPServer.new @host, 0
24 ENV["UNICORN_FD"] = @sock.fileno.to_s
25 @host_with_port = "#@host:#@port"
26 @cfg = Tempfile.new 'unicorn_config_file'
27 @cfg.puts "require 'raindrops'"
28 @cfg.puts "preload_app true"
29 ENV['RAINDROPS_MQUEUE'] = @queue
30 # @cfg.puts "worker_processes 4"
31 @opts = { :listeners => [ @host_with_port ], :config_file => @cfg.path }
34 def test_auto_listener
36 Thread.abort_on_exception = true
37 app = %q!Rack::Builder.new do
38 map("/ldr") { run Raindrops::LastDataRecv.new }
39 map("/") { run Rack::Lobster.new }
42 def app.call; eval self; end
43 Unicorn::HttpServer.new(app, @opts).start.join
45 400.times { assert_kind_of Net::HTTPSuccess, get("/") }
47 # # p(resp.methods - Object.methods)
48 # resp.each_header { |k,v| p [k, "=" , v] }
49 assert resp.header["x-count"]
50 assert resp.header["x-min"]
51 assert resp.header["x-max"]
52 assert resp.header["x-mean"]
53 assert resp.header["x-std-dev"]
54 assert resp.header["x-outliers-low"]
55 assert resp.header["x-outliers-high"]
56 assert resp.body.size > 0
60 Net::HTTP.start(@host, @port) { |http| http.get path }
64 Process.kill :QUIT, @srv
65 _, status = Process.waitpid2 @srv
66 assert status.success?
67 POSIX_MQ.unlink @queue
69 end if defined?(Unicorn) && RUBY_PLATFORM =~ /linux/ && pmq