test_hot_reload.rs

Overview

This file implements a test harness for evaluating the hot reload capabilities of a networked node system using the MsQuicTransport transport layer. It defines a HotReloadNode struct that wraps a network node instance with facilities to receive, store, and inspect messages asynchronously. The main functionality centers around starting nodes, receiving messages via an asynchronous Tokio task, and verifying message propagation behavior in a multi-node setup. The file includes a Tokio integration test test_hot_reload that initializes multiple nodes, sends broadcast messages, and asserts correct message delivery and reception.

Entities and Functionality

HotReloadNode

A wrapper struct representing a network node instance configured for hot reloading tests. It manages internal node state, message sending channels, and a thread dedicated to receiving incoming messages.

Fields:

Methods:

async fn start(transport: MsQuicTransport, config: NodeConfig) -> Self

Starts a HotReloadNode instance asynchronously.

fn received_messages(&self) -> Vec<Message>

Returns a clone of the vector containing all messages received by this node.

fn run_receiver(receiver: String, message_rx: InstrumentedReceiver<IncomingMessage>, received_messages: Arc<std::sync::Mutex<Vec<Message>>>)

Continuously receives and processes incoming messages for a node, running in a separate thread.

#[tokio::test] async fn test_hot_reload()

An integration test that verifies hot reload message passing functionality among multiple nodes.

Implementation Details and Algorithms

Interaction with Other System Components

Visual Diagram: Structure and Workflow of HotReloadNode

classDiagram
class HotReloadNode {
-_node: Node<MsQuicTransport>
-_direct_tx: NetDirectSender
+broadcast_tx: NetBroadcastSender
-_peers_rx: watch::Receiver<HashMap>
-received_messages: Arc<Mutex<Vec<Message>>>
-_receiver_task: JoinHandle
+start()
+received_messages()
-run_receiver()
}
HotReloadNode --> Node
HotReloadNode --> NetDirectSender
HotReloadNode --> NetBroadcastSender
HotReloadNode --> "Arc<Mutex<Vec<Message>>>"
HotReloadNode --> "Thread (Receiver Task)"

This class diagram shows the main components of the HotReloadNode struct, highlighting its fields and methods, and the relation to the underlying Node, message channels, thread-safe message storage, and the receiver task thread.


For further exploration of asynchronous programming patterns, concurrency primitives, and transport abstractions referenced here, see topics on Asynchronous Rust, Concurrency and Synchronization, and Network Transport Layers. The interaction between message channels and node lifecycle is related to Pub/Sub Messaging and Node Configuration.