[test] fix running tests when corenlp is already running

We had 'race' previously and so the tests quit immediately, because
corenlp nix couldn't start.

Now I use 'waitBoth' so that even if corenlp fails to start (because
it's already running on dev machine), the tests will continue.
parent 84bbdd5e
Pipeline #7812 failed with stages
in 144 minutes and 9 seconds
...@@ -70,7 +70,9 @@ startCoreNLPServer = do ...@@ -70,7 +70,9 @@ startCoreNLPServer = do
pure (stdout_hdl, stderr_hdl, hdl) pure (stdout_hdl, stderr_hdl, hdl)
killProcessTree :: (Handle, Handle, ProcessHandle) -> IO () killProcessTree :: (Handle, Handle, ProcessHandle) -> IO ()
killProcessTree (_, _, ph) = do killProcessTree (_, stderr_hdl, ph) = do
errContent <- hGetContents stderr_hdl
unless (errContent == "") $ putText $ "CoreNLP ERROR:\n" <> T.pack errContent
pid <- getPid ph pid <- getPid ph
case pid of case pid of
Nothing -> putText "Process already terminated" Nothing -> putText "Process already terminated"
...@@ -105,7 +107,11 @@ waitOrDie (stdout_h, stderr_h, h) = do ...@@ -105,7 +107,11 @@ waitOrDie (stdout_h, stderr_h, h) = do
main :: IO () main :: IO ()
main = do main = do
hSetBuffering stdout NoBuffering hSetBuffering stdout NoBuffering
bracket startCoreNLPServer killProcessTree (\h -> race (waitOrDie h) run_tests *> pure()) bracket startCoreNLPServer killProcessTree $ \h -> do
corenlpP <- async $ waitOrDie h
testP <- async run_tests
-- race (waitOrDie h) run_tests *> pure()
void $ waitBoth corenlpP testP
where where
run_tests = hspec $ sequential $ do run_tests = hspec $ sequential $ do
API.tests API.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