From 12cbb3af2413dc28838ed271351dda16df8f7bdb Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 15 Sep 2017 06:22:10 -0400 Subject: Separating dht-client library from bittorrent package. --- bittorrent/tests/Network/BitTorrent/DHTSpec.hs | 60 ++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 bittorrent/tests/Network/BitTorrent/DHTSpec.hs (limited to 'bittorrent/tests/Network/BitTorrent/DHTSpec.hs') diff --git a/bittorrent/tests/Network/BitTorrent/DHTSpec.hs b/bittorrent/tests/Network/BitTorrent/DHTSpec.hs new file mode 100644 index 00000000..77160eb5 --- /dev/null +++ b/bittorrent/tests/Network/BitTorrent/DHTSpec.hs @@ -0,0 +1,60 @@ +module Network.BitTorrent.DHTSpec (spec) where +import Control.Exception +import Control.Monad +import Data.Default +import Data.List as L +import Test.Hspec +import System.Timeout + +import Data.Torrent +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 opts def fullLogging $ do + bootstrap Nothing [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 () -- cgit v1.2.3