1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
| | # -*- encoding: binary -*-
require 'test/unit'
require 'tempfile'
require 'raindrops'
require 'socket'
$stderr.sync = $stdout.sync = true
class TestLinuxMiddleware < Test::Unit::TestCase
def setup
@resp_headers = { 'Content-Type' => 'text/plain', 'Content-Length' => '0' }
@response = [ 200, @resp_headers, [] ]
@app = lambda { |env| @response }
@to_close = []
end
def teardown
@to_close.each { |io| io.close unless io.closed? }
end
def test_unix_listener
tmp = Tempfile.new("")
File.unlink(tmp.path)
@to_close << UNIXServer.new(tmp.path)
app = Raindrops::Middleware.new(@app, :listeners => [tmp.path])
linux_extra = "#{tmp.path} active: 0\n#{tmp.path} queued: 0\n"
response = app.call("PATH_INFO" => "/_raindrops")
expect = [
200,
{
"Content-Type" => "text/plain",
"Content-Length" => (22 + linux_extra.size).to_s
},
[
"calling: 0\nwriting: 0\n#{linux_extra}" \
]
]
assert_equal expect, response
end
def test_unix_listener_queued
tmp = Tempfile.new("")
File.unlink(tmp.path)
@to_close << UNIXServer.new(tmp.path)
@to_close << UNIXSocket.new(tmp.path)
app = Raindrops::Middleware.new(@app, :listeners => [tmp.path])
linux_extra = "#{tmp.path} active: 0\n#{tmp.path} queued: 1\n"
response = app.call("PATH_INFO" => "/_raindrops")
expect = [
200,
{
"Content-Type" => "text/plain",
"Content-Length" => (22 + linux_extra.size).to_s
},
[
"calling: 0\nwriting: 0\n#{linux_extra}" \
]
]
assert_equal expect, response
end
end if RUBY_PLATFORM =~ /linux/
|