From ef90411204c43f12e82e9d628796542c755e8fc9 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 23 Dec 2024 17:48:42 +0100 Subject: [PATCH] Fix: ssParser --- integration/test/Testlib/ModService.hs | 29 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/integration/test/Testlib/ModService.hs b/integration/test/Testlib/ModService.hs index 83b5cfcf900..38545049a67 100644 --- a/integration/test/Testlib/ModService.hs +++ b/integration/test/Testlib/ModService.hs @@ -11,6 +11,7 @@ where import Control.Concurrent import Control.Concurrent.Async +import Control.Exception (assert) import qualified Control.Exception as E import Control.Monad.Catch (catch, displayException, throwM) import Control.Monad.Codensity @@ -19,6 +20,7 @@ import Control.Monad.Reader import Control.Retry (fibonacciBackoff, limitRetriesByCumulativeDelay, retrying) import Data.Aeson hiding ((.=)) import qualified Data.Attoparsec.Text as Parser +import Data.Char (isSpace) import Data.Default import Data.Foldable import Data.Function @@ -309,10 +311,21 @@ ensureFederatorPortIsFree resource = do Left e -> assertFailure $ "Failed while parsing ss output with error: " <> e parseSS :: Text -> Either String (Maybe (String, ProcessID)) -parseSS input = - if Text.null input - then pure Nothing - else Just <$> Parser.parseOnly (ssParser <* Parser.endOfInput) input +parseSS = assert (and tests) prs + where + tests = + [ parseSS "LISTEN 0 4096 127.0.0.1:8082 0.0.0.0:* users:((\"brig\",pid=51468,fd=79))" + == Right (Just ("brig", 51468)), + parseSS "LISTEN 0 4096 127.0.0.1:8082 0.0.0.0:* users:((\"brig\",pid=51468,fd=79)) \t" + == Right (Just ("brig", 51468)), + parseSS "LISTEN 0 4096 127.0.0.1:8082 0.0.0.0:* users:((\"brig\",pid=51468,fd=79)) \n" + == Right (Just ("brig", 51468)) + ] + + prs input = + if Text.null input + then pure Nothing + else Just <$> Parser.parseOnly ssParser input -- Example input: -- LISTEN 0 4096 127.0.0.1:8082 0.0.0.0:* users:(("brig",pid=51468,fd=79)) @@ -327,12 +340,11 @@ ssParser = do name <- quoted _ <- Parser.char ',' p <- pid - _ <- Parser.many1 noNewLine pure (name, p) where spaces = void $ Parser.many' Parser.space - noSpace = Parser.satisfy (/= ' ') - noSpaces = Parser.many1 noSpace + noSpaces = Parser.takeWhile1 (not . isSpace) + noDoubleQuote = Parser.takeWhile1 (/= '"') token p = do spaces res <- p @@ -344,13 +356,12 @@ ssParser = do quoted = do token $ do _ <- Parser.char '"' - tok <- noSpaces + tok <- Text.unpack <$> noDoubleQuote _ <- Parser.char '"' pure tok pid = do ignoreStrToken "pid=" Parser.decimal - noNewLine = Parser.satisfy (/= '\n') ensureBackendReachable :: (HasCallStack) => String -> App () ensureBackendReachable domain = do