diff options
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 6 | ||||
-rw-r--r-- | tests/Network/BitTorrent/DHT/SessionSpec.hs | 12 |
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. | ||
269 | instance 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'. |
268 | instance MonadResource (DHT ip) where | 274 | instance 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 #-} |
2 | module Network.BitTorrent.DHT.SessionSpec (spec) where | 2 | module Network.BitTorrent.DHT.SessionSpec (spec) where |
3 | import Control.Monad.Reader | 3 | import Control.Monad.Reader |
4 | import Control.Monad.Trans.Resource | ||
4 | import Data.Default | 5 | import Data.Default |
5 | import Data.List as L | 6 | import Data.List as L |
6 | import Test.Hspec | 7 | import Test.Hspec |
@@ -29,8 +30,19 @@ isRight (Right _) = True | |||
29 | isLeft :: Either a b -> Bool | 30 | isLeft :: Either a b -> Bool |
30 | isLeft = not . isRight | 31 | isLeft = not . isRight |
31 | 32 | ||
33 | nullLogger :: LogFun | ||
34 | nullLogger _ _ _ _ = return () | ||
35 | |||
32 | spec :: Spec | 36 | spec :: Spec |
33 | spec = do | 37 | spec = 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 |