Skip to content

Commit

Permalink
integration: Print name of the test in logs from dynamic backends (#4383
Browse files Browse the repository at this point in the history
)
  • Loading branch information
akshaymankar authored Dec 18, 2024
1 parent 8bf04be commit 34f8e17
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
7 changes: 4 additions & 3 deletions integration/test/Testlib/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -161,7 +161,8 @@ mkEnv ge = do
mls = mls,
resourcePool = ge.gBackendResourcePool,
rabbitMQConfig = ge.gRabbitMQConfig,
timeOutSeconds = ge.gTimeOutSeconds
timeOutSeconds = ge.gTimeOutSeconds,
currentTestName
}

allCiphersuites :: [Ciphersuite]
Expand Down
12 changes: 6 additions & 6 deletions integration/test/Testlib/ModService.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions integration/test/Testlib/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 $
Expand Down
2 changes: 1 addition & 1 deletion integration/test/Testlib/RunServices.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion integration/test/Testlib/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 34f8e17

Please sign in to comment.