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
152
Issues
152
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
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
3c0de944
Commit
3c0de944
authored
Apr 25, 2023
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/adinapoli/issue-198' into dev
parents
261f7ea3
37d72aa8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
33 deletions
+39
-33
Main.hs
tests/queue/Main.hs
+39
-33
No files found.
tests/queue/Main.hs
View file @
3c0de944
...
@@ -35,6 +35,7 @@ import Gargantext.API.Prelude
...
@@ -35,6 +35,7 @@ import Gargantext.API.Prelude
import
Gargantext.API.Admin.EnvTypes
as
EnvTypes
import
Gargantext.API.Admin.EnvTypes
as
EnvTypes
import
Gargantext.API.Admin.Orchestrator.Types
import
Gargantext.API.Admin.Orchestrator.Types
data
JobT
=
A
data
JobT
=
A
|
B
|
B
|
C
|
C
...
@@ -138,35 +139,28 @@ testExceptions = do
...
@@ -138,35 +139,28 @@ testExceptions = do
testFairness
::
IO
()
testFairness
::
IO
()
testFairness
=
do
testFairness
=
do
k
<-
genSecret
k
<-
genSecret
let
settings
=
defaultJobSettings
2
k
let
settings
=
defaultJobSettings
1
k
st
::
JobsState
JobT
[
String
]
()
<-
newJobsState
settings
defaultPrios
st
::
JobsState
JobT
[
String
]
()
<-
newJobsState
settings
defaultPrios
runningJs
<-
newTVarIO
(
Counts
0
0
)
pickedSchedule
<-
newMVar
(
JobSchedule
mempty
)
let
j
jobt
_jHandle
_inp
_l
=
do
let
j
jobt
_jHandle
_inp
_l
=
addJobToSchedule
jobt
pickedSchedule
atomically
$
modifyTVar
runningJs
(
inc
jobt
)
threadDelay
jobDuration
atomically
$
modifyTVar
runningJs
(
dec
jobt
)
jobs
=
[
(
A
,
j
A
)
jobs
=
[
(
A
,
j
A
)
,
(
A
,
j
A
)
,
(
A
,
j
A
)
,
(
B
,
j
B
)
,
(
B
,
j
B
)
,
(
A
,
j
A
)
,
(
A
,
j
A
)
,
(
A
,
j
A
)
,
(
A
,
j
A
)
]
]
_jids
<-
forM
jobs
$
\
(
t
,
f
)
->
do
time
<-
getCurrentTime
pushJob
t
()
f
settings
st
-- in this scenario we simulate two types of jobs all with
threadDelay
initialDelay
-- all the same level of priority: our queue implementation
r1
<-
readTVarIO
runningJs
-- will behave as a classic FIFO, keeping into account the
r1
`
shouldBe
`
(
Counts
2
0
)
-- time of arrival.
threadDelay
jobDuration
atomically
$
forM_
(
zip
[
0
,
2
..
]
jobs
)
$
\
(
timeDelta
,
(
t
,
f
))
->
void
$
r2
<-
readTVarIO
runningJs
pushJobWithTime
(
addUTCTime
(
fromInteger
timeDelta
)
time
)
t
()
f
settings
st
r2
`
shouldBe
`
(
Counts
1
1
)
-- MOST IMPORTANT CHECK: the B got picked after the
-- two As, because it was inserted right after them
-- and has equal priority.
threadDelay
jobDuration
r3
<-
readTVarIO
runningJs
r3
`
shouldBe
`
(
Counts
1
0
)
threadDelay
jobDuration
threadDelay
jobDuration
r4
<-
readTVarIO
runningJs
finalSchedule
<-
readMVar
pickedSchedule
r4
`
shouldBe
`
(
Counts
0
0
)
finalSchedule
`
shouldBe
`
JobSchedule
(
fromList
[
A
,
A
,
B
,
A
,
A
])
newtype
MyDummyMonad
a
=
newtype
MyDummyMonad
a
=
MyDummyMonad
{
_MyDummyMonad
::
GargM
Env
GargError
a
}
MyDummyMonad
{
_MyDummyMonad
::
GargM
Env
GargError
a
}
...
@@ -219,7 +213,7 @@ withJob_ env f = void (withJob env f)
...
@@ -219,7 +213,7 @@ withJob_ env f = void (withJob env f)
newTestEnv
::
IO
Env
newTestEnv
::
IO
Env
newTestEnv
=
do
newTestEnv
=
do
k
<-
genSecret
k
<-
genSecret
let
settings
=
defaultJobSettings
2
k
let
settings
=
defaultJobSettings
1
k
myEnv
<-
newJobEnv
settings
defaultPrios
testTlsManager
myEnv
<-
newJobEnv
settings
defaultPrios
testTlsManager
pure
$
Env
pure
$
Env
{
_env_settings
=
error
"env_settings not needed, but forced somewhere (check StrictData)"
{
_env_settings
=
error
"env_settings not needed, but forced somewhere (check StrictData)"
...
@@ -284,28 +278,40 @@ testFetchJobStatusNoContention = do
...
@@ -284,28 +278,40 @@ testFetchJobStatusNoContention = do
testMarkProgress
::
IO
()
testMarkProgress
::
IO
()
testMarkProgress
=
do
testMarkProgress
=
do
myEnv
<-
newTestEnv
myEnv
<-
newTestEnv
evts
<-
newMVar
[]
evts
<-
newTBQueueIO
7
let
getStatus
hdl
=
do
liftIO
$
threadDelay
100
_000
st
<-
getLatestJobStatus
hdl
liftIO
$
atomically
$
writeTBQueue
evts
st
readAllEvents
=
do
allEventsArrived
<-
isFullTBQueue
evts
if
allEventsArrived
then
flushTBQueue
evts
else
retry
withJob_
myEnv
$
\
hdl
_input
->
do
withJob_
myEnv
$
\
hdl
_input
->
do
markStarted
10
hdl
markStarted
10
hdl
jl0
<-
getLatestJobStatus
hdl
getStatus
hdl
markProgress
1
hdl
markProgress
1
hdl
jl1
<-
getLatestJobStatus
hdl
getStatus
hdl
markFailure
1
Nothing
hdl
markFailure
1
Nothing
hdl
jl2
<-
getLatestJobStatus
hdl
getStatus
hdl
markFailure
1
(
Just
"boom"
)
hdl
markFailure
1
(
Just
"boom"
)
hdl
jl3
<-
getLatestJobStatus
hdl
getStatus
hdl
markComplete
hdl
markComplete
hdl
jl4
<-
getLatestJobStatus
hdl
getStatus
hdl
markStarted
5
hdl
markStarted
5
hdl
markProgress
1
hdl
markProgress
1
hdl
jl5
<-
getLatestJobStatus
hdl
getStatus
hdl
markFailed
(
Just
"kaboom"
)
hdl
markFailed
(
Just
"kaboom"
)
hdl
jl6
<-
getLatestJobStatus
hdl
liftIO
$
modifyMVar_
evts
(
const
(
pure
[
jl0
,
jl1
,
jl2
,
jl3
,
jl4
,
jl5
,
jl6
]))
threadDelay
500
_000
getStatus
hdl
[
jl0
,
jl1
,
jl2
,
jl3
,
jl4
,
jl5
,
jl6
]
<-
readMVar
evts
[
jl0
,
jl1
,
jl2
,
jl3
,
jl4
,
jl5
,
jl6
]
<-
atomically
readAllEvents
-- Check the events are what we expect
-- Check the events are what we expect
jl0
`
shouldBe
`
JobLog
{
_scst_succeeded
=
Just
0
jl0
`
shouldBe
`
JobLog
{
_scst_succeeded
=
Just
0
...
...
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