summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--tests/Main.hs2
-rw-r--r--tests/Network/BitTorrent/DHT/MessageSpec.hs17
3 files changed, 19 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 851c60cc..2880dc7b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,4 @@ upload-docs
11*.pdf 11*.pdf
12*.ps 12*.ps
13*.prof 13*.prof
14res/rtorrent-sessiondir
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"