summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs32
-rw-r--r--tests/Network/BitTorrent/Tracker/TestData.hs4
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 #-}
2module Network.BitTorrent.Tracker.RPC.UDPSpec (spec, rpcOpts) where 2module Network.BitTorrent.Tracker.RPC.UDPSpec (spec, rpcOpts) where
3import Control.Concurrent
3import Control.Concurrent.Async 4import Control.Concurrent.Async
4import Control.Exception 5import Control.Exception
5import Control.Monad 6import Control.Monad
@@ -44,6 +45,9 @@ isTimeoutExpired _ = False
44isSomeException :: SomeException -> Bool 45isSomeException :: SomeException -> Bool
45isSomeException _ = True 46isSomeException _ = True
46 47
48isIOException :: IOException -> Bool
49isIOException _ = True
50
47spec :: Spec 51spec :: Spec
48spec = parallel $ do 52spec = 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
10import Data.Maybe 11import 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
88badTracker :: TrackerEntry
89badTracker = notWorking "rarbg" "udp://9.rarbg.com:2710/announce" \ No newline at end of file