From 90726e5187a9053c6eb7caf90ebec1d38d4372ea Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 8 Mar 2011 14:18:11 -0800 Subject: preliminary Rack app to track last_data_recv Seems to basically work --- test/test_last_data_recv_unicorn.rb | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/test_last_data_recv_unicorn.rb (limited to 'test') diff --git a/test/test_last_data_recv_unicorn.rb b/test/test_last_data_recv_unicorn.rb new file mode 100644 index 0000000..19aba0d --- /dev/null +++ b/test/test_last_data_recv_unicorn.rb @@ -0,0 +1,65 @@ +# -*- encoding: binary -*- +require "./test/rack_unicorn" +require "tempfile" +require "net/http" + +$stderr.sync = $stdout.sync = true +pmq = begin + Raindrops::Aggregate::PMQ +rescue => LoadError + warn "W: #{e} skipping test" + false +end + +class TestLastDataRecvUnicorn < Test::Unit::TestCase + def setup + @queue = "/test.#{rand}" + @host = ENV["UNICORN_TEST_ADDR"] || "127.0.0.1" + @sock = TCPServer.new @host, 0 + @port = @sock.addr[1] + ENV["UNICORN_FD"] = @sock.fileno.to_s + @host_with_port = "#@host:#@port" + @cfg = Tempfile.new 'unicorn_config_file' + @cfg.puts "require 'raindrops'" + @cfg.puts "preload_app true" + ENV['RAINDROPS_MQUEUE'] = @queue + # @cfg.puts "worker_processes 4" + @opts = { :listeners => [ @host_with_port ], :config_file => @cfg.path } + end + + def test_auto_listener + @srv = fork { + Thread.abort_on_exception = true + app = %q!Rack::Builder.new do + map("/ldr") { run Raindrops::LastDataRecv.new } + map("/") { run Rack::Lobster.new } + end.to_app! + def app.arity; 0; end + def app.call; eval self; end + Unicorn.run(app, @opts) + } + 400.times { assert_kind_of Net::HTTPSuccess, get("/") } + resp = get("/ldr") + # # p(resp.methods - Object.methods) + # resp.each_header { |k,v| p [k, "=" , v] } + assert resp.header["x-count"] + assert resp.header["x-min"] + assert resp.header["x-max"] + assert resp.header["x-mean"] + assert resp.header["x-std-dev"] + assert resp.header["x-outliers-low"] + assert resp.header["x-outliers-high"] + assert resp.body.size > 0 + end + + def get(path) + Net::HTTP.start(@host, @port) { |http| http.get path } + end + + def teardown + Process.kill :QUIT, @srv + _, status = Process.waitpid2 @srv + assert status.success? + POSIX_MQ.unlink @queue + end +end if defined?(Unicorn) && RUBY_PLATFORM =~ /linux/ && pmq -- cgit v1.2.3-24-ge0c7