From fa01c6b1b3918b5dc68933ad18a7ce930788338b Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Wed, 26 Feb 2014 16:50:33 +0400 Subject: Test TimeoutExpired exceptions --- tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs | 16 +++++++++++----- tests/Network/BitTorrent/Tracker/TestData.hs | 6 +++++- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'tests/Network/BitTorrent/Tracker') diff --git a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs index 57680a5b..acc60e09 100644 --- a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs +++ b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs @@ -36,6 +36,10 @@ rpcOpts = def , optMaxTimeout = 10 } +isTimeoutExpired :: RpcException -> Bool +isTimeoutExpired (TimeoutExpired _) = True +isTimeoutExpired _ = False + spec :: Spec spec = parallel $ do forM_ (L.filter isUdpTracker trackers) $ \ TrackerEntry {..} -> @@ -48,8 +52,10 @@ spec = parallel $ do q <- arbitrarySample announce mgr trackerURI q >>= validateInfo q else do - it "should throw TrackerNotResponding" $ do - pending + it "should throw TimeoutExpired" $ do + withManager rpcOpts $ \ mgr -> do + q <- arbitrarySample + announce mgr trackerURI q `shouldThrow` isTimeoutExpired describe "scrape" $ do if tryScraping then do @@ -58,9 +64,9 @@ spec = parallel $ do xs <- scrape mgr trackerURI [def] L.length xs `shouldSatisfy` (>= 1) else do - it "should throw TrackerNotResponding" $ do - pending - + it "should throw TimeoutExpired" $ do + withManager rpcOpts $ \ mgr -> do + scrape mgr trackerURI [def] `shouldThrow` isTimeoutExpired describe "Manager" $ do when tryScraping $ do diff --git a/tests/Network/BitTorrent/Tracker/TestData.hs b/tests/Network/BitTorrent/Tracker/TestData.hs index 85544b91..22077e90 100644 --- a/tests/Network/BitTorrent/Tracker/TestData.hs +++ b/tests/Network/BitTorrent/Tracker/TestData.hs @@ -72,7 +72,11 @@ notWorking name uri = (trackerEntry uri) trackers :: [TrackerEntry] trackers = [ announceOnly "LinuxTracker" - "http://linuxtracker.org:2710/00000000000000000000000000000000/announce" + "http://linuxtracker.org:2710/00000000000000000000000000000000/announce" + + -- from "http://www.linux23.com/" + , announceScrape "Arch" "http://tracker.archlinux.org:6969/announce" + , notWorking "rarbg" "udp://9.rarbg.com:2710/announce" , announceScrape "OpenBitTorrent" "udp://tracker.openbittorrent.com:80/announce" , announceScrape "PublicBT" "udp://tracker.publicbt.com:80/announce" -- cgit v1.2.3