summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-16 22:26:12 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-16 22:26:12 +0400
commit98b0f21793f947c0babfc3c6bb97f3c27a4c3f24 (patch)
treec3ed50afbfeb95a58b9360b4ed5cb3fb7f19b4d3 /tests/Network/BitTorrent
parent494480ae28a8fc2a6dc399127ffa9b8374e6c92b (diff)
Add skeleton of DHT spec
Diffstat (limited to 'tests/Network/BitTorrent')
-rw-r--r--tests/Network/BitTorrent/DHTSpec.hs62
1 files changed, 62 insertions, 0 deletions
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