summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2014-01-04 04:10:15 +0000
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-04 21:40:49 +0400
commitc3bcc1e84f7f7f49de1fcd75e589ed4099bff2ea (patch)
tree3fd05798c427b52ca25a0b8be33e4ea5c50d5100 /tests
parentbc732f562d82fcfacfff277c0e5c39c742eb2920 (diff)
Test against rtorrent's dht server when enabled
Diffstat (limited to 'tests')
-rw-r--r--tests/Main.hs2
-rw-r--r--tests/Network/BitTorrent/DHT/MessageSpec.hs17
2 files changed, 18 insertions, 1 deletions
diff --git a/tests/Main.hs b/tests/Main.hs
index 32ee3992..63281cf3 100644
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -12,7 +12,7 @@ import Data.Functor
12 12
13clients :: [(String, String)] 13clients :: [(String, String)]
14clients = [ 14clients = [
15 ("rtorrent","rtorrent -p 51234-51234 testfile.torrent") ] 15 ("rtorrent","rtorrent -p 51234-51234 -O dht=on -O dht_port=6881 -O session=rtorrent-sessiondir testfile.torrent") ]
16 16
17main :: IO () 17main :: IO ()
18main = do 18main = do
diff --git a/tests/Network/BitTorrent/DHT/MessageSpec.hs b/tests/Network/BitTorrent/DHT/MessageSpec.hs
index ce2ac0de..af694470 100644
--- a/tests/Network/BitTorrent/DHT/MessageSpec.hs
+++ b/tests/Network/BitTorrent/DHT/MessageSpec.hs
@@ -1,6 +1,7 @@
1{-# LANGUAGE RecordWildCards #-} 1{-# LANGUAGE RecordWildCards #-}
2module Network.BitTorrent.DHT.MessageSpec (spec) where 2module Network.BitTorrent.DHT.MessageSpec (spec) where
3import Control.Monad.Reader 3import Control.Monad.Reader
4import Control.Concurrent
4import Data.BEncode as BE 5import Data.BEncode as BE
5import Data.ByteString.Lazy as BL 6import Data.ByteString.Lazy as BL
6import Data.Default 7import Data.Default
@@ -11,6 +12,7 @@ import Network.KRPC
11import Network.Socket (PortNumber) 12import Network.Socket (PortNumber)
12import Test.Hspec 13import Test.Hspec
13import Test.QuickCheck 14import Test.QuickCheck
15import System.Timeout
14 16
15import Network.BitTorrent.CoreSpec () 17import Network.BitTorrent.CoreSpec ()
16import Network.BitTorrent.DHT.TokenSpec () 18import Network.BitTorrent.DHT.TokenSpec ()
@@ -37,9 +39,24 @@ isProtocolError KError {..} = errorCode == ProtocolError
37prop_bencode :: Eq a => Show a => BEncode a => a -> Expectation 39prop_bencode :: Eq a => Show a => BEncode a => a -> Expectation
38prop_bencode x = BE.decode (BL.toStrict (BE.encode x)) `shouldBe` Right x 40prop_bencode x = BE.decode (BL.toStrict (BE.encode x)) `shouldBe` Right x
39 41
42retry :: Int -> IO (Maybe a) -> IO (Maybe a)
43retry 0 _ = return Nothing
44retry n a = do
45 res <- a
46 case res of
47 Just _ -> return res
48 Nothing -> threadDelay (100 * 1000) >> retry (n-1) a
49
40spec :: Spec 50spec :: Spec
41spec = do 51spec = do
42 context ("you need running DHT node at " ++ show remoteAddr) $ do 52 context ("you need running DHT node at " ++ show remoteAddr) $ do
53 it "is running" $ do
54 _ <- retry 5 $ timeout (100 * 1000) $ do
55 nid <- genNodeId
56 Response _remoteAddr Ping <-
57 rpc (query remoteAddr (Query nid Ping))
58 return ()
59 return ()
43 describe "ping" $ do 60 describe "ping" $ do
44 it "properly bencoded" $ do 61 it "properly bencoded" $ do
45 BE.decode "d2:id20:abcdefghij0123456789e" 62 BE.decode "d2:id20:abcdefghij0123456789e"