From 98b0f21793f947c0babfc3c6bb97f3c27a4c3f24 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sun, 16 Feb 2014 22:26:12 +0400 Subject: Add skeleton of DHT spec --- tests/Network/BitTorrent/DHTSpec.hs | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/Network/BitTorrent/DHTSpec.hs (limited to 'tests/Network/BitTorrent') diff --git a/tests/Network/BitTorrent/DHTSpec.hs b/tests/Network/BitTorrent/DHTSpec.hs new file mode 100644 index 00000000..a8248be2 --- /dev/null +++ b/tests/Network/BitTorrent/DHTSpec.hs @@ -0,0 +1,62 @@ +module Network.BitTorrent.DHTSpec (spec) where +import Control.Exception +import Control.Monad +import Data.Default +import Data.List as L +import Test.Hspec +import Test.QuickCheck +import System.Timeout + +import Data.Torrent.InfoHash +import Network.BitTorrent.Core +import Network.BitTorrent.DHT + + +partialBootstrapTimeout :: Int +partialBootstrapTimeout = 10 * 1000000 + +opts :: Options +opts = def { optBucketCount = 1 } + +-- NOTE to shorten test cases run time include only "good" infohashes +-- with many nodes +existingInfoHashes :: [InfoHash] +existingInfoHashes = + [ + ] + +-- TODO use Test.Hspec.parallel + +spec :: Spec +spec = do + describe "bootstrapping" $ do + it "should resolve all default bootstrap nodes" $ do + nodes <- forM defaultBootstrapNodes resolveHostName + _ <- evaluate nodes + return () + + it "partial bootstrapping should finish in less than 10 seconds" $ do + node <- resolveHostName (L.head defaultBootstrapNodes) + res <- timeout partialBootstrapTimeout $ do + dht def def $ do + bootstrap [node] + isBootstrapped + res `shouldBe` Just True + + describe "initialization" $ do + it "should be bootstrapped after restore process" $ do + pending + + describe "lookup" $ do + describe "for any existing infohash" $ do + forM_ existingInfoHashes $ \ ih -> do + context (show ih) $ do + it "should find peers" $ do + pending + + describe "insert" $ do + it "should return this peer if announced" $ do + pending + + describe "delete" $ do + return () \ No newline at end of file -- cgit v1.2.3