Skip to content

Commit 0f1eb47

Browse files
committed
trace-dispatcher: forwarder-test with unique message ids
1 parent ef258b1 commit 0f1eb47

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

Diff for: trace-dispatcher/bench/trace-dispatcher-bench.hs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Cardano.Logging.Test.Tracer
1010
import Cardano.Logging.Test.Types
1111
import System.Remote.Monitoring (forkServer)
1212

13-
import Debug.Trace
1413

1514
-- Can be run with:
1615
-- cabal bench trace-dispatcher-bench --benchmark-option='-o benchmark-trace.html'

Diff for: trace-dispatcher/test/Cardano/Logging/ForwardingStressTest/Script.hs

+19-13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ import Cardano.Logging.Test.Messages
3737
import Cardano.Logging.Test.Types
3838

3939

40+
import Debug.Trace
41+
42+
4043
data TestSetup a
4144
= TestSetup
4245
{ tsTime :: !(a Double)
@@ -111,7 +114,8 @@ runScriptForwarding ::
111114
-> Trace IO FormattedMessage
112115
-> IORef Int
113116
-> Property
114-
runScriptForwarding TestSetup{..} fwdTracer stdoutTracer' accumulationCounter = do
117+
runScriptForwarding ts@TestSetup{..} fwdTracer stdoutTracer' accumulationCounter =
118+
trace ("Test setup " ++ show ts) $ do
115119
let generator :: Gen [Script] = vectorOf (runIdentity tsThreads) $
116120
case runIdentity tsMessages of
117121
Nothing -> scale (* 1000) arbitrary
@@ -127,14 +131,16 @@ runScriptForwarding TestSetup{..} fwdTracer stdoutTracer' accumulationCounter =
127131
severityForMessage
128132
privacyForMessage
129133
configureTracers simpleTestConfig docMessage [tr]
130-
let scripts' = map (\ (Script sc) ->
131-
Script (sort sc)) scripts
132-
scripts'' = map (\ (Script sc) ->
133-
Script (withMessageIds 0 sc)) scripts'
134-
scripts''' = map (\ (Script sc) ->
135-
Script $ map (withTimeFactor (runIdentity tsTime)) sc) scripts''
136-
scripts'''' = map (\ (Script sc) ->
137-
Script $ filter (\(ScriptedMessage _ msg) -> namesForMessage msg /= ["Message2"]) sc) scripts'''
134+
let scripts' = map (\ (Script sc) -> Script
135+
$ filter (\(ScriptedMessage _ msg) ->
136+
namesForMessage msg /= ["Message2"]) sc) scripts
137+
scripts'' = map (\ (Script sc) -> Script (sort sc)) scripts'
138+
scripts''' = zipWith (\ (Script sc) ind -> Script (
139+
withMessageIds (runIdentity tsThreads) ind sc)) scripts'' [0..]
140+
scripts'''' = map (\ (Script sc) -> Script
141+
$ map (withTimeFactor (runIdentity tsTime)) sc) scripts'''
142+
143+
138144
-- putStrLn ("runTest " ++ show scripts)
139145
children :: MVar [MVar (Either SomeException ())] <- newMVar []
140146
mapM_ (\sc -> forkChild children (playIt sc tr 0.0)) scripts''''
@@ -150,7 +156,7 @@ runScriptForwarding TestSetup{..} fwdTracer stdoutTracer' accumulationCounter =
150156
let numMsg = sum (map (\ (Script sc) -> length sc) scripts'''')
151157
in if numMsg > 0 then do
152158
-- TODO mutiple files
153-
contents <- readFile "/tmp/cardano-tracer-logs/tmp-tracersock@0/node.json"
159+
contents <- readFile "/tmp/cardano-forwarder-test-logs/tmp-tracersock@0/node.json"
154160
let lineLength = length (lines contents) - 1
155161
putStrLn $ "Line length " ++ show lineLength
156162
putStrLn $ "Msg length " ++ show numMsg
@@ -198,12 +204,12 @@ playIt (Script (ScriptedMessage d1 m1 : rest)) tr d = do
198204
-- MessageId gives the id to start with.
199205
-- Returns a tuple with the messages with ids and
200206
-- the successor of the last used messageId
201-
withMessageIds :: MessageID -> [ScriptedMessage] -> [ScriptedMessage]
202-
withMessageIds mid sMsgs = go mid sMsgs []
207+
withMessageIds :: Int -> MessageID -> [ScriptedMessage] -> [ScriptedMessage]
208+
withMessageIds numThreads mid sMsgs = go mid sMsgs []
203209
where
204210
go _mid' [] acc = reverse acc
205211
go mid' (ScriptedMessage time msg : tl) acc =
206-
go (mid' + 1) tl (ScriptedMessage time (setMessageID msg mid') : acc)
212+
go (mid' + numThreads) tl (ScriptedMessage time (setMessageID msg mid') : acc)
207213

208214
withTimeFactor :: Double -> ScriptedMessage -> ScriptedMessage
209215
withTimeFactor factor (ScriptedMessage time msg) =

Diff for: trace-dispatcher/test/Cardano/Logging/Test/Types.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ instance LogFormatting Message where
3939
]
4040
forMachine _dtal (Message3 mid d) =
4141
mconcat [ "kind" .= String "Message3"
42-
, "mid" .= String (showT mid)
42+
, "mid" .= String ("<" <> showT mid <> ">")
4343
, "workload" .= String (showT d)
4444
]
4545
forHuman (Message1 mid i) =

Diff for: trace-dispatcher/test/cardano-tracer-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ network:
44
tag: AcceptAt
55
contents: "/tmp/tracer.sock"
66
logging:
7-
- logRoot: "/tmp/cardano-tracer-logs"
7+
- logRoot: "/tmp/cardano-forwarder-test-logs"
88
logMode: FileMode
99
logFormat: ForMachine

Diff for: trace-dispatcher/test/trace-dispatcher-test.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Ouroboros.Network.NodeToClient (withIOManager)
2323
main :: IO ()
2424
main = do
2525
ts <- getTestSetup
26-
let logPath = "/tmp/cardano-tracer-logs"
26+
let logPath = "/tmp/cardano-forwarder-test-logs"
2727
fe <- fileExist logPath
2828
when fe
2929
(removeDirectoryRecursive logPath)

0 commit comments

Comments
 (0)