about summary refs log tree commit homepage
path: root/test/test_clogger.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-06-06 00:43:34 +0000
committerEric Wong <normalperson@yhbt.net>2010-06-06 05:19:34 +0000
commitbc1d1df38d7803ce9fdae05fc5129051eeed89e0 (patch)
treefda0e314119f27ed3ea4aa6848d653e2ff0070ed /test/test_clogger.rb
parente4c3548e8ff4c95c697b4a30699e6f655d60f188 (diff)
downloadclogger-bc1d1df38d7803ce9fdae05fc5129051eeed89e0.tar.gz
We no longer write the log out at the end of the body.each call.
This is a behavioral change, but fortunately all Rack servers
I've seen call body.close inside an ensure.

This allows us to later pass along the "to_path" method
and not rely on "each" to write the log.
Diffstat (limited to 'test/test_clogger.rb')
-rw-r--r--test/test_clogger.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/test/test_clogger.rb b/test/test_clogger.rb
index a20793c..1311017 100644
--- a/test/test_clogger.rb
+++ b/test/test_clogger.rb
@@ -55,6 +55,7 @@ class TestClogger < Test::Unit::TestCase
     assert_equal("302 Found", status)
     assert_equal({}, headers)
     body.each { |part| assert false }
+    body.close
     str = str.string
     r = %r{\Ahome - - \[[^\]]+\] "GET /hello\?goodbye=true HTTP/1.0" 302 -\n\z}
     assert_match r, str
@@ -134,7 +135,9 @@ class TestClogger < Test::Unit::TestCase
       'HTTP_COOKIE' => cookie,
     }
     req = @req.merge(req)
-    cl.call(req).last.each { |part| part }
+    body = cl.call(req).last
+    body.each { |part| part }
+    body.close
     str = str.string
     assert(str.size > 128)
     assert_match %r["echo and socat \\o/" "#{cookie}" \d+\.\d{3}], str
@@ -221,6 +224,7 @@ class TestClogger < Test::Unit::TestCase
     status, headers, body = cl.call(@req)
     tmp = []
     body.each { |s| tmp << s }
+    body.close
     assert_equal %w(a b c), tmp
     str = str.string
     assert_match %r[" 200 3 \d+\.\d{4}\n\z], str
@@ -279,6 +283,7 @@ class TestClogger < Test::Unit::TestCase
     cl = Clogger.new(app, :logger => str, :format => '$response_length')
     status, header, bodies = cl.call(@req)
     bodies.each { |part| part }
+    bodies.close
     assert_equal "-\n", str.string
   end
 
@@ -290,6 +295,7 @@ class TestClogger < Test::Unit::TestCase
     status, headers, body = cl.call(@req)
     tmp = []
     body.each { |s| tmp << s }
+    body.close
     assert_equal %w(a b c), tmp
     str = str.string
     assert_match %r[" 200 3 "-" "echo and socat \\o/"\n\z], str
@@ -402,7 +408,7 @@ class TestClogger < Test::Unit::TestCase
     req = Rack::Utils::HeaderHash.new(@req)
     app = lambda { |env| [302, [ %w(a) ], []] }
     cl = Clogger.new(app, :logger => str, :format => Rack_1_0)
-    assert_nothing_raised { cl.call(req).last.each {} }
+    assert_nothing_raised { cl.call(req).last.each {}.close }
     assert str.size > 0
   end
 
@@ -415,7 +421,7 @@ class TestClogger < Test::Unit::TestCase
     }
     app = lambda { |env| [302, [ %w(a) ], []] }
     cl = Clogger.new(app, :logger => str, :format => Rack_1_0)
-    assert_nothing_raised { cl.call(req).last.each {} }
+    assert_nothing_raised { cl.call(req).last.each {}.close }
     assert str.size > 0
   end
 
@@ -425,7 +431,7 @@ class TestClogger < Test::Unit::TestCase
     r = nil
     app = lambda { |env| [302, [ %w(a) ], [FooString.new(body)]] }
     cl = Clogger.new(app, :logger => str, :format => '$body_bytes_sent')
-    assert_nothing_raised { cl.call(@req).last.each { |x| r = x } }
+    assert_nothing_raised { cl.call(@req).last.each { |x| r = x }.close }
     assert str.size > 0
     assert_equal body.size.to_s << "\n", str.string
     assert_equal r, body