Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quasar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
quasar
Commits
0fc8d6c6
Commit
0fc8d6c6
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add test for withRootResourceManager to ensure no exceptions are lost
parent
3b316a1b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Quasar/ResourceManager.hs
+9
-6
9 additions, 6 deletions
src/Quasar/ResourceManager.hs
test/Quasar/ResourceManagerSpec.hs
+9
-0
9 additions, 0 deletions
test/Quasar/ResourceManagerSpec.hs
with
18 additions
and
6 deletions
src/Quasar/ResourceManager.hs
+
9
−
6
View file @
0fc8d6c6
...
...
@@ -22,6 +22,7 @@ module Quasar.ResourceManager (
-- ** Initialization
CombinedException
,
combinedExceptions
,
withRootResourceManager
,
-- ** Linking computations to a resource manager
...
...
@@ -40,8 +41,7 @@ import Control.Monad.Catch
import
Control.Monad.Reader
import
Data.Foldable
(
toList
)
import
Data.List.NonEmpty
(
NonEmpty
(
..
),
nonEmpty
)
import
Data.List.NonEmpty
qualified
as
NonEmpty
import
Data.Sequence
import
Data.Sequence
(
Seq
(
..
),
(
|>
))
import
Data.Sequence
qualified
as
Seq
import
Quasar.Awaitable
import
Quasar.Disposable
...
...
@@ -240,9 +240,12 @@ newtype CombinedException = CombinedException (NonEmpty SomeException)
instance
Exception
CombinedException
where
displayException
(
CombinedException
exceptions
)
=
intercalate
"
\n
"
(
header
:
exceptionMessages
)
where
header
=
mconcat
[
"CombinedException with "
,
show
(
NonEmpty
.
length
exceptions
),
"exceptions:"
]
header
=
mconcat
[
"CombinedException with "
,
show
(
length
exceptions
),
"exceptions:"
]
exceptionMessages
=
(
displayException
<$>
toList
exceptions
)
combinedExceptions
::
CombinedException
->
[
SomeException
]
combinedExceptions
(
CombinedException
exceptions
)
=
toList
exceptions
data
RootResourceManager
=
RootResourceManager
ResourceManager
(
TVar
Bool
)
(
TVar
(
Maybe
(
Seq
SomeException
)))
(
Awaitable
()
)
...
...
@@ -287,12 +290,12 @@ newUnmanagedRootResourceManager = liftIO $ toResourceManager <$> do
await
=<<
dispose
child
mE
xceptions
<-
atomically
do
e
xceptions
<-
atomically
do
-- The var is set to `Nothing` to signal that no more exceptions can be received
nonEmpty
.
toList
<$>
(
maybe
impossibleCodePathM
pure
=<<
swapTVar
exceptionsVar
Nothing
)
maybe
impossibleCodePathM
pure
=<<
swapTVar
exceptionsVar
Nothing
-- If there are any exceptions will be stored in the awaitable (isDisposedAwaitable) by throwing them here
mapM_
(
throwM
.
CombinedException
)
mE
xceptions
mapM_
(
throwM
.
CombinedException
)
$
nonEmpty
$
toList
e
xceptions
withRootResourceManager
::
(
MonadAwait
m
,
MonadMask
m
,
MonadIO
m
)
=>
ReaderT
ResourceManager
IO
a
->
m
a
...
...
This diff is collapsed.
Click to expand it.
test/Quasar/ResourceManagerSpec.hs
+
9
−
0
View file @
0fc8d6c6
...
...
@@ -3,6 +3,7 @@ module Quasar.ResourceManagerSpec (spec) where
import
Control.Concurrent
import
Control.Concurrent.STM
import
Control.Exception
import
Control.Monad.Catch
import
Quasar.Prelude
import
Test.Hspec
import
Quasar.Awaitable
...
...
@@ -109,6 +110,14 @@ spec = parallel $ do
liftIO
$
throwToResourceManager
rm
TestException
sleepForever
it
"combines exceptions from resources with exceptions on the thread"
$
io
do
pendingWith
"not implemented"
(`
shouldThrow
`
\
(
combinedExceptions
->
exceptions
)
->
length
exceptions
==
2
)
do
withRootResourceManager
do
rm
<-
askResourceManager
liftIO
$
throwToResourceManager
rm
TestException
throwM
TestException
describe
"linkExecution"
do
it
"does not generate an exception after it is completed"
$
io
do
(`
shouldThrow
`
\
(
_
::
CombinedException
)
->
True
)
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment