about summary refs log tree commit homepage
path: root/test/test_linux_middleware.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_linux_middleware.rb')
-rw-r--r--test/test_linux_middleware.rb59
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/