Skip to content
Snippets Groups Projects
Commit 8b263600 authored by Jens Nolte's avatar Jens Nolte
Browse files

Add more tests

parent c0372cc5
No related branches found
No related tags found
No related merge requests found
......@@ -273,7 +273,8 @@ collectGarbage resourceManager = go >> traceIO "gc: completed"
traceIO "gc: change detected"
-- Check entries for completion. Completion will be queried with `entryIsEmpty` during the next STM transaction.
-- Checking entries for completion has to be done in IO.
-- Completion is then queried with `entryIsEmpty` during the following STM transaction.
checkEntries =<< atomically (readTVar entriesVar')
traceIO "gc: entries checked"
......
module Quasar.DisposableSpec (spec) where
import Control.Exception
import Control.Concurrent
import Control.Monad (void)
import Prelude
......@@ -7,6 +8,11 @@ import Test.Hspec
import Quasar.Awaitable
import Quasar.Disposable
data TestException = TestException
deriving (Eq, Show)
instance Exception TestException
spec :: Spec
spec = parallel $ do
describe "Disposable" $ do
......@@ -36,6 +42,13 @@ spec = parallel $ do
withResourceManager \resourceManager -> do
attachDisposable resourceManager noDisposable
it "can attach an disposable" $ do
withResourceManager \resourceManager -> do
avar <- newAsyncVar :: IO (AsyncVar ())
attachDisposable resourceManager $ alreadyDisposing avar
putAsyncVar_ avar ()
pure () :: IO ()
it "can dispose an awaitable that is completed asynchronously" $ do
avar <- newAsyncVar :: IO (AsyncVar ())
void $ forkIO $ do
......@@ -44,3 +57,21 @@ spec = parallel $ do
withResourceManager \resourceManager -> do
attachDisposable resourceManager (alreadyDisposing avar)
it "can call a trivial dispose action" $ do
withResourceManager \resourceManager ->
attachDisposeAction resourceManager $ pure $ pure ()
pure () :: IO ()
it "can call a dispose action" $ do
withResourceManager \resourceManager -> do
avar <- newAsyncVar :: IO (AsyncVar ())
attachDisposeAction resourceManager $ toAwaitable avar <$ putAsyncVar_ avar ()
pure () :: IO ()
it "re-throws an exception from a dispose action" $ do
shouldThrow
do
withResourceManager \resourceManager ->
attachDisposeAction resourceManager $ throwIO $ TestException
\TestException -> True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment