diff options
author | joe <joe@jerkface.net> | 2017-09-15 06:22:10 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-09-15 06:22:10 -0400 |
commit | 12cbb3af2413dc28838ed271351dda16df8f7bdb (patch) | |
tree | 2db77a787e18a81a8369a8d73fee369d8826f064 /bittorrent/tests/Network/BitTorrent/DHTSpec.hs | |
parent | 362357c6d08cbd8dffa627a1e80199dcb9ba231f (diff) |
Separating dht-client library from bittorrent package.
Diffstat (limited to 'bittorrent/tests/Network/BitTorrent/DHTSpec.hs')
-rw-r--r-- | bittorrent/tests/Network/BitTorrent/DHTSpec.hs | 60 |
1 files changed, 60 insertions, 0 deletions
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 @@ | |||
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 System.Timeout | ||
8 | |||
9 | import Data.Torrent | ||
10 | import Network.BitTorrent.DHT | ||
11 | |||
12 | |||
13 | partialBootstrapTimeout :: Int | ||
14 | partialBootstrapTimeout = 10 * 1000000 | ||
15 | |||
16 | opts :: Options | ||
17 | opts = def { optBucketCount = 1 } | ||
18 | |||
19 | -- NOTE to shorten test cases run time include only "good" infohashes | ||
20 | -- with many nodes | ||
21 | existingInfoHashes :: [InfoHash] | ||
22 | existingInfoHashes = | ||
23 | [ | ||
24 | ] | ||
25 | |||
26 | -- TODO use Test.Hspec.parallel | ||
27 | |||
28 | spec :: Spec | ||
29 | spec = do | ||
30 | describe "bootstrapping" $ do | ||
31 | it "should resolve all default bootstrap nodes" $ do | ||
32 | nodes <- forM defaultBootstrapNodes resolveHostName | ||
33 | _ <- evaluate nodes | ||
34 | return () | ||
35 | |||
36 | it "partial bootstrapping should finish in less than 10 seconds" $ do | ||
37 | node <- resolveHostName (L.head defaultBootstrapNodes) | ||
38 | res <- timeout partialBootstrapTimeout $ do | ||
39 | dht opts def fullLogging $ do | ||
40 | bootstrap Nothing [node] | ||
41 | isBootstrapped | ||
42 | res `shouldBe` Just True | ||
43 | |||
44 | describe "initialization" $ do | ||
45 | it "should be bootstrapped after restore process" $ do | ||
46 | pending | ||
47 | |||
48 | describe "lookup" $ do | ||
49 | describe "for any existing infohash" $ do | ||
50 | forM_ existingInfoHashes $ \ ih -> do | ||
51 | context (show ih) $ do | ||
52 | it "should find peers" $ do | ||
53 | pending | ||
54 | |||
55 | describe "insert" $ do | ||
56 | it "should return this peer if announced" $ do | ||
57 | pending | ||
58 | |||
59 | describe "delete" $ do | ||
60 | return () | ||