From ecd1dcc059e45e6ff8df1869b1fb7f5b3dea3837 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Thu, 27 Feb 2014 14:47:10 +0400 Subject: Add spec for RPC.UDP.closeManager --- tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs | 32 ++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'tests/Network/BitTorrent/Tracker/RPC') 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 @@ {-# LANGUAGE RecordWildCards #-} module Network.BitTorrent.Tracker.RPC.UDPSpec (spec, rpcOpts) where +import Control.Concurrent import Control.Concurrent.Async import Control.Exception import Control.Monad @@ -44,6 +45,9 @@ isTimeoutExpired _ = False isSomeException :: SomeException -> Bool isSomeException _ = True +isIOException :: IOException -> Bool +isIOException _ = True + spec :: Spec spec = parallel $ do describe "newManager" $ do @@ -67,7 +71,33 @@ spec = parallel $ do let opts = def { optMultiplier = 0 } newManager opts `shouldThrow` isSomeException - forM_ (L.filter isUdpTracker trackers) $ \ TrackerEntry {..} -> + describe "closeManager" $ do + it "unblock rpc calls" $ do + mgr <- newManager rpcOpts + _ <- forkIO $ do + threadDelay 10000000 + closeManager mgr + q <- arbitrarySample + announce mgr (trackerURI badTracker) q `shouldThrow` (== ManagerClosed) + + it "announce throw exception after manager closed" $ do + mgr <- newManager rpcOpts + closeManager mgr + q <- arbitrarySample + announce mgr (trackerURI badTracker) q `shouldThrow` isIOException + + it "scrape throw exception after manager closed" $ do + mgr <- newManager rpcOpts + closeManager mgr + scrape mgr (trackerURI badTracker) [def] `shouldThrow` isIOException + + describe "withManager" $ do + it "closesManager at exit" $ do + mgr <- withManager rpcOpts return + scrape mgr (trackerURI badTracker) [def] `shouldThrow` isSomeException + + describe "RPC" $ do + forM_ (L.filter isUdpTracker trackers) $ \ TrackerEntry {..} -> context trackerName $ do describe "announce" $ do -- cgit v1.2.3