packages feed

lifted-async 0.5.0 → 0.5.0.1

raw patch · 3 files changed

+131/−2 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+## v0.5.0.1 - 2014-12-29++* Fix build issues in the test suite (#11 and others)+ ## v0.5.0 - 2014-12-29  * Simplify the type of `Concurrently` (#10)
lifted-async.cabal view
@@ -1,5 +1,5 @@ name:                lifted-async-version:             0.5.0+version:             0.5.0.1 synopsis:            Run lifted IO operations asynchronously and wait for their results homepage:            https://github.com/maoe/lifted-async bug-reports:         https://github.com/maoe/lifted-async/issues@@ -52,6 +52,7 @@     Test.Async.Common     Test.Async.IO     Test.Async.State+    Test.Async.Reader   build-depends:       base     , HUnit@@ -107,5 +108,5 @@  source-repository this   type: git-  tag: v0.5.0+  tag: v0.5.0.1   location: https://github.com/maoe/lifted-async.git
+ tests/Test/Async/Reader.hs view
@@ -0,0 +1,124 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE TemplateHaskell #-}+module Test.Async.Reader+  ( readerTestGroup+  ) where+import Control.Monad.Reader+import Data.Maybe (isJust, isNothing)++import Control.Concurrent.Lifted+import Control.Exception.Lifted as E++#if MIN_VERSION_monad_control(1, 0, 0)+import Control.Concurrent.Async.Lifted.Safe+#else+import Control.Concurrent.Async.Lifted+#endif+import Test.Async.Common++readerTestGroup :: TestTree+readerTestGroup = $(testGroupGenerator)++case_async_waitCatch :: Assertion+case_async_waitCatch = do+  r <- flip runReaderT value $ do+    a <- async $ return value+    waitCatch a+  case r of+    Left _  -> assertFailure "An exception must not be raised."+    Right e -> do+      e @?= value++case_async_wait :: Assertion+case_async_wait = do+  r <- flip runReaderT value $ do+    a <- async $ return value+    wait a+  r @?= value++case_async_exwaitCatch :: Assertion+case_async_exwaitCatch = do+  r <- flip runReaderT value $ do+    a <- async $ throwIO TestException+    waitCatch a+  case r of+    Left e ->+      fromException e @?= Just TestException+    Right _ -> assertFailure "An exception must be raised."++case_async_exwait :: Assertion+case_async_exwait =+  void $ flip runReaderT value $ do+    a <- async $ throwIO TestException+    (wait a >> liftIO (assertFailure "An exception must be raised"))+      `E.catch` \e ->+        liftIO $ e @?= TestException++case_withAsync_waitCatch :: Assertion+case_withAsync_waitCatch =+  void $ flip runReaderT value $ do+    withAsync (return value) $ \a -> do+      r <- waitCatch a+      case r of+        Left _  -> liftIO $ assertFailure "An exception must not be raised."+        Right e -> do+          liftIO $ e @?= value++case_withAsync_wait2 :: Assertion+case_withAsync_wait2 = do+  r <- flip runReaderT value $ do+    a <- withAsync (threadDelay 1000000) $ return+    waitCatch a+  case r of+    Left e  -> do+      fromException e @?= Just ThreadKilled+    Right _ -> assertFailure "An exception must be raised."++case_async_cancel :: Assertion+case_async_cancel = sequence_ $ replicate 1000 run+  where+    run = do+      r <- flip runReaderT value $ do+        a <- async $ return value+        cancelWith a TestException+        waitCatch a+      case r of+        Left e ->+          fromException e @?= Just TestException+        Right r' ->+          r' @?= value++case_async_poll :: Assertion+case_async_poll =+  void $ flip runReaderT value $ do+    a <- async (threadDelay 1000000)+    r <- poll a+    when (isJust r) $+      liftIO $ assertFailure "The result must be nothing."+    r' <- poll a   -- poll twice, just to check we don't deadlock+    when (isJust r') $+      liftIO $ assertFailure "The result must be Nothing."++case_async_poll2 :: Assertion+case_async_poll2 =+  void $ flip runReaderT value $ do+    a <- async (return value)+    void $ wait a+    r <- poll a+    when (isNothing r) $+      liftIO $ assertFailure "The result must not be Nothing."+    r' <- poll a   -- poll twice, just to check we don't deadlock+    when (isNothing r') $+      liftIO $ assertFailure "The result must not be Nothing."++case_link :: Assertion+case_link = do+  r <- try $ flip runReaderT value $ do+    a <- async $ threadDelay 1000000 >> return value+    link a+    cancelWith a TestException+    wait a+  case r of+    Left e -> do+      fromException e @?= Just TestException+    Right _ -> assertFailure "An exception must be raised."