Skip to content

Commit 88a3e7b

Browse files
committed
printMemory to output info about top failure.
1 parent 92fc021 commit 88a3e7b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

rules_haskell_tests/tests/RunTests.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import System.FilePath ((</>))
1111
import System.Info (os)
1212
import System.IO.Temp (withSystemTempDirectory)
1313
import System.Environment (lookupEnv)
14+
import System.Exit (ExitCode(..))
1415

1516
import qualified System.Process as Process
1617
import Test.Hspec.Core.Spec (SpecM)
@@ -179,17 +180,22 @@ shutdownBazel = do
179180
-- | Print memory information before and after each test
180181
printMemoryHook :: IO () -> IO ()
181182
printMemoryHook action = bracket_
182-
(printMemory "BEFORE")
183-
(printMemory "AFTER")
183+
(printMemory "=== BEFORE ===")
184+
(printMemory "=== AFTER ===")
184185
action
185186

186187
-- | Print information about the current memory state to debug intermittent failures
187188
-- Related to https://github.com/tweag/rules_haskell/issues/2089
188189
printMemory :: String -> IO ()
189190
printMemory msg = do
190191
putStrLn msg
191-
(_, stdOut, _) <- Process.readProcessWithExitCode "/usr/bin/top" ["-l", "1", "-s", "0", "-o", "mem", "-n", "15"] ""
192-
putStrLn stdOut
192+
(exitCode, stdOut, stdErr) <- Process.readProcessWithExitCode "top" ["-l", "1", "-s", "0", "-o", "mem", "-n", "15"] ""
193+
-- (exitCode, stdOut, stdErr) <- Process.readProcessWithExitCode "/usr/bin/top" ["-l", "1", "-s", "0", "-o", "mem", "-n", "15"] ""
194+
-- (exitCode, stdOut, stdErr) <- Process.readProcessWithExitCode "foo" ["-l", "1", "-s", "0", "-o", "mem", "-n", "15"] ""
195+
-- putStrLn stdOut
196+
case exitCode of
197+
ExitSuccess -> putStrLn stdOut
198+
ExitFailure _ -> putStrLn ("=== printMemory failed ===\n" ++ stdErr)
193199

194200
-- Generated dependencies for testing the ghcide support
195201
_ghciIDE :: Int

0 commit comments

Comments
 (0)