Skip to content

Commit

Permalink
tmp test macOS 4, one prop per group 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Shevchenko committed Jan 18, 2022
1 parent c85274d commit 3df0e37
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
44 changes: 23 additions & 21 deletions cardano-tracer/test/Cardano/Tracer/Test/Logs/Tests.hs
@@ -1,7 +1,8 @@
{-# LANGUAGE LambdaCase #-}

module Cardano.Tracer.Test.Logs.Tests
( tests
( testsLogs
, testsJson
) where

import Control.Concurrent.Async (withAsync)
Expand All @@ -24,28 +25,22 @@ import Cardano.Tracer.Utils (applyBrake, initProtocolsBrake, initDataP
import Cardano.Tracer.Test.Forwarder
import Cardano.Tracer.Test.Utils

tests :: TestTree
tests = localOption (QuickCheckTests 1) $ testGroup "Test.Logs"
[ tests1 -- testProperty ".log" $ propRunInLogsStructure (propLogs ForHuman)
, tests2 -- testProperty ".json" $ propRunInLogsStructure (propLogs ForMachine)
--, testProperty "multi, initiator" $ propRunInLogsStructure2 (propMultiInit ForMachine)
--, testProperty "multi, responder" $ propRunInLogsStructure (propMultiResp ForMachine)
]

tests1 :: TestTree
tests1 = localOption (QuickCheckTests 1) $ testGroup "Test.Logs.Log"
testsLogs :: TestTree
testsLogs = localOption (QuickCheckTests 1) $ testGroup "Test.Logs"
[ testProperty ".log" $ propRunInLogsStructure (propLogs ForHuman)
]

tests2 :: TestTree
tests2 = localOption (QuickCheckTests 1) $ testGroup "Test.Logs.Json"
testsJson :: TestTree
testsJson = localOption (QuickCheckTests 1) $ testGroup "Test.Logs"
[ testProperty ".json" $ propRunInLogsStructure (propLogs ForMachine)
--, testProperty "multi, initiator" $ propRunInLogsStructure2 (propMultiInit ForMachine)
--, testProperty "multi, responder" $ propRunInLogsStructure (propMultiResp ForMachine)
]

propLogs :: LogFormat -> FilePath -> FilePath -> IO Property
propLogs format rootDir localSock = do
traceIO $ "rootDir: " <> rootDir
traceIO $ "localSock: " <> localSock
removeDirectoryContent rootDir

stopProtocols <- initProtocolsBrake
dpRequestors <- initDataPointRequestors
withAsync (doRunCardanoTracer (config rootDir localSock) stopProtocols dpRequestors) . const $
Expand All @@ -55,19 +50,26 @@ propLogs format rootDir localSock = do
sleep 0.5

doesDirectoryExist rootDir >>= \case
True ->
True -> do
traceIO "Logs, 1__"
-- ... and contains one node's subdir...
listDirectory rootDir >>= \case
[] -> false "root dir is empty"
(subDir:_) ->
withCurrentDirectory rootDir $
(subDir:_) -> do
traceIO "Logs, 2__"
withCurrentDirectory rootDir $ do
traceIO $ "Logs, 3__. rootDir " <> rootDir
-- ... with *.log-files inside...
listDirectory subDir >>= \case
[] -> false "subdir is empty"
logsAndSymLink ->
withCurrentDirectory subDir $
logsAndSymLink -> do
traceIO $ "Logs, 3__. subDir " <> subDir
withCurrentDirectory subDir $ do
traceIO $ "Logs, 4__"
case filter (isItLog format) logsAndSymLink of
[] -> false "subdir doesn't contain expected logs"
[] -> do
traceIO $ "Logs, 5__, logsAndSymLink " <> show logsAndSymLink
false "subdir doesn't contain expected logs"
logsWeNeed ->
if length logsWeNeed > 1
then
Expand Down
1 change: 0 additions & 1 deletion cardano-tracer/test/Cardano/Tracer/Test/Utils.hs
Expand Up @@ -23,7 +23,6 @@ propRunInLogsStructure
-> Property
propRunInLogsStructure testAction = ioProperty $ do
(rootDir, deleteDir) <- newTempDir
removeDirectoryContent rootDir
(localSock, _) <- newTempFile
let preparedLocalSock = prepareLocalSock localSock
testAction rootDir preparedLocalSock
Expand Down
3 changes: 2 additions & 1 deletion cardano-tracer/test/cardano-tracer-test.hs
Expand Up @@ -8,7 +8,8 @@ import qualified Cardano.Tracer.Test.Logs.Tests as Logs
main :: IO ()
main = defaultMain $
testGroup "cardano-tracer"
[ Logs.tests
[ Logs.testsLogs
, Logs.testsJson
--, DataPoint.tests
--, Network.tests
--, Queue.tests
Expand Down

0 comments on commit 3df0e37

Please sign in to comment.