Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add tests for SendFile and Cached

And some other miscellaneous changes.
  • Loading branch information...
commit 43d4080318441e07a21596b53e6b5a7db01035a0 1 parent 8b3c022
@scvalex authored
View
2  README.md
@@ -12,7 +12,7 @@ Start off with the
[naïve](https://github.com/scvalex/dissemina2/blob/master/Naive.hs)
implementation that just reads a file and sends it.
-[Continue](https://github.com/scvalex/dissemina2/blob/master/Sendfile.hs)
+[Continue](https://github.com/scvalex/dissemina2/blob/master/SendFile.hs)
using the dedicated system call for sending files, `sendfile(2)`.
Try to see if we can do better
View
2  Sendfile.hs → SendFile.hs
@@ -6,7 +6,7 @@
--
-- - @sendfile@ the requested file.
--
-module Cached where
+module SendFile where
import Data.ByteString.Char8 ()
import Network.Socket ( Socket )
View
17 Test/SimpleRequest.hs → Test/SimpleRequestTest.hs
@@ -1,25 +1,15 @@
{-# LANGUAGE OverloadedStrings #-}
-module Main where
+module SimpleRequestTest where
-import Control.Concurrent
import Data.ByteString.Char8 ( ByteString )
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
-import Data.Monoid
-import qualified Naive
import Network.HTTP
import Network.URI
-import Test.Framework
-import Test.Framework.Providers.HUnit
import Test.HUnit
-main :: IO ()
-main = defaultMainWithOpts
- [ testCase "naive" testNaive
- ] mempty
-
makeRequest :: String -> Request ByteString
makeRequest url =
Request { rqURI = fromJust (parseURI url)
@@ -27,9 +17,8 @@ makeRequest url =
, rqHeaders = []
, rqBody = "" }
-testNaive :: Assertion
-testNaive = do
- _ <- forkIO Naive.main
+testSimpleRequest :: Assertion
+testSimpleRequest = do
res <- simpleHTTP (makeRequest "http://localhost:5000/Naive.hs")
case res of
Left err -> do
View
22 Test/TestCached.hs
@@ -0,0 +1,22 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import Control.Concurrent
+import Data.Monoid
+import qualified Cached
+import SimpleRequestTest
+
+import Test.Framework
+import Test.Framework.Providers.HUnit
+import Test.HUnit
+
+main :: IO ()
+main = defaultMainWithOpts
+ [ testCase "cached" testCached
+ ] mempty
+
+testCached :: Assertion
+testCached = do
+ _ <- forkIO Cached.main
+ testSimpleRequest
View
22 Test/TestNaive.hs
@@ -0,0 +1,22 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import Control.Concurrent
+import Data.Monoid
+import qualified Naive
+import SimpleRequestTest
+
+import Test.Framework
+import Test.Framework.Providers.HUnit
+import Test.HUnit
+
+main :: IO ()
+main = defaultMainWithOpts
+ [ testCase "naive" testNaive
+ ] mempty
+
+testNaive :: Assertion
+testNaive = do
+ _ <- forkIO Naive.main
+ testSimpleRequest
View
22 Test/TestSendFile.hs
@@ -0,0 +1,22 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import Control.Concurrent
+import Data.Monoid
+import qualified SendFile
+import SimpleRequestTest
+
+import Test.Framework
+import Test.Framework.Providers.HUnit
+import Test.HUnit
+
+main :: IO ()
+main = defaultMainWithOpts
+ [ testCase "sendfile" testSendFile
+ ] mempty
+
+testSendFile :: Assertion
+testSendFile = do
+ _ <- forkIO SendFile.main
+ testSimpleRequest
View
28 dissemina2.cabal
@@ -13,7 +13,7 @@ Build-Type: Simple
Description:
See the @README.md@ file and the homepage for details.
-Extra-Source-Files: Makefile, Utils.hs
+Extra-Source-Files: Makefile, Utils.hs, Test/SimpleRequestTest.hs
Data-Files: README.md, LICENSE
@@ -28,7 +28,7 @@ Executable dissemina2-naive
Executable dissemina2-sendfile
Build-depends: base >= 4 && < 5, bytestring, network, sendfile
- Main-Is: Sendfile.hs
+ Main-Is: SendFile.hs
Ghc-options: -Wall -threaded
Executable dissemina2-cached
@@ -36,12 +36,32 @@ Executable dissemina2-cached
Main-Is: Cached.hs
Ghc-options: -Wall -threaded
-Test-suite simple
+Test-suite naive
Hs-Source-Dirs: Test, .
- Main-Is: SimpleRequest.hs
+ Main-Is: TestNaive.hs
Type: exitcode-stdio-1.0
Build-Depends: base >= 4 && < 5, bytestring, HTTP, network
Ghc-Options: -Wall -threaded
Build-Depends: test-framework, test-framework-hunit, HUnit
+
+Test-suite sendfile
+ Hs-Source-Dirs: Test, .
+ Main-Is: TestSendFile.hs
+ Type: exitcode-stdio-1.0
+
+ Build-Depends: base >= 4 && < 5, bytestring, HTTP, network, sendfile
+ Ghc-Options: -Wall -threaded
+
+ Build-Depends: test-framework, test-framework-hunit, HUnit
+
+Test-suite cached
+ Hs-Source-Dirs: Test, .
+ Main-Is: TestCached.hs
+ Type: exitcode-stdio-1.0
+
+ Build-Depends: base >= 4 && < 5, bytestring, containers, HTTP, mmap, network
+ Ghc-Options: -Wall -threaded
+
+ Build-Depends: test-framework, test-framework-hunit, HUnit
Please sign in to comment.
Something went wrong with that request. Please try again.