mirror of
https://github.com/corda/corda.git
synced 2025-02-20 09:26:41 +00:00
Documents waitQuiescent. Explains why it is important. (#3787)
* Update api-testing.rst * Warning regarding using threadPerNode * Corrects JavaDocs. Adds message to .
This commit is contained in:
parent
fffa063803
commit
f3392e31d2
@ -201,19 +201,22 @@ CorDapps specific to their role in the network.
|
||||
|
||||
Running the network
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
When using a ``MockNetwork``, you must be careful to ensure that all the nodes have processed all the relevant messages
|
||||
before making assertions about the result of performing some action. For example, if you start a flow to update the ledger
|
||||
but don't wait until all the nodes involved have processed all the resulting messages, your nodes' vaults may not be in
|
||||
the state you expect.
|
||||
|
||||
Regular Corda nodes automatically process received messages. When using a ``MockNetwork`` with
|
||||
``networkSendManuallyPumped`` set to ``false``, you must manually initiate the processing of received messages.
|
||||
|
||||
When ``networkSendManuallyPumped`` is set to ``false``, you must manually initiate the processing of received messages.
|
||||
You manually process received messages as follows:
|
||||
|
||||
* ``StartedMockNode.pumpReceive`` to process a single message from the node's queue
|
||||
|
||||
* ``MockNetwork.runNetwork`` to process all the messages in every node's queue. This may generate additional messages
|
||||
that must in turn be processed
|
||||
|
||||
* ``network.runNetwork(-1)`` (the default in Kotlin) will exchange messages until there are no further messages to
|
||||
* ``StartedMockNode.pumpReceive()`` processes a single message from the node's queue
|
||||
* ``MockNetwork.runNetwork()`` processes all the messages in every node's queue until there are no further messages to
|
||||
process
|
||||
|
||||
When ``networkSendManuallyPumped`` is set to ``true``, nodes will automatically process the messages they receive. You
|
||||
can block until all messages have been processed using ``MockNetwork.waitQuiescent()``.
|
||||
|
||||
.. warning:: If ``threadPerNode`` is set to ``true``, ``networkSendManuallyPumped`` must also be set to ``true``.
|
||||
|
||||
Running flows
|
||||
^^^^^^^^^^^^^
|
||||
|
@ -71,7 +71,7 @@ data class MockNodeParameters constructor(
|
||||
* Immutable builder for configuring a [MockNetwork]. Kotlin users can also use named parameters to the constructor
|
||||
* of [MockNetwork], which is more convenient.
|
||||
*
|
||||
* @property networkSendManuallyPumped If true then messages will not be routed from sender to receiver until you use
|
||||
* @property networkSendManuallyPumped If false then messages will not be routed from sender to receiver until you use
|
||||
* the [MockNetwork.runNetwork] method. This is useful for writing single-threaded unit test code that can examine the
|
||||
* state of the mock network before and after a message is sent, without races and without the receiving node immediately
|
||||
* sending a response. The default is false, so you must call runNetwork.
|
||||
@ -280,7 +280,7 @@ inline fun <reified F : FlowLogic<*>> StartedMockNode.registerResponderFlow(
|
||||
* @property cordappPackages A [List] of cordapp packages to scan for any cordapp code, e.g. contract verification code, flows and services.
|
||||
* @property defaultParameters A [MockNetworkParameters] object which contains the same parameters as the constructor, provided
|
||||
* as a convenience for Java users.
|
||||
* @property networkSendManuallyPumped If true then messages will not be routed from sender to receiver until you use
|
||||
* @property networkSendManuallyPumped If false then messages will not be routed from sender to receiver until you use
|
||||
* the [MockNetwork.runNetwork] method. This is useful for writing single-threaded unit test code that can examine the
|
||||
* state of the mock network before and after a message is sent, without races and without the receiving node immediately
|
||||
* sending a response. The default is false, so you must call runNetwork.
|
||||
|
@ -506,7 +506,8 @@ open class InternalMockNetwork(defaultParameters: MockNetworkParameters = MockNe
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun runNetwork(rounds: Int = -1) {
|
||||
check(!networkSendManuallyPumped)
|
||||
check(!networkSendManuallyPumped) { "MockNetwork.runNetwork() should only be used when networkSendManuallyPumped == false. " +
|
||||
"You can use MockNetwork.waitQuiescent() to wait for all the nodes to process all the messages on their queues instead." }
|
||||
fun pumpAll() = messagingNetwork.endpoints.map { it.pumpReceive(false) }
|
||||
|
||||
if (rounds == -1) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user