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
5095609d
Commit
5095609d
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for cacheAwaitable
parent
59bc7df0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
quasar.cabal
+2
-0
2 additions, 0 deletions
quasar.cabal
test/Quasar/AwaitableSpec.hs
+60
-2
60 additions, 2 deletions
test/Quasar/AwaitableSpec.hs
with
62 additions
and
2 deletions
quasar.cabal
+
2
−
0
View file @
5095609d
...
...
@@ -101,8 +101,10 @@ test-suite quasar-test
type: exitcode-stdio-1.0
build-depends:
base >=4.7 && <5,
exceptions,
hspec,
quasar,
stm,
unordered-containers,
main-is: Spec.hs
other-modules:
...
...
This diff is collapsed.
Click to expand it.
test/Quasar/AwaitableSpec.hs
+
60
−
2
View file @
5095609d
module
Quasar.AwaitableSpec
(
spec
)
where
import
Control.Concurrent
import
Control.Monad
(
void
)
import
Prelude
import
Control.Concurrent.STM
import
Control.Monad.Catch
import
GHC.Conc
(
unsafeIOToSTM
)
import
Test.Hspec
import
Quasar.Awaitable
import
Quasar.Prelude
data
TestException
=
TestException
deriving
stock
(
Eq
,
Show
)
instance
Exception
TestException
spec
::
Spec
spec
=
parallel
$
do
...
...
@@ -55,3 +62,54 @@ spec = parallel $ do
threadDelay
100000
putAsyncVar_
avar2
()
awaitAny2
avar1
avar2
describe
"cacheAwaitable"
do
it
"can cache an awaitable"
$
io
do
var
<-
newTVarIO
(
0
::
Int
)
awaitable
<-
cacheAwaitable
do
unsafeAwaitSTM
(
modifyTVar
var
(
+
1
))
::
Awaitable
()
await
awaitable
await
awaitable
readTVarIO
var
`
shouldReturn
`
1
it
"can cache a bind"
$
io
do
var1
<-
newTVarIO
(
0
::
Int
)
var2
<-
newTVarIO
(
0
::
Int
)
awaitable
<-
cacheAwaitable
do
unsafeAwaitSTM
(
modifyTVar
var1
(
+
1
))
>>=
\
_
->
unsafeAwaitSTM
(
modifyTVar
var2
(
+
1
))
::
Awaitable
()
await
awaitable
await
awaitable
readTVarIO
var1
`
shouldReturn
`
1
readTVarIO
var2
`
shouldReturn
`
1
it
"can cache an exception"
$
io
do
var
<-
newMVar
(
0
::
Int
)
awaitable
<-
cacheAwaitable
do
unsafeAwaitSTM
(
unsafeIOToSTM
(
modifyMVar_
var
(
pure
.
(
+
1
)))
>>
throwM
TestException
)
::
Awaitable
()
await
awaitable
`
shouldThrow
`
\
TestException
->
True
await
awaitable
`
shouldThrow
`
\
TestException
->
True
readMVar
var
`
shouldReturn
`
1
it
"can cache the left side of an awaitAny2"
$
io
do
var
<-
newTVarIO
(
0
::
Int
)
let
a1
=
unsafeAwaitSTM
(
modifyTVar
var
(
+
1
))
::
Awaitable
()
let
a2
=
unsafeAwaitSTM
retry
::
Awaitable
()
awaitable
<-
cacheAwaitable
$
(
awaitAny2
a1
a2
::
Awaitable
()
)
await
awaitable
await
awaitable
readTVarIO
var
`
shouldReturn
`
1
it
"can cache the right side of an awaitAny2"
$
io
do
var
<-
newTVarIO
(
0
::
Int
)
let
a1
=
unsafeAwaitSTM
retry
::
Awaitable
()
let
a2
=
unsafeAwaitSTM
(
modifyTVar
var
(
+
1
))
::
Awaitable
()
awaitable
<-
cacheAwaitable
$
(
awaitAny2
a1
a2
::
Awaitable
()
)
await
awaitable
await
awaitable
readTVarIO
var
`
shouldReturn
`
1
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