1 # -*- encoding: binary -*-
2 # frozen_string_literal: false
7 $stderr.sync = $stdout.sync = true
9 class TestLinuxMiddleware < Test::Unit::TestCase
12 @resp_headers = { 'Content-Type' => 'text/plain', 'Content-Length' => '0' }
13 @response = [ 200, @resp_headers, [] ]
14 @app = lambda { |env| @response }
19 @to_close.each { |io| io.close unless io.closed? }
22 def test_unix_listener
23 tmp = Tempfile.new("")
25 @to_close << UNIXServer.new(tmp.path)
26 app = Raindrops::Middleware.new(@app, :listeners => [tmp.path])
27 linux_extra = "#{tmp.path} active: 0\n#{tmp.path} queued: 0\n"
28 response = app.call("PATH_INFO" => "/_raindrops")
33 "Content-Type" => "text/plain",
34 "Content-Length" => (22 + linux_extra.size).to_s
37 "calling: 0\nwriting: 0\n#{linux_extra}" \
40 assert_equal expect, response
43 def test_unix_listener_queued
44 tmp = Tempfile.new("")
46 @to_close << UNIXServer.new(tmp.path)
47 @to_close << UNIXSocket.new(tmp.path)
48 app = Raindrops::Middleware.new(@app, :listeners => [tmp.path])
49 linux_extra = "#{tmp.path} active: 0\n#{tmp.path} queued: 1\n"
50 response = app.call("PATH_INFO" => "/_raindrops")
55 "Content-Type" => "text/plain",
56 "Content-Length" => (22 + linux_extra.size).to_s
59 "calling: 0\nwriting: 0\n#{linux_extra}" \
62 assert_equal expect, response
65 end if RUBY_PLATFORM =~ /linux/