Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
153
Issues
153
List
Board
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
9058776b
Commit
9058776b
authored
Mar 17, 2025
by
Alfredo Di Napoli
Committed by
Alfredo Di Napoli
Mar 26, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add concurrent test for worker notifications
Concurrency is a good way to trigger any interleaving bug.
parent
f12b9df7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
Worker.hs
test/Test/API/Worker.hs
+26
-1
No files found.
test/Test/API/Worker.hs
View file @
9058776b
...
...
@@ -19,7 +19,7 @@ module Test.API.Worker (
tests
)
where
import
Control.Concurrent.Async
(
withAsync
)
import
Control.Concurrent.Async
(
withAsync
,
forConcurrently_
)
import
Control.Concurrent.STM.TChan
import
Control.Lens
import
Control.Monad.STM
(
atomically
)
...
...
@@ -40,6 +40,7 @@ import Test.Utils.Notifications
import
Gargantext.System.Logging
import
qualified
Data.Text.Encoding
as
TE
import
qualified
Data.ByteString
as
BL
import
Test.Tasty.HUnit
(
assertBool
)
...
...
@@ -63,6 +64,30 @@ tests = sequential $ aroundAll withTestDBAndPort $ do
mTimeout
`
shouldSatisfy
`
isJust
describe
"concurrency"
$
do
-- This test checks that two concurrent threads can both subscribe
-- to the same topic and get notified.
it
"handles concurrent threads"
$
\
(
SpecContext
testEnv
port
_app
_
)
->
do
let
cfg
=
test_config
testEnv
let
log_cfg
=
(
test_config
testEnv
)
^.
gc_logging
let
topic
=
DT
.
Ping
let
competingThreads
=
3
forConcurrently_
[
1
..
competingThreads
]
$
\
(
tid
::
Int
)
->
do
tchan
<-
newTChanIO
::
IO
(
TChan
(
Maybe
DT
.
Notification
))
withAsync
(
setupWsThread
log_cfg
topic
tchan
port
)
$
\
_a
->
do
_
<-
sendJobWithCfg
cfg
Ping
mTimeout
<-
Timeout
.
timeout
(
5
*
1
_000_000
)
$
do
md
<-
atomically
$
readTChan
tchan
md
`
shouldBe
`
Just
DT
.
NPing
assertBool
(
"Competing Thread "
<>
show
tid
<>
" didn't receive a value."
)
(
isJust
mTimeout
)
setupWsThread
::
LogConfig
->
DT
.
Topic
->
TChan
(
Maybe
DT
.
Notification
)
->
Int
->
IO
()
setupWsThread
log_cfg
topic
tchan
port
=
withLogger
log_cfg
$
\
ioL
->
do
withWSConnection
(
"127.0.0.1"
,
port
)
$
\
conn
->
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment