1 # -*- encoding: binary -*-
6 $stderr.sync = $stdout.sync = true
8 class TestLinuxMiddleware < Test::Unit::TestCase
11 @resp_headers = { 'Content-Type' => 'text/plain', 'Content-Length' => '0' }
12 @response = [ 200, @resp_headers, [] ]
13 @app = lambda { |env| @response }
18 @to_close.each { |io| io.close unless io.closed? }
21 def test_unix_listener
22 tmp = Tempfile.new("")
24 @to_close << UNIXServer.new(tmp.path)
25 app = Raindrops::Middleware.new(@app, :listeners => [tmp.path])
26 linux_extra = "#{tmp.path} active: 0\n#{tmp.path} queued: 0\n"
27 response = app.call("PATH_INFO" => "/_raindrops")
32 "Content-Type" => "text/plain",
33 "Content-Length" => (22 + linux_extra.size).to_s
36 "calling: 0\nwriting: 0\n#{linux_extra}" \
39 assert_equal expect, response
42 def test_unix_listener_queued
43 tmp = Tempfile.new("")
45 @to_close << UNIXServer.new(tmp.path)
46 @to_close << UNIXSocket.new(tmp.path)
47 app = Raindrops::Middleware.new(@app, :listeners => [tmp.path])
48 linux_extra = "#{tmp.path} active: 0\n#{tmp.path} queued: 1\n"
49 response = app.call("PATH_INFO" => "/_raindrops")
54 "Content-Type" => "text/plain",
55 "Content-Length" => (22 + linux_extra.size).to_s
58 "calling: 0\nwriting: 0\n#{linux_extra}" \
61 assert_equal expect, response
64 end if RUBY_PLATFORM =~ /linux/