summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Tracker/RPC
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Network/BitTorrent/Tracker/RPC')
-rw-r--r--tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs32
1 files changed, 31 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