Skip to content

Commit

Permalink
Improve error message if hydra-node crashes
Browse files Browse the repository at this point in the history
By delaying the connection exception based errors on the websocket
client of the test driver, we improve the error output in cases where
other assertions provide more info. For example, checkProcessHasNotDied
prints the stderr of the crashed hydra-node.

Co-authored: Sebastian Nagel <[email protected]>
  • Loading branch information
ch1bo committed Mar 4, 2024
1 parent ab45d09 commit 563ac81
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions hydra-cluster/src/HydraNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Hydra.Network qualified as Network
import Hydra.Options (ChainConfig (..), DirectChainConfig (..), LedgerConfig (..), RunOptions (..), defaultDirectChainConfig, toArgs)
import Network.HTTP.Req (GET (..), HttpException, JsonResponse, NoReqBody (..), POST (..), ReqBodyJson (..), defaultHttpConfig, responseBody, runReq, (/:))
import Network.HTTP.Req qualified as Req
import Network.WebSockets (Connection, HandshakeException, receiveData, runClient, sendClose, sendTextData)
import Network.WebSockets (Connection, ConnectionException, HandshakeException, receiveData, runClient, sendClose, sendTextData)
import System.FilePath ((<.>), (</>))
import System.IO.Temp (withSystemTempDirectory)
import System.Info (os)
Expand Down Expand Up @@ -62,7 +62,14 @@ send HydraClient{tracer, hydraNodeId, connection} v = do

waitNext :: HasCallStack => HydraClient -> IO Aeson.Value
waitNext HydraClient{connection} = do
bytes <- receiveData connection
-- NOTE: We delay on connection errors to give other assertions the chance to
-- provide more detail (e.g. checkProcessHasNotDied) before this fails.
bytes <-
try (receiveData connection) >>= \case
Left (err :: ConnectionException) -> do
threadDelay 1
failure $ "waitNext: " <> show err
Right msg -> pure msg
case Aeson.eitherDecode' bytes of
Left err -> failure $ "WaitNext failed to decode msg: " <> err
Right value -> pure value
Expand Down

0 comments on commit 563ac81

Please sign in to comment.