diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-04-07 17:07:42 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-04-07 17:36:31 -0700 |
commit | c3e9f5ba6fc10397f55941f36da29808a105d248 (patch) | |
tree | 705970f479064931ae07cfca0cd44013c113cb8d /test/test_linux_middleware.rb | |
download | raindrops-c3e9f5ba6fc10397f55941f36da29808a105d248.tar.gz |
Diffstat (limited to 'test/test_linux_middleware.rb')
-rw-r--r-- | test/test_linux_middleware.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/test_linux_middleware.rb b/test/test_linux_middleware.rb new file mode 100644 index 0000000..670b853 --- /dev/null +++ b/test/test_linux_middleware.rb @@ -0,0 +1,59 @@ +# -*- 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 } + end + + def test_unix_listener + tmp = Tempfile.new("") + File.unlink(tmp.path) + us = 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) + us = UNIXServer.new(tmp.path) + uc = 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/ |