From 34f8e17a5f59706879f675fdae001ff597c26063 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Wed, 18 Dec 2024 20:18:46 +0100 Subject: [PATCH] integration: Print name of the test in logs from dynamic backends (#4383) --- integration/test/Testlib/Env.hs | 7 ++++--- integration/test/Testlib/ModService.hs | 12 ++++++------ integration/test/Testlib/Run.hs | 8 ++++---- integration/test/Testlib/RunServices.hs | 2 +- integration/test/Testlib/Types.hs | 3 ++- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/integration/test/Testlib/Env.hs b/integration/test/Testlib/Env.hs index 401332e4a0b..d14cb630a17 100644 --- a/integration/test/Testlib/Env.hs +++ b/integration/test/Testlib/Env.hs @@ -130,8 +130,8 @@ mkGlobalEnv cfgFile = do pure $ Just sslContext createSSLContext Nothing = pure Nothing -mkEnv :: GlobalEnv -> Codensity IO Env -mkEnv ge = do +mkEnv :: Maybe String -> GlobalEnv -> Codensity IO Env +mkEnv currentTestName ge = do mls <- liftIO . newIORef =<< mkMLSState liftIO $ do pks <- newIORef (zip [1 ..] somePrekeys) @@ -161,7 +161,8 @@ mkEnv ge = do mls = mls, resourcePool = ge.gBackendResourcePool, rabbitMQConfig = ge.gRabbitMQConfig, - timeOutSeconds = ge.gTimeOutSeconds + timeOutSeconds = ge.gTimeOutSeconds, + currentTestName } allCiphersuites :: [Ciphersuite] diff --git a/integration/test/Testlib/ModService.hs b/integration/test/Testlib/ModService.hs index a41244faaae..31716b94e9c 100644 --- a/integration/test/Testlib/ModService.hs +++ b/integration/test/Testlib/ModService.hs @@ -358,17 +358,17 @@ withProcess :: (HasCallStack) => BackendResource -> ServiceOverrides -> Service withProcess resource overrides service = do let domain = berDomain resource sm <- lift $ getServiceMap domain + env <- lift ask getConfig <- lift . appToIO $ readServiceConfig service >>= updateServiceMapInConfig resource service >>= lookupConfigOverride overrides service let execName = configName service - (cwd, exe) <- - lift $ asks \env -> case env.servicesCwdBase of - Nothing -> (Nothing, execName) - Just dir -> - (Just (dir execName), "../../dist" execName) + let (cwd, exe) = case env.servicesCwdBase of + Nothing -> (Nothing, execName) + Just dir -> + (Just (dir execName), "../../dist" execName) startNginzLocalIO <- lift $ appToIO $ startNginzLocal resource @@ -379,7 +379,7 @@ withProcess resource overrides service = do config <- getConfig tempFile <- writeTempFile "/tmp" (execName <> "-" <> domain <> "-" <> ".yaml") (cs $ Yaml.encode config) (_, Just stdoutHdl, Just stderrHdl, ph) <- createProcess (proc exe ["-c", tempFile]) {cwd = cwd, std_out = CreatePipe, std_err = CreatePipe} - let prefix = "[" <> execName <> "@" <> domain <> "] " + let prefix = "[" <> execName <> "@" <> domain <> maybe "" (":" <>) env.currentTestName <> "] " let colorize = fromMaybe id (lookup execName processColors) void $ forkIO $ logToConsole colorize prefix stdoutHdl void $ forkIO $ logToConsole colorize prefix stderrHdl diff --git a/integration/test/Testlib/Run.hs b/integration/test/Testlib/Run.hs index d7d533060c7..56caebb5055 100644 --- a/integration/test/Testlib/Run.hs +++ b/integration/test/Testlib/Run.hs @@ -31,9 +31,9 @@ import Text.Printf import UnliftIO.Async import Prelude -runTest :: GlobalEnv -> App a -> IO (Either String a) -runTest ge action = lowerCodensity $ do - env <- mkEnv ge +runTest :: String -> GlobalEnv -> App a -> IO (Either String a) +runTest testName ge action = lowerCodensity $ do + env <- mkEnv (Just testName) ge liftIO $ (Right <$> runAppWithEnv env action) `E.catches` [ E.Handler $ \(e :: SomeAsyncException) -> do @@ -121,7 +121,7 @@ runTests tests mXMLOutput cfg = do withAsync displayOutput $ \displayThread -> do -- Currently 4 seems to be stable, more seems to create more timeouts. report <- fmap mconcat $ pooledForConcurrentlyN 4 tests $ \(qname, _, _, action) -> do - (mErr, tm) <- withTime (runTest genv action) + (mErr, tm) <- withTime (runTest qname genv action) case mErr of Left err -> do writeOutput $ diff --git a/integration/test/Testlib/RunServices.hs b/integration/test/Testlib/RunServices.hs index a88686b2979..434cfbf50ef 100644 --- a/integration/test/Testlib/RunServices.hs +++ b/integration/test/Testlib/RunServices.hs @@ -71,7 +71,7 @@ main = do (_, _, _, ph) <- createProcess cp exitWith =<< waitForProcess ph - runCodensity (mkGlobalEnv cfg >>= mkEnv) $ \env -> + runCodensity (mkGlobalEnv cfg >>= mkEnv Nothing) $ \env -> runAppWithEnv env $ lowerCodensity $ do diff --git a/integration/test/Testlib/Types.hs b/integration/test/Testlib/Types.hs index d5c95021afa..bdb732c6831 100644 --- a/integration/test/Testlib/Types.hs +++ b/integration/test/Testlib/Types.hs @@ -228,7 +228,8 @@ data Env = Env mls :: IORef MLSState, resourcePool :: ResourcePool BackendResource, rabbitMQConfig :: RabbitMQConfig, - timeOutSeconds :: Int + timeOutSeconds :: Int, + currentTestName :: Maybe String } data Response = Response