transport_test.rs

Overview

This file contains asynchronous integration tests focused on evaluating network transport implementations, specifically the MsQuicTransport variant of the NetTransport trait. It orchestrates multiple nodes and optional proxies across data centers, simulating a gossip-based communication network. The tests verify message broadcasting and direct messaging functionality, as well as the reliability and performance of the transport layer under multi-threaded conditions.

The primary test function, test_msquic_transport, initializes and exercises the MsQuicTransport implementation by invoking the generic test_transport function. test_transport configures nodes and proxies, sets up gossip seeds, and runs multiple iterations to print network statistics, thereby validating the transport's behavior in a realistic multi-node environment.

The file also defines the NodeTest struct, which manages a node instance along with its associated producer and consumer threads. These threads simulate message production (broadcasting) and consumption (handling incoming messages and sending acknowledgments), respectively.


Classes and Structures

NodeTest

A generic struct parameterized by a type implementing NetTransport. It encapsulates a test node and manages two internal threads: one for producing broadcast messages and one for consuming incoming messages.

Fields

Methods

async fn start(config: NodeConfig, transport: Transport, node_count: usize) -> anyhow::Result<Self>

Starts a new NodeTest instance by creating a node with the provided configuration and transport implementation. It also launches the producer and consumer threads.

fn run_producer(state: Arc<NodeState>, chitchat: ChitchatRef, node_count: usize, node_id: String, broadcast_tx: NetBroadcastSender<Message>) -> anyhow::Result<()>

Continuously produces and broadcasts Message::Data messages after all nodes are live. It generates random data payloads and tracks unconfirmed messages in the node state.

fn run_consumer(state: Arc<NodeState>, direct_tx: NetDirectSender<String, Message>, incoming_rx: InstrumentedReceiver<IncomingMessage>, _peers_rx: tokio::sync::watch::Receiver<HashMap<String, Vec<PeerData>>>) -> anyhow::Result<()>

Consumes incoming messages, updating internal counters and sending acknowledgments for received data messages.


Functions

#[tokio::test(flavor = "multi_thread", worker_threads = 8)] #[ignore] async fn test_msquic_transport()

An asynchronous test function which invokes test_transport with an instance of MsQuicTransport. Marked to be ignored by default to prevent automatic execution in normal test runs.

async fn test_transport(transport: impl NetTransport + 'static)

Sets up a test environment with multiple nodes and proxies distributed across data centers, initializes gossip seeds, and runs a timed loop to print network statistics.


Important Implementation Details and Algorithms


Interaction with Other System Components


Visual Diagram

flowchart TD
A[test_msquic_transport] -->|calls| B[test_transport]
B --> C[Setup gossip seeds]
B --> D["Create proxies (optional)"]
B --> E[Create nodes with NodeTest::start]
E --> F["Spawn producer thread (run_producer)"]
E --> G["Spawn consumer thread (run_consumer)"]
F -->|broadcasts| H[NetBroadcastSender<Message>]
G -->|consumes| I[InstrumentedReceiver<IncomingMessage>]
G -->|sends ack| J[NetDirectSender<String, Message>]
F --> K[NodeState.unconfirmed & counters]
G --> K
B --> L[Print stats loop]

The diagram illustrates the test flow starting from the test_msquic_transport function, through the setup and creation of nodes and proxies, spawning of producer and consumer threads within each node, and the interaction between message channels and node states.


Usage Example of NodeTest::start

let config = NodeConfig::new(
    node_addr,
    gossip_addr,
    "node_0_0".to_string(),
    gossip_seeds.clone(),
);
let node_test = NodeTest::start(config, transport.clone(), total_node_count).await?;

This snippet creates and starts a new test node with the specified configuration and transport, ready to produce and consume test messages.


Related Topics