diff options
Diffstat (limited to 'tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs')
-rw-r--r-- | tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs | 32 |
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 #-} |
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 |