Skip to content

Commit a465941

Browse files
committed
replace concurrently with labeled variant
1 parent f34b66f commit a465941

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

hydra-cluster/bench/Bench/EndToEnd.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,12 @@ processTransactions clients clientDatasets = do
386386
submissionQ <- newLabelledTBQueueIO "submission" (fromIntegral numberOfTxs)
387387
registry <- newRegistry
388388
atomically $ forM_ txSequence $ writeTBQueue submissionQ
389-
( submitTxs client registry submissionQ
390-
`concurrently_` waitForAllConfirmations client registry (Set.fromList $ map txId txSequence)
391-
`concurrently_` progressReport (hydraNodeId client) clientId numberOfTxs submissionQ
389+
concurrentlyLabelled_
390+
("submit-txs", submitTxs client registry submissionQ)
391+
( "confirm-txs"
392+
, concurrentlyLabelled_
393+
("wait-for-all-confirmations", waitForAllConfirmations client registry (Set.fromList $ map txId txSequence))
394+
("progress-report", progressReport (hydraNodeId client) clientId numberOfTxs submissionQ)
392395
)
393396
`catch` \(HUnitFailure sourceLocation reason) ->
394397
putStrLn ("Something went wrong while waiting for all confirmations: " <> formatLocation sourceLocation <> ": " <> formatFailureReason reason)

hydra-cluster/test/Test/EndToEndSpec.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,9 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
676676
withClusterTempDir $ \tmpDir -> do
677677
withBackend (contramap FromCardanoNode tracer) tmpDir $ \_ backend -> do
678678
hydraScriptsTxId <- publishHydraScriptsAs backend Faucet
679-
concurrently_
680-
(initAndClose tmpDir tracer 0 hydraScriptsTxId backend)
681-
(initAndClose tmpDir tracer 1 hydraScriptsTxId backend)
679+
concurrentlyLabelled_
680+
("init-and-close-0", initAndClose tmpDir tracer 0 hydraScriptsTxId backend)
681+
("init-and-close-1", initAndClose tmpDir tracer 1 hydraScriptsTxId backend)
682682

683683
it "alice inits a Head with incorrect keys preventing bob from observing InitTx" $ \tracer ->
684684
failAfter 60 $

hydra-node/test/Hydra/API/ServerSpec.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ spec =
9696
semaphore <- newLabelledTVarIO "semaphore" 0
9797
withAsyncLabelled
9898
( "concurrent-test-clients"
99-
, concurrently_
100-
(withClient port "/" $ testClient queue semaphore)
101-
(withClient port "/" $ testClient queue semaphore)
99+
, concurrentlyLabelled_
100+
("concurrent-test-client-1", withClient port "/" $ testClient queue semaphore)
101+
("concurrent-test-client-2", withClient port "/" $ testClient queue semaphore)
102102
)
103103
$ \_ -> do
104104
waitForClients semaphore
@@ -131,9 +131,9 @@ spec =
131131
semaphore <- newLabelledTVarIO "semaphore" 0
132132
withAsyncLabelled
133133
( "concurrent-test-clients"
134-
, concurrently_
135-
(withClient port "/?history=yes" $ testClient queue1 semaphore)
136-
(withClient port "/?history=yes" $ testClient queue2 semaphore)
134+
, concurrentlyLabelled_
135+
("concurrent-test-client-queue1", withClient port "/?history=yes" $ testClient queue1 semaphore)
136+
("concurrent-test-client-queue2", withClient port "/?history=yes" $ testClient queue2 semaphore)
137137
)
138138
$ \_ -> do
139139
waitForClients semaphore

hydra-node/test/Hydra/Events/S3Spec.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ spec = do
5353

5454
it "allows concurrent usage" $ \bucketName -> do
5555
withS3EventStore bucketName $ \(source, sink) -> do
56-
concurrently_
57-
(putEvent sink 123)
58-
(putEvent sink 456)
56+
concurrentlyLabelled_
57+
("concurrent-put-event-123", putEvent sink 123)
58+
("concurrent-put-event-456", putEvent sink 456)
5959
getEvents source `shouldReturn` [123, 456 :: EventId]
6060

6161
it "supports multiple instances" $ \bucketName ->

hydra-node/test/Hydra/Events/UDPSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ spec = do
2626
it "allows concurrent usage" $ do
2727
withFreePort $ \port -> do
2828
withUDPEventSink @EventId "0.0.0.0" (show port) $ \EventSink{putEvent} -> do
29-
concurrently_ (putEvent 123) (putEvent 456)
29+
concurrentlyLabelled_ ("put-event-123", putEvent 123) ("put-event-456", putEvent 456)
3030

3131
it "supports multiple instances" $ do
3232
withFreePort $ \port -> do

hydra-prelude/src/Hydra/Prelude.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ module Hydra.Prelude (
4848
newLabelledTQueueIO,
4949
newLabelledEmptyTMVarIO,
5050
labelMyThread,
51+
concurrentlyLabelled,
52+
concurrentlyLabelled_,
5153
raceLabelled,
5254
raceLabelled_,
5355
withAsyncLabelled,
@@ -363,3 +365,12 @@ raceLabelled_ = (void .) . raceLabelled
363365

364366
withAsyncLabelled :: MonadAsync m => (String, m a) -> (Async m a -> m b) -> m b
365367
withAsyncLabelled (lbl, ma) = withAsync (labelMyThread lbl >> ma)
368+
369+
concurrentlyLabelled :: (MonadThread m, MonadAsync m) => (String, m a) -> (String, m b) -> m (a, b)
370+
concurrentlyLabelled (lblA, mA) (lblB, mB) =
371+
concurrently
372+
(labelMyThread lblA >> mA)
373+
(labelMyThread lblB >> mB)
374+
375+
concurrentlyLabelled_ :: (MonadThread m, MonadAsync m) => (String, m a) -> (String, m b) -> m ()
376+
concurrentlyLabelled_ = (void .) . concurrentlyLabelled

0 commit comments

Comments
 (0)