Commit 1ad17efd authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

fix(tests): allow ctrl-c to shut down the tests cleanly

The problem was caused by the improper usage of
`delegate_ctrl` when creating the coreNLP process. For a long
time I was under the impression this flag was essential to allow child
processes to shutdown cleanly without leaving zombie threads, but the
result here in the context of the testsuite was that the coreNLP server
was receiving the first Ctrl^C, completely starving the Haskell RTS,
which wouldn't receive any and as a result our testsuite would be
running forever.
parent 8ddb544b
Pipeline #7417 passed with stages
in 63 minutes and 28 seconds
...@@ -865,7 +865,9 @@ test-suite garg-test-hspec ...@@ -865,7 +865,9 @@ test-suite garg-test-hspec
, commonTestDependencies , commonTestDependencies
type: exitcode-stdio-1.0 type: exitcode-stdio-1.0
main-is: drivers/hspec/Main.hs main-is: drivers/hspec/Main.hs
build-depends: process ^>= 1.6.18.0 build-depends:
process ^>= 1.6.18.0
, unix >= 2.7.3 && < 2.9
other-modules: other-modules:
Paths_gargantext Paths_gargantext
Test.API Test.API
......
...@@ -6,9 +6,10 @@ import Control.Monad ...@@ -6,9 +6,10 @@ import Control.Monad
import Data.Text (isInfixOf) import Data.Text (isInfixOf)
import Data.Text qualified as T import Data.Text qualified as T
import Gargantext.Prelude hiding (isInfixOf) import Gargantext.Prelude hiding (isInfixOf)
import Shelly hiding (FilePath)
import System.IO import System.IO
import System.Process import System.Process
import System.Posix.Process
import System.Posix.Signals
import Test.API qualified as API import Test.API qualified as API
import Test.Database.Operations qualified as DB import Test.Database.Operations qualified as DB
import Test.Hspec import Test.Hspec
...@@ -21,7 +22,13 @@ startCoreNLPServer = do ...@@ -21,7 +22,13 @@ startCoreNLPServer = do
devNull <- openFile "/dev/null" WriteMode devNull <- openFile "/dev/null" WriteMode
let p = proc "./startServer.sh" [] let p = proc "./startServer.sh" []
(_, _, _, hdl) <- (createProcess $ p { cwd = Just "devops/coreNLP/stanford-corenlp-current" (_, _, _, hdl) <- (createProcess $ p { cwd = Just "devops/coreNLP/stanford-corenlp-current"
, delegate_ctlc = True -- NOTE(adn) Issue #451, this one has to stay disabled, because if we
-- turn it on, despite the confusing documentation on the `process` library
-- it will cause the Haskell RTS to completely ignore the Ctrl^c and instead
-- delegate it exclusively to the process here, which means that our CoreNLP
-- server will shut down correctly, but the test running will stop responding
-- to Ctrl^C requests.
, delegate_ctlc = False
, create_group = True , create_group = True
, std_out = UseHandle devNull , std_out = UseHandle devNull
, std_err = UseHandle devNull , std_err = UseHandle devNull
...@@ -34,12 +41,14 @@ startCoreNLPServer = do ...@@ -34,12 +41,14 @@ startCoreNLPServer = do
| otherwise -> throwIO e | otherwise -> throwIO e
pure hdl pure hdl
stopCoreNLPServer :: ProcessHandle -> IO () killProcessTree :: ProcessHandle -> IO ()
stopCoreNLPServer ph = do killProcessTree ph = do
putText "calling stop core nlp" pid <- getPid ph
interruptProcessGroupOf ph case pid of
putText "calling stop core nlp - done" Nothing -> putText "Process already terminated"
Just p -> do
pgid <- getProcessGroupIDOf p
signalProcessGroup keyboardSignal pgid
-- It's especially important to use Hspec for DB tests, because, -- It's especially important to use Hspec for DB tests, because,
-- unlike 'tasty', 'Hspec' has explicit control over parallelism, -- unlike 'tasty', 'Hspec' has explicit control over parallelism,
...@@ -55,9 +64,9 @@ stopCoreNLPServer ph = do ...@@ -55,9 +64,9 @@ stopCoreNLPServer ph = do
main :: IO () main :: IO ()
main = do main = do
hSetBuffering stdout NoBuffering hSetBuffering stdout NoBuffering
-- TODO Ideally remove start/stop notifications and use bracket startCoreNLPServer killProcessTree (const run_tests)
-- Test/API/Setup to initialize this in env where
bracket startCoreNLPServer stopCoreNLPServer $ \_ -> hspec $ sequential $ do run_tests = hspec $ sequential $ do
API.tests API.tests
ReverseProxy.tests ReverseProxy.tests
DB.tests DB.tests
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment