Skip to content

Commit 75dee26

Browse files
committed
label all the things!
1 parent 6a9e3c3 commit 75dee26

File tree

36 files changed

+131
-159
lines changed

36 files changed

+131
-159
lines changed

hydra-chain-observer/src/Hydra/Blockfrost/ChainObserver.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import Blockfrost.Client (
1111
import Blockfrost.Client qualified as Blockfrost
1212
import Control.Concurrent.Class.MonadSTM (
1313
MonadSTM (readTVarIO),
14-
newTVarIO,
1514
writeTVar,
1615
)
1716
import Control.Retry (RetryPolicyM, RetryStatus, constantDelay, retrying)
@@ -96,7 +95,7 @@ blockfrostClient tracer projectPath blockConfirmations = do
9695

9796
let blockHash = fromChainPoint chainPoint genesisBlockHash
9897

99-
stateTVar <- newTVarIO (blockHash, mempty)
98+
stateTVar <- newLabelledTVarIO "blockfrost-client-state" (blockHash, mempty)
10099
void $
101100
retrying (retryPolicy blockTime) shouldRetry $ \_ -> do
102101
loop tracer prj networkId blockTime observerHandler blockConfirmations stateTVar

hydra-cluster/bench/Bench/EndToEnd.hs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import Control.Concurrent.Class.MonadSTM (
1212
check,
1313
lengthTBQueue,
1414
modifyTVar,
15-
newTBQueueIO,
16-
newTVarIO,
1715
tryReadTBQueue,
1816
writeTBQueue,
1917
writeTVar,
@@ -83,7 +81,7 @@ bench startingNodeId timeoutSeconds workDir dataset = do
8381
putTextLn "Starting benchmark"
8482
let cardanoKeys = hydraNodeKeys dataset <&> \sk -> (getVerificationKey sk, sk)
8583
let hydraKeys = generateSigningKey . show <$> [1 .. toInteger (length cardanoKeys)]
86-
statsTvar <- newTVarIO mempty
84+
statsTvar <- newLabelledTVarIO "bench-stats" mempty
8785
scenarioData <- withOSStats workDir statsTvar $
8886
withCardanoNodeDevnet (contramap FromCardanoNode tracer) workDir $ \_ backend -> do
8987
let nodeSocket' = case Backend.getOptions backend of
@@ -261,13 +259,14 @@ withOSStats workDir tvar action =
261259
Nothing -> action
262260
Just _ ->
263261
withCreateProcess process{std_out = CreatePipe} $ \_stdin out _stderr _processHandle ->
264-
race
265-
( do
262+
raceLabelled
263+
( "os-stats-collect"
264+
, do
266265
-- Write the header
267266
atomically $ writeTVar tvar [" | Time | Used | Free | ", "|------------------------------------|------|------|"]
268267
collectStats tvar out
269268
)
270-
action
269+
("os-stats-action", action)
271270
>>= \case
272271
Left _ -> failure "dool process failed unexpectedly"
273272
Right a -> pure a
@@ -384,7 +383,7 @@ processTransactions clients clientDatasets = do
384383

385384
clientProcessDataset (ClientDataset{txSequence}, client) clientId = do
386385
let numberOfTxs = length txSequence
387-
submissionQ <- newTBQueueIO (fromIntegral numberOfTxs)
386+
submissionQ <- newLabelledTBQueueIO "submission" (fromIntegral numberOfTxs)
388387
registry <- newRegistry
389388
atomically $ forM_ txSequence $ writeTBQueue submissionQ
390389
( submitTxs client registry submissionQ
@@ -443,8 +442,8 @@ data Registry tx = Registry
443442
newRegistry ::
444443
IO (Registry Tx)
445444
newRegistry = do
446-
processedTxs <- newTVarIO mempty
447-
latestSnapshot <- newTVarIO 0
445+
processedTxs <- newLabelledTVarIO "registry-processed-txs" mempty
446+
latestSnapshot <- newLabelledTVarIO "registry-latest-snapshot" 0
448447
pure $ Registry{processedTxs, latestSnapshot}
449448

450449
submitTxs ::

hydra-cluster/src/CardanoNode.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ withCardanoNode tr stateDirectory args action = do
322322
withCreateProcess process{std_out = UseHandle out, std_err = CreatePipe} $
323323
\_stdin _stdout mError processHandle ->
324324
(`finally` cleanupSocketFile) $
325-
race (checkProcessHasNotDied "cardano-node" processHandle mError) waitForNode
325+
raceLabelled
326+
("check-cardano-node-process-not-died", checkProcessHasNotDied "cardano-node" processHandle mError)
327+
("wait-for-node", waitForNode)
326328
<&> either absurd id
327329
where
328330
CardanoNodeArgs{nodeSocket} = args

hydra-cluster/src/Hydra/Cluster/Scenarios.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,9 +1896,9 @@ threeNodesWithMirrorParty tracer workDir backend hydraScriptsTxId = do
18961896
-- N1 & N3 commit the same thing at the same time
18971897
-- XXX: one will fail but the head will still open
18981898
aliceUTxO <- seedFromFaucet backend aliceCardanoVk 1_000_000 (contramap FromFaucet tracer)
1899-
race_
1900-
(requestCommitTx n1 aliceUTxO >>= Backend.submitTransaction backend)
1901-
(requestCommitTx n3 aliceUTxO >>= Backend.submitTransaction backend)
1899+
raceLabelled_
1900+
("request-commit-tx-n1", requestCommitTx n1 aliceUTxO >>= Backend.submitTransaction backend)
1901+
("request-commit-tx-n3", requestCommitTx n3 aliceUTxO >>= Backend.submitTransaction backend)
19021902

19031903
-- N2 commits something
19041904
bobUTxO <- seedFromFaucet backend bobCardanoVk 1_000_000 (contramap FromFaucet tracer)

hydra-cluster/src/HydraNode.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Hydra.Prelude hiding (STM, delete)
77

88
import CardanoNode (cliQueryProtocolParameters)
99
import Control.Concurrent.Async (forConcurrently_)
10-
import Control.Concurrent.Class.MonadSTM (modifyTVar', newTVarIO, readTVarIO)
10+
import Control.Concurrent.Class.MonadSTM (modifyTVar', readTVarIO)
1111
import Control.Exception (Handler (..), IOException, catches)
1212
import Control.Lens ((?~))
1313
import Control.Monad.Class.MonadAsync (forConcurrently)
@@ -105,7 +105,7 @@ waitNoMatch delay client match = do
105105
-- | Wait up to some time for an API server output to match the given predicate.
106106
waitMatch :: HasCallStack => NominalDiffTime -> HydraClient -> (Aeson.Value -> Maybe a) -> IO a
107107
waitMatch delay client@HydraClient{tracer, hydraNodeId} match = do
108-
seenMsgs <- newTVarIO []
108+
seenMsgs <- newLabelledTVarIO "wait-match-seen-msgs" []
109109
timeout (realToFrac delay) (go seenMsgs) >>= \case
110110
Just x -> pure x
111111
Nothing -> do
@@ -453,9 +453,9 @@ withPreparedHydraNode tracer workDir hydraNodeId runOptions action =
453453

454454
withProcessTerm cmd $ \p -> do
455455
-- NOTE: exit code thread gets cancelled if 'action' terminates first
456-
race
457-
(collectAndCheckExitCode p)
458-
(withConnectionToNode tracer hydraNodeId action)
456+
raceLabelled
457+
("collect-check-process-exit-code", collectAndCheckExitCode p)
458+
("with-connection-to-node", withConnectionToNode tracer hydraNodeId action)
459459
<&> either absurd id
460460
where
461461
collectAndCheckExitCode p = do

hydra-cluster/test/Test/BlockfrostChainSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Hydra.Prelude
66
import Test.Hydra.Prelude
77

88
import Cardano.Api.UTxO qualified as UTxO
9-
import Control.Concurrent.STM (newEmptyTMVarIO, takeTMVar)
9+
import Control.Concurrent.STM (takeTMVar)
1010
import Control.Concurrent.STM.TMVar (putTMVar)
1111
import Control.Exception (IOException)
1212
import Hydra.Chain (
@@ -164,7 +164,7 @@ withBlockfrostChainTest tracer config party action = do
164164
_ -> failure $ "unexpected chainBackendOptions: " <> show chainBackendOptions
165165
otherConfig -> failure $ "unexpected chainConfig: " <> show otherConfig
166166
ctx <- loadChainContext backend configuration party
167-
eventMVar <- newEmptyTMVarIO
167+
eventMVar <- newLabelledEmptyTMVarIO "blockfrost-chain-events"
168168

169169
let callback event = atomically $ putTMVar eventMVar event
170170

hydra-cluster/test/Test/ChainObserverSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Test.Hydra.Prelude
1111

1212
import Cardano.Api.UTxO qualified as UTxO
1313
import CardanoNode (NodeLog, withCardanoNodeDevnet)
14-
import Control.Concurrent.Class.MonadSTM (modifyTVar', newTVarIO, readTVarIO)
14+
import Control.Concurrent.Class.MonadSTM (modifyTVar', readTVarIO)
1515
import Control.Lens ((^?))
1616
import Data.Aeson as Aeson
1717
import Data.Aeson.Lens (key, _JSON, _String)
@@ -114,7 +114,7 @@ chainObserverSees observer txType headId =
114114

115115
awaitMatch :: HasCallStack => ChainObserverHandle -> DiffTime -> (Aeson.Value -> Maybe a) -> IO a
116116
awaitMatch chainObserverHandle delay f = do
117-
seenMsgs <- newTVarIO []
117+
seenMsgs <- newLabelledTVarIO "await-match-seen-msgs" []
118118
timeout delay (go seenMsgs) >>= \case
119119
Just x -> pure x
120120
Nothing -> do

hydra-cluster/test/Test/DirectChainSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import CardanoClient (
1212
waitForUTxO,
1313
)
1414
import CardanoNode (NodeLog, withCardanoNodeDevnet)
15-
import Control.Concurrent.STM (newEmptyTMVarIO, takeTMVar)
15+
import Control.Concurrent.STM (takeTMVar)
1616
import Control.Concurrent.STM.TMVar (putTMVar)
1717
import Control.Lens ((<>~))
1818
import Data.List.Split (splitWhen)
@@ -548,7 +548,7 @@ withDirectChainTest tracer config party action = do
548548
_ -> failure $ "unexpected chainBackendOptions: " <> show chainBackendOptions
549549
otherConfig -> failure $ "unexpected chainConfig: " <> show otherConfig
550550
ctx <- loadChainContext backend configuration party
551-
eventMVar <- newEmptyTMVarIO
551+
eventMVar <- newLabelledEmptyTMVarIO "direct-chain-events"
552552

553553
let callback event = atomically $ putTMVar eventMVar event
554554

hydra-cluster/test/Test/Hydra/Cluster/MithrilSpec.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Test.Hydra.Cluster.MithrilSpec where
33
import Hydra.Prelude
44
import Test.Hydra.Prelude
55

6-
import Control.Concurrent.Class.MonadSTM (newTVarIO, readTVarIO)
6+
import Control.Concurrent.Class.MonadSTM (readTVarIO)
77
import Control.Lens ((^?))
88
import Data.Aeson.Lens (key)
99
import Hydra.Cluster.Fixture (KnownNetwork (..))
@@ -24,9 +24,9 @@ spec = parallel $ do
2424
withTempDir ("mithril-download-" <> show network) $ \tmpDir -> do
2525
let dbPath = tmpDir </> "db"
2626
doesDirectoryExist dbPath `shouldReturn` False
27-
race_
28-
(downloadLatestSnapshotTo tracer network tmpDir)
29-
(waitForDownload getTraces)
27+
raceLabelled_
28+
("download-latest-snapshot-to", downloadLatestSnapshotTo tracer network tmpDir)
29+
("wait-for-download", waitForDownload getTraces)
3030

3131
-- | Wait for the 'StdErr' message to indicate it starts downloading.
3232
waitForDownload :: HasCallStack => IO [Envelope MithrilLog] -> IO ()
@@ -45,6 +45,6 @@ waitForDownload getTraces = do
4545
-- traces captured.
4646
captureTracer :: Text -> IO (Tracer IO a, IO [Envelope a])
4747
captureTracer namespace = do
48-
traces <- newTVarIO []
48+
traces <- newLabelledTVarIO "capture-tracer" []
4949
let tracer = traceInTVar traces namespace
5050
pure (tracer, readTVarIO traces)

hydra-cluster/test/Test/OfflineChainSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Test.OfflineChainSpec where
55
import Hydra.Prelude
66
import Test.Hydra.Prelude
77

8-
import Control.Concurrent.Class.MonadSTM (modifyTVar', newTChanIO, newTVarIO, readTChan, readTVarIO, writeTChan)
8+
import Control.Concurrent.Class.MonadSTM (modifyTVar', newTChanIO, readTChan, readTVarIO, writeTChan)
99
import Control.Lens ((^?))
1010
import Data.Aeson qualified as Aeson
1111
import Data.Aeson.Lens (key, _Number)
@@ -102,7 +102,7 @@ monitorCallbacks = do
102102
-- XXX: Dry with the other waitMatch utilities
103103
waitMatch :: (HasCallStack, ToJSON a) => IO a -> DiffTime -> (a -> Maybe b) -> IO b
104104
waitMatch waitNext seconds match = do
105-
seen <- newTVarIO []
105+
seen <- newLabelledTVarIO "wait-match-seen" []
106106
timeout seconds (go seen) >>= \case
107107
Just x -> pure x
108108
Nothing -> do

0 commit comments

Comments
 (0)