This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "snap-core".

The branch, master has been updated
       via  fab18d58ee5282c61005045acd5851921bb6db25 (commit)
      from  e6f55ff7f097e639e4d5b67ef1faf092ef227c04 (commit)


Summary of changes:
 src/Snap/Iteratee.hs              |    7 +++++-
 test/suite/Snap/Iteratee/Tests.hs |   40 +++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletions(-)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit fab18d58ee5282c61005045acd5851921bb6db25
Author: Gregory Collins <[email protected]>
Date:   Wed Jun 2 21:07:21 2010 -0400

    Add some buffer iteratee tests

diff --git a/src/Snap/Iteratee.hs b/src/Snap/Iteratee.hs
index 718f0b0..545ed36 100644
--- a/src/Snap/Iteratee.hs
+++ b/src/Snap/Iteratee.hs
@@ -126,6 +126,11 @@ countBytes = go 0
 -- Our enumerators produce a lot of little strings; rather than spending all
 -- our time doing kernel context switches for 4-byte write() calls, we buffer
 -- the iteratee to send 8KB at a time.
+--
+-- The IORef returned can be set to True to "cancel" buffering. We added this
+-- so that transfer-encoding: chunked (which needs its own buffer and therefore
+-- doesn't need /its/ output buffered) can switch the outer buffer off.
+--
 bufferIteratee :: Iteratee IO a -> IO (Iteratee IO a, IORef Bool)
 bufferIteratee iteratee = do
     esc <- newIORef False
@@ -157,7 +162,7 @@ bufferIteratee iteratee = do
         big = WrapBS str
 
     f (!dl,!n) iter (Chunk (WrapBS s)) =
-        if n' > blocksize
+        if n' >= blocksize
            then do
                iterv <- runIter iter (Chunk big)
                case iterv of
diff --git a/test/suite/Snap/Iteratee/Tests.hs 
b/test/suite/Snap/Iteratee/Tests.hs
index f00eb84..8ea2687 100644
--- a/test/suite/Snap/Iteratee/Tests.hs
+++ b/test/suite/Snap/Iteratee/Tests.hs
@@ -12,6 +12,7 @@ import           Control.Monad.Identity
 import qualified Data.ByteString as S
 import qualified Data.ByteString.Lazy.Char8 as L
 import           Data.Monoid
+import           Data.IORef
 import           Data.Iteratee.WrappedByteString
 import           Data.Word
 import           Prelude hiding (drop, take)
@@ -45,6 +46,8 @@ tests = [ testEnumBS
         , testBuffer2
         , testBuffer3
         , testBuffer4
+        , testBufferChain
+        , testBufferChainEscape
         , testUnsafeBuffer
         , testUnsafeBuffer2
         , testUnsafeBuffer3
@@ -136,6 +139,43 @@ testBuffer4 = testProperty "testBuffer4" $
         expectException $ run k
 
 
+testBufferChain :: Test
+testBufferChain = testProperty "testBufferChain" $
+                  monadicIO $ forAllM arbitrary prop
+  where
+    prop s = do
+        pre (s /= L.empty)
+
+        (j,_) <- liftQ $ bufferIteratee stream2stream
+        (i,_) <- liftQ $ bufferIteratee j
+        iter  <- liftQ $ enumLBS s' i
+        x     <- liftQ $ run iter
+
+        QC.assert $ fromWrap x == s'
+      where
+        s' = L.take 20000 $ L.cycle s
+
+
+testBufferChainEscape :: Test
+testBufferChainEscape = testProperty "testBufferChainEscape" $
+                        monadicIO $ forAllM arbitrary prop
+  where
+    prop s = do
+        pre (s /= L.empty)
+
+        (j,esc) <- liftQ $ bufferIteratee stream2stream
+        (i,_)   <- liftQ $ bufferIteratee j
+
+        liftQ $ writeIORef esc True
+
+        iter    <- liftQ $ enumLBS s' i
+        x       <- liftQ $ run iter
+
+        QC.assert $ fromWrap x == s'
+      where
+        s' = L.take 20000 $ L.cycle s
+
+
 copyingStream2stream :: Iteratee IO (WrappedByteString Word8)
 copyingStream2stream = IterateeG (step mempty)
   where
-----------------------------------------------------------------------


hooks/post-receive
-- 
snap-core
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap

Reply via email to