summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs6
-rw-r--r--tests/Network/BitTorrent/DHT/SessionSpec.hs12
2 files changed, 18 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs
index 75d3294f..a452b764 100644
--- a/src/Network/BitTorrent/DHT/Session.hs
+++ b/src/Network/BitTorrent/DHT/Session.hs
@@ -264,6 +264,12 @@ instance MonadBaseControl IO (DHT ip) where
264 restoreM = DHT . restoreM . unSt 264 restoreM = DHT . restoreM . unSt
265 {-# INLINE restoreM #-} 265 {-# INLINE restoreM #-}
266 266
267-- | Check is it is possible to run 'queryNode' or handle pending
268-- query from remote node.
269instance MonadActive (DHT ip) where
270 monadActive = getManager >>= liftIO . isActive
271 {-# INLINE monadActive #-}
272
267-- | All allocated resources will be closed at 'stopNode'. 273-- | All allocated resources will be closed at 'stopNode'.
268instance MonadResource (DHT ip) where 274instance MonadResource (DHT ip) where
269 liftResourceT m = do 275 liftResourceT m = do
diff --git a/tests/Network/BitTorrent/DHT/SessionSpec.hs b/tests/Network/BitTorrent/DHT/SessionSpec.hs
index 381aa77d..343c8ab6 100644
--- a/tests/Network/BitTorrent/DHT/SessionSpec.hs
+++ b/tests/Network/BitTorrent/DHT/SessionSpec.hs
@@ -1,6 +1,7 @@
1{-# LANGUAGE ScopedTypeVariables #-} 1{-# LANGUAGE ScopedTypeVariables #-}
2module Network.BitTorrent.DHT.SessionSpec (spec) where 2module Network.BitTorrent.DHT.SessionSpec (spec) where
3import Control.Monad.Reader 3import Control.Monad.Reader
4import Control.Monad.Trans.Resource
4import Data.Default 5import Data.Default
5import Data.List as L 6import Data.List as L
6import Test.Hspec 7import Test.Hspec
@@ -29,8 +30,19 @@ isRight (Right _) = True
29isLeft :: Either a b -> Bool 30isLeft :: Either a b -> Bool
30isLeft = not . isRight 31isLeft = not . isRight
31 32
33nullLogger :: LogFun
34nullLogger _ _ _ _ = return ()
35
32spec :: Spec 36spec :: Spec
33spec = do 37spec = do
38 describe "session" $ do
39 it "is active until stopNode called" $ do
40 node <- startNode [] def myAddr nullLogger
41 runDHT node monadActive `shouldReturn` True
42 runDHT node monadActive `shouldReturn` True
43 stopNode node
44 runDHT node monadActive `shouldReturn` False
45
34 describe "tokens" $ do 46 describe "tokens" $ do
35 it "should not complain about valid token" $ 47 it "should not complain about valid token" $
36 property $ \ (addrs :: [NodeAddr IPv4]) -> do 48 property $ \ (addrs :: [NodeAddr IPv4]) -> do