summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bittorrent.cabal1
-rw-r--r--tests/Network/BitTorrent/DHTSpec.hs62
2 files changed, 63 insertions, 0 deletions
diff --git a/bittorrent.cabal b/bittorrent.cabal
index e517f582..8cf045e7 100644
--- a/bittorrent.cabal
+++ b/bittorrent.cabal
@@ -192,6 +192,7 @@ test-suite spec
192 Network.BitTorrent.Core.NodeInfoSpec 192 Network.BitTorrent.Core.NodeInfoSpec
193 Network.BitTorrent.Core.PeerAddrSpec 193 Network.BitTorrent.Core.PeerAddrSpec
194 Network.BitTorrent.Core.PeerIdSpec 194 Network.BitTorrent.Core.PeerIdSpec
195 Network.BitTorrent.DHTSpec
195 Network.BitTorrent.DHT.MessageSpec 196 Network.BitTorrent.DHT.MessageSpec
196 Network.BitTorrent.DHT.RoutingSpec 197 Network.BitTorrent.DHT.RoutingSpec
197 Network.BitTorrent.DHT.TokenSpec 198 Network.BitTorrent.DHT.TokenSpec
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 @@
1module Network.BitTorrent.DHTSpec (spec) where
2import Control.Exception
3import Control.Monad
4import Data.Default
5import Data.List as L
6import Test.Hspec
7import Test.QuickCheck
8import System.Timeout
9
10import Data.Torrent.InfoHash
11import Network.BitTorrent.Core
12import Network.BitTorrent.DHT
13
14
15partialBootstrapTimeout :: Int
16partialBootstrapTimeout = 10 * 1000000
17
18opts :: Options
19opts = def { optBucketCount = 1 }
20
21-- NOTE to shorten test cases run time include only "good" infohashes
22-- with many nodes
23existingInfoHashes :: [InfoHash]
24existingInfoHashes =
25 [
26 ]
27
28-- TODO use Test.Hspec.parallel
29
30spec :: Spec
31spec = do
32 describe "bootstrapping" $ do
33 it "should resolve all default bootstrap nodes" $ do
34 nodes <- forM defaultBootstrapNodes resolveHostName
35 _ <- evaluate nodes
36 return ()
37
38 it "partial bootstrapping should finish in less than 10 seconds" $ do
39 node <- resolveHostName (L.head defaultBootstrapNodes)
40 res <- timeout partialBootstrapTimeout $ do
41 dht def def $ do
42 bootstrap [node]
43 isBootstrapped
44 res `shouldBe` Just True
45
46 describe "initialization" $ do
47 it "should be bootstrapped after restore process" $ do
48 pending
49
50 describe "lookup" $ do
51 describe "for any existing infohash" $ do
52 forM_ existingInfoHashes $ \ ih -> do
53 context (show ih) $ do
54 it "should find peers" $ do
55 pending
56
57 describe "insert" $ do
58 it "should return this peer if announced" $ do
59 pending
60
61 describe "delete" $ do
62 return () \ No newline at end of file