Skip to content

Commit

Permalink
No invalid trace test and monadic assertion error
Browse files Browse the repository at this point in the history
- This way an assertion is not a pure exception evaluated when printing
an `io-sim` test case, but a simulation error. Note that this will hide
such exceptions from simulation. To test that such assertion do not
happen we can analyse trace.

- Check that `TrUnexpectedlyMissingConnectionState` is not logged.
This is an initial part of #3465.

Authors: Marcin Szamotulski
  • Loading branch information
bolt12 authored and coot committed Nov 11, 2021
1 parent 7bd91a3 commit e89de62
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,10 @@ withConnectionManager ConnectionManagerArguments {
)

case mConnVar of
Left Unknown ->
assert False $ do
traceWith tracer (TrUnexpectedlyMissingConnectionState connId)
traceCounters stateVar
Left Unknown -> do
traceWith tracer (TrUnexpectedlyMissingConnectionState connId)
_ <- evaluate (assert False)
traceCounters stateVar

Left connState@Known {} -> do
traceWith trTracer (TransitionTrace peerAddr
Expand Down
53 changes: 53 additions & 0 deletions ouroboros-network-framework/test/Test/Ouroboros/Network/Server2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ tests =
prop_never_above_hardlimit
, testProperty "connection_manager_valid_transitions"
prop_connection_manager_valid_transitions
, testProperty "connection_manager_no_invalid_traces"
prop_connection_manager_no_invalid_traces
, testProperty "inbound_governor_valid_transitions"
prop_inbound_governor_valid_transitions
, testProperty "inbound_governor_no_unsupported_state"
Expand Down Expand Up @@ -2036,6 +2038,57 @@ prop_connection_manager_valid_transitions serverAcc (ArbDataFlow dataFlow)
(Script (toBearerInfo absBi :| [noAttenuation]))
maxAcceptedConnectionsLimit l

-- | Property wrapping `multinodeExperiment`.
--
-- Note: this test validates that we do not get undesired traces, such as
-- TrUnexpectedlyMissingConnectionState in connection manager.
--
prop_connection_manager_no_invalid_traces :: Int
-> ArbDataFlow
-> AbsBearerInfo
-> MultiNodeScript Int TestAddr
-> Property
prop_connection_manager_no_invalid_traces serverAcc (ArbDataFlow dataFlow)
absBi (MultiNodeScript l) =
let trace = runSimTrace sim

evsCMT :: Trace (SimResult ())
(ConnectionManagerTrace
SimAddr
(ConnectionHandlerTrace
UnversionedProtocol
DataFlowProtocolData))
evsCMT = traceWithNameTraceEvents trace

in tabulate "ConnectionEvents" (map showCEvs l)
. counterexample (intercalate "\n"
[ "========== Script =========="
, ppScript (MultiNodeScript l)
, "========== ConnectionManager Events =========="
, Trace.ppTrace show show evsCMT
, "========== Simulation Trace =========="
, ppTrace trace
])
. getAllProperty
. bifoldMap
( \ case
MainReturn {} -> mempty
v -> AllProperty (counterexample (show v) False)
)
( \ tr
-> case tr of
TrUnexpectedlyMissingConnectionState _ ->
AllProperty (counterexample (show tr) False)
_ ->
mempty
)
$ evsCMT
where
sim :: IOSim s ()
sim = multiNodeSim serverAcc dataFlow
(Script (toBearerInfo absBi :| [noAttenuation]))
maxAcceptedConnectionsLimit l

-- | Property wrapping `multinodeExperiment`.
--
-- Note: this test validates the order of connection manager state changes.
Expand Down

0 comments on commit e89de62

Please sign in to comment.