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