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
151
Issues
151
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
40ff740e
Commit
40ff740e
authored
Apr 07, 2025
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pollUntilWorkFinished returns a JobLog now
parent
645463e6
Pipeline
#7521
canceled with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
24 deletions
+39
-24
List.hs
test/Test/API/Private/List.hs
+21
-8
UpdateList.hs
test/Test/API/UpdateList.hs
+4
-4
Utils.hs
test/Test/Utils.hs
+14
-12
No files found.
test/Test/API/Private/List.hs
View file @
40ff740e
...
...
@@ -12,6 +12,7 @@ import Data.Aeson.QQ
import
Data.Text
qualified
as
T
import
Data.Text.IO
qualified
as
TIO
import
Fmt
import
Gargantext.API.Admin.Orchestrator.Types
import
Gargantext.API.HashedResponse
import
Gargantext.API.Ngrams.List.Types
import
Gargantext.API.Ngrams.Types
qualified
as
APINgrams
...
...
@@ -22,7 +23,6 @@ import Gargantext.Core.Config
import
Gargantext.Core.Text.List.Social
import
Gargantext.Core.Types
import
Gargantext.Core.Types.Individu
import
Gargantext.Core.Worker.Types
import
Gargantext.Prelude
import
Paths_gargantext
import
Prelude
...
...
@@ -47,7 +47,7 @@ mkNewWithForm content name = NewWithForm
}
importTermsTSV
::
SpecContext
()
->
String
->
IO
(
Job
Info
,
CorpusId
,
ListId
)
importTermsTSV
::
SpecContext
()
->
String
->
IO
(
Job
Log
,
CorpusId
,
ListId
)
importTermsTSV
(
SpecContext
testEnv
port
app
_
)
name
=
do
cId
<-
liftIO
$
newCorpusForUser
testEnv
"alice"
let
log_cfg
=
test_config
testEnv
^.
gc_logging
...
...
@@ -60,11 +60,11 @@ importTermsTSV (SpecContext testEnv port app _) name = do
,
_wtf_data
=
simpleNgrams
,
_wtf_name
=
"simple.tsv"
}
pendingJob
<-
checkEither
$
liftIO
$
runClientM
(
add_tsv_to_list
token
listId
params
)
clientEnv
job
Info
<-
pollUntilWorkFinished
log_cfg
port
pendingJob
job
Log
<-
pollUntilWorkFinished
log_cfg
port
pendingJob
pure
(
job
Info
,
cId
,
listId
)
pure
(
job
Log
,
cId
,
listId
)
importCorpusTSV
::
SpecContext
()
->
String
->
IO
(
Job
Info
,
CorpusId
,
ListId
)
importCorpusTSV
::
SpecContext
()
->
String
->
IO
(
Job
Log
,
CorpusId
,
ListId
)
importCorpusTSV
(
SpecContext
testEnv
port
app
_
)
name
=
do
cId
<-
liftIO
$
newCorpusForUser
testEnv
"alice"
let
log_cfg
=
test_config
testEnv
^.
gc_logging
...
...
@@ -75,9 +75,9 @@ importCorpusTSV (SpecContext testEnv port app _) name = do
simpleNgrams
<-
liftIO
(
TIO
.
readFile
=<<
getDataFileName
name
)
let
params
=
mkNewWithForm
simpleNgrams
"simple.tsv"
pendingJob
<-
checkEither
$
liftIO
$
runClientM
(
importCorpus
token
cId
params
)
clientEnv
job
Info
<-
pollUntilWorkFinished
log_cfg
port
pendingJob
job
Log
<-
pollUntilWorkFinished
log_cfg
port
pendingJob
pure
(
job
Info
,
cId
,
listId
)
pure
(
job
Log
,
cId
,
listId
)
tests
::
Spec
tests
=
sequential
$
aroundAll
withTestDBAndPort
$
do
...
...
@@ -110,7 +110,7 @@ tests = sequential $ aroundAll withTestDBAndPort $ do
length
tr_docs
`
shouldBe
`
7
it
"should skip problematic rows"
$
\
ctx
@
(
SpecContext
_testEnv
port
app
_
)
->
do
(
_
,
cId
,
_listId
)
<-
importCorpusTSV
ctx
"test-data/issue-380/malformed_row.tsv"
(
jobLogs
,
cId
,
_listId
)
<-
importCorpusTSV
ctx
"test-data/issue-380/malformed_row.tsv"
withApplication
app
$
do
withValidLogin
port
"alice"
(
GargPassword
"alice"
)
$
\
clientEnv
token
->
do
-- Now check that we can retrieve the ngrams, and the ngrams list is not empty!
...
...
@@ -118,3 +118,16 @@ tests = sequential $ aroundAll withTestDBAndPort $ do
eRes
<-
checkEither
$
runClientM
(
get_table
token
cId
(
Just
APINgrams
.
Docs
)
Nothing
Nothing
Nothing
Nothing
Nothing
)
clientEnv
let
(
HashedResponse
_
TableResult
{
tr_docs
})
=
eRes
length
tr_docs
`
shouldBe
`
6
-- it must have skipped the broken row
-- Check that the events include the two failures we encountered.
_scst_events
jobLogs
`
shouldBe
`
Just
[
ScraperEvent
{
_scev_message
=
Just
"Skipping record at row 6 as parsing failed due to: no field named
\"
Publication Year
\"
"
,
_scev_level
=
Just
"WARNING"
,
_scev_date
=
Nothing
}
,
ScraperEvent
{
_scev_message
=
Just
"Skipping record at row 8 as parsing failed due to: parse error (endOfInput)"
,
_scev_level
=
Just
"WARNING"
,
_scev_date
=
Nothing
}
]
test/Test/API/UpdateList.hs
View file @
40ff740e
...
...
@@ -75,7 +75,7 @@ import Test.Hspec
import
Test.Hspec.Wai.Internal
(
withApplication
,
WaiSession
)
import
Test.Hspec.Wai.JSON
(
json
)
import
Test.Types
(
JobPollHandle
(
..
))
import
Test.Utils
(
pollUntilWorkFinished
,
protectedJSON
,
withValidLogin
)
import
Test.Utils
(
pollUntilWorkFinished
,
protectedJSON
,
withValidLogin
,
isJobFinished
)
import
Text.Printf
(
printf
)
...
...
@@ -104,7 +104,7 @@ uploadJSONList log_cfg port token cId pathToNgrams clientEnv = do
ji
<-
checkEither
$
liftIO
$
runClientM
(
add_form_to_list
token
listId
params
)
clientEnv
-- liftIO (_jph_status j' `shouldBe` "IsFinished")
ji'
<-
pollUntilWorkFinished
log_cfg
port
ji
liftIO
$
ji'
`
should
Be
`
ji
liftIO
$
ji'
`
should
Satisfy
`
isJobFinished
pure
listId
...
...
@@ -357,7 +357,7 @@ createDocsList testDataPath testEnv port clientEnv token = do
let
newWithForm
=
mkNewWithForm
simpleDocs
(
T
.
pack
$
takeBaseName
testDataPath
)
ji
<-
checkEither
$
liftIO
$
runClientM
(
add_file_async
token
corpusId
newWithForm
)
clientEnv
ji'
<-
pollUntilWorkFinished
log_cfg
port
ji
liftIO
$
ji'
`
should
Be
`
ji
liftIO
$
ji'
`
should
Satisfy
`
isJobFinished
pure
corpusId
where
log_cfg
=
(
test_config
testEnv
)
^.
gc_logging
...
...
@@ -376,7 +376,7 @@ updateNode log_cfg port clientEnv token nodeId = do
let
params
=
UpdateNodeParamsTexts
Both
ji
<-
checkEither
$
liftIO
$
runClientM
(
update_node
token
nodeId
params
)
clientEnv
ji'
<-
pollUntilWorkFinished
log_cfg
port
ji
liftIO
$
ji'
`
should
Be
`
ji
liftIO
$
ji'
`
should
Satisfy
`
isJobFinished
mkNewWithForm
::
T
.
Text
->
T
.
Text
->
NewWithForm
mkNewWithForm
content
name
=
NewWithForm
...
...
test/Test/Utils.hs
View file @
40ff740e
...
...
@@ -28,6 +28,7 @@ module Test.Utils (
,
waitUntil
,
withValidLogin
,
withValidLoginA
,
isJobFinished
)
where
import
Control.Concurrent.STM.TChan
(
TChan
,
readTChan
)
...
...
@@ -256,10 +257,10 @@ pollUntilWorkFinished :: HasCallStack
=>
LogConfig
->
Port
->
JobInfo
->
WaiSession
()
Job
Info
->
WaiSession
()
Job
Log
pollUntilWorkFinished
log_cfg
port
ji
=
do
let
waitSecs
=
60
isFinishedTVar
<-
liftIO
$
newTVarIO
False
isFinishedTVar
<-
liftIO
$
newTVarIO
Nothing
let
wsConnect
=
withWSConnection
(
"127.0.0.1"
,
port
)
$
\
conn
->
do
-- We wait a bit before the server settles
...
...
@@ -275,11 +276,11 @@ pollUntilWorkFinished log_cfg port ji = do
Just
(
DT
.
NUpdateWorkerProgress
ji'
jl
)
->
do
withLogger
log_cfg
$
\
ioL
->
logMsg
ioL
DEBUG
$
"[pollUntilWorkFinished] received "
<>
show
ji'
<>
", "
<>
show
jl
if
ji'
==
ji
&&
isFinished
jl
if
ji'
==
ji
&&
is
Job
Finished
jl
then
do
withLogger
log_cfg
$
\
ioL
->
logMsg
ioL
DEBUG
$
"[pollUntilWorkFinished] FINISHED! "
<>
show
ji'
atomically
$
writeTVar
isFinishedTVar
True
atomically
$
writeTVar
isFinishedTVar
(
Just
jl
)
else
pure
()
_
->
pure
()
...
...
@@ -287,23 +288,24 @@ pollUntilWorkFinished log_cfg port ji = do
liftIO
$
withAsync
wsConnect
$
\
_
->
do
mRet
<-
Timeout
.
timeout
(
waitSecs
*
1000
*
millisecond
)
$
do
let
go
=
do
finished
<-
readTVarIO
isFinishedTVar
if
finished
then
do
finished
_mb
<-
readTVarIO
isFinishedTVar
case
finished_mb
of
Just
job_log
->
do
withLogger
log_cfg
$
\
ioL
->
logMsg
ioL
DEBUG
$
"[pollUntilWorkFinished] JOB FINISHED: "
<>
show
ji
return
True
else
do
pure
job_log
Nothing
->
do
threadDelay
(
50
*
millisecond
)
go
go
case
mRet
of
Nothing
->
panicTrace
$
"[pollUntilWorkFinished] timed out while waiting to finish job "
<>
show
ji
Just
_
->
return
ji
Just
jl
->
pure
jl
where
isFinished
(
JobLog
{
..
})
=
_scst_remaining
==
Just
0
isJobFinished
::
JobLog
->
Bool
isJobFinished
(
JobLog
{
..
})
=
_scst_remaining
==
Just
0
-- | Like HUnit's '@?=', but With a nicer error message in case the two entities are not equal.
(
@??=
)
::
(
HasCallStack
,
ToExpr
a
,
Eq
a
)
=>
a
->
a
->
Assertion
...
...
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