diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-27 14:47:10 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-27 14:47:10 +0400 |
commit | ecd1dcc059e45e6ff8df1869b1fb7f5b3dea3837 (patch) | |
tree | b3653908d8331a80bf57aaf393c4469a950e22bb /tests/Network | |
parent | f48b30127efbbeeb30a1fdd6e202fc52e1ee6e3a (diff) |
Add spec for RPC.UDP.closeManager
Diffstat (limited to 'tests/Network')
-rw-r--r-- | tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs | 32 | ||||
-rw-r--r-- | tests/Network/BitTorrent/Tracker/TestData.hs | 4 |
2 files changed, 35 insertions, 1 deletions
diff --git a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs index bfe0c92f..c406aabd 100644 --- a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs +++ b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs | |||
@@ -1,5 +1,6 @@ | |||
1 | {-# LANGUAGE RecordWildCards #-} | 1 | {-# LANGUAGE RecordWildCards #-} |
2 | module Network.BitTorrent.Tracker.RPC.UDPSpec (spec, rpcOpts) where | 2 | module Network.BitTorrent.Tracker.RPC.UDPSpec (spec, rpcOpts) where |
3 | import Control.Concurrent | ||
3 | import Control.Concurrent.Async | 4 | import Control.Concurrent.Async |
4 | import Control.Exception | 5 | import Control.Exception |
5 | import Control.Monad | 6 | import Control.Monad |
@@ -44,6 +45,9 @@ isTimeoutExpired _ = False | |||
44 | isSomeException :: SomeException -> Bool | 45 | isSomeException :: SomeException -> Bool |
45 | isSomeException _ = True | 46 | isSomeException _ = True |
46 | 47 | ||
48 | isIOException :: IOException -> Bool | ||
49 | isIOException _ = True | ||
50 | |||
47 | spec :: Spec | 51 | spec :: Spec |
48 | spec = parallel $ do | 52 | spec = parallel $ do |
49 | describe "newManager" $ do | 53 | describe "newManager" $ do |
@@ -67,7 +71,33 @@ spec = parallel $ do | |||
67 | let opts = def { optMultiplier = 0 } | 71 | let opts = def { optMultiplier = 0 } |
68 | newManager opts `shouldThrow` isSomeException | 72 | newManager opts `shouldThrow` isSomeException |
69 | 73 | ||
70 | forM_ (L.filter isUdpTracker trackers) $ \ TrackerEntry {..} -> | 74 | describe "closeManager" $ do |
75 | it "unblock rpc calls" $ do | ||
76 | mgr <- newManager rpcOpts | ||
77 | _ <- forkIO $ do | ||
78 | threadDelay 10000000 | ||
79 | closeManager mgr | ||
80 | q <- arbitrarySample | ||
81 | announce mgr (trackerURI badTracker) q `shouldThrow` (== ManagerClosed) | ||
82 | |||
83 | it "announce throw exception after manager closed" $ do | ||
84 | mgr <- newManager rpcOpts | ||
85 | closeManager mgr | ||
86 | q <- arbitrarySample | ||
87 | announce mgr (trackerURI badTracker) q `shouldThrow` isIOException | ||
88 | |||
89 | it "scrape throw exception after manager closed" $ do | ||
90 | mgr <- newManager rpcOpts | ||
91 | closeManager mgr | ||
92 | scrape mgr (trackerURI badTracker) [def] `shouldThrow` isIOException | ||
93 | |||
94 | describe "withManager" $ do | ||
95 | it "closesManager at exit" $ do | ||
96 | mgr <- withManager rpcOpts return | ||
97 | scrape mgr (trackerURI badTracker) [def] `shouldThrow` isSomeException | ||
98 | |||
99 | describe "RPC" $ do | ||
100 | forM_ (L.filter isUdpTracker trackers) $ \ TrackerEntry {..} -> | ||
71 | context trackerName $ do | 101 | context trackerName $ do |
72 | 102 | ||
73 | describe "announce" $ do | 103 | describe "announce" $ do |
diff --git a/tests/Network/BitTorrent/Tracker/TestData.hs b/tests/Network/BitTorrent/Tracker/TestData.hs index 22077e90..bfb1bff0 100644 --- a/tests/Network/BitTorrent/Tracker/TestData.hs +++ b/tests/Network/BitTorrent/Tracker/TestData.hs | |||
@@ -5,6 +5,7 @@ module Network.BitTorrent.Tracker.TestData | |||
5 | , isUdpTracker | 5 | , isUdpTracker |
6 | , isHttpTracker | 6 | , isHttpTracker |
7 | , trackers | 7 | , trackers |
8 | , badTracker | ||
8 | ) where | 9 | ) where |
9 | 10 | ||
10 | import Data.Maybe | 11 | import Data.Maybe |
@@ -83,3 +84,6 @@ trackers = | |||
83 | , notWorking "OpenBitTorrent" "http://tracker.openbittorrent.com:80/announce" | 84 | , notWorking "OpenBitTorrent" "http://tracker.openbittorrent.com:80/announce" |
84 | , notWorking "PublicBT" "http://tracker.publicbt.com:80/announce" | 85 | , notWorking "PublicBT" "http://tracker.publicbt.com:80/announce" |
85 | ] | 86 | ] |
87 | |||
88 | badTracker :: TrackerEntry | ||
89 | badTracker = notWorking "rarbg" "udp://9.rarbg.com:2710/announce" \ No newline at end of file | ||