1 # -*- encoding: binary -*-
6 class TestWatcher < Test::Unit::TestCase
7 TEST_ADDR = ENV['UNICORN_TEST_ADDR'] || '127.0.0.1'
8 def check_headers(headers)
9 %w(X-Count X-Std-Dev X-Min X-Max X-Mean
10 X-Outliers-Low X-Outliers-Low X-Last-Reset).each { |x|
11 assert_kind_of String, headers[x], "#{x} missing"
17 @ios.each { |io| io.close unless io.closed? }
22 @srv = TCPServer.new TEST_ADDR, 0
25 @client = TCPSocket.new TEST_ADDR, @port
26 @addr = "#{TEST_ADDR}:#{@port}"
28 @app = Raindrops::Watcher.new :delay => 0.001
29 @req = Rack::MockRequest.new @app
34 assert_equal 200, resp.status.to_i
35 t = Time.parse resp.headers["Last-Modified"]
36 assert_in_delta Time.now.to_f, t.to_f, 2.0
40 resp = @req.get "/active/#@addr.txt"
41 assert_equal 200, resp.status.to_i
42 assert_equal "text/plain", resp.headers["Content-Type"]
43 check_headers(resp.headers)
47 resp = @req.get "/active/#@addr.html"
48 assert_equal 200, resp.status.to_i
49 assert_equal "text/html", resp.headers["Content-Type"]
50 check_headers(resp.headers)
54 resp = @req.get "/queued/#@addr.txt"
55 assert_equal 200, resp.status.to_i
56 assert_equal "text/plain", resp.headers["Content-Type"]
57 check_headers(resp.headers)
61 resp = @req.get "/queued/#@addr.html"
62 assert_equal 200, resp.status.to_i
63 assert_equal "text/html", resp.headers["Content-Type"]
64 check_headers(resp.headers)
68 resp = @req.post "/reset/#@addr"
69 assert_equal 302, resp.status.to_i
73 env = @req.class.env_for "/tail/#@addr.txt"
74 status, headers, body = @app.call env
75 assert_equal "text/plain", headers["Content-Type"]
76 assert_equal 200, status.to_i
79 assert_kind_of String, x
85 def test_tail_queued_min
86 env = @req.class.env_for "/tail/#@addr.txt?queued_min=1"
87 status, headers, body = @app.call env
88 assert_equal "text/plain", headers["Content-Type"]
89 assert_equal 200, status.to_i
92 tmp = TCPSocket.new TEST_ADDR, @port
94 assert_kind_of String, x
95 assert_equal 1, x.strip.split(/\s+/).last.to_i
99 end if RUBY_PLATFORM =~ /linux/