diff options
-rw-r--r-- | bittorrent.cabal | 1 | ||||
-rw-r--r-- | tests/Network/BitTorrent/DHTSpec.hs | 62 |
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 @@ | |||
1 | module Network.BitTorrent.DHTSpec (spec) where | ||
2 | import Control.Exception | ||
3 | import Control.Monad | ||
4 | import Data.Default | ||
5 | import Data.List as L | ||
6 | import Test.Hspec | ||
7 | import Test.QuickCheck | ||
8 | import System.Timeout | ||
9 | |||
10 | import Data.Torrent.InfoHash | ||
11 | import Network.BitTorrent.Core | ||
12 | import Network.BitTorrent.DHT | ||
13 | |||
14 | |||
15 | partialBootstrapTimeout :: Int | ||
16 | partialBootstrapTimeout = 10 * 1000000 | ||
17 | |||
18 | opts :: Options | ||
19 | opts = def { optBucketCount = 1 } | ||
20 | |||
21 | -- NOTE to shorten test cases run time include only "good" infohashes | ||
22 | -- with many nodes | ||
23 | existingInfoHashes :: [InfoHash] | ||
24 | existingInfoHashes = | ||
25 | [ | ||
26 | ] | ||
27 | |||
28 | -- TODO use Test.Hspec.parallel | ||
29 | |||
30 | spec :: Spec | ||
31 | spec = 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 | ||