Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: test_run_mesh_client documentation #1697

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions iroh-net/src/derp/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,20 @@ mod tests {
Ok(())
}

/// In the real world, when we create a local server, that server spawn a [`MeshClient`] for every remote server it was instructed to mesh with (we give it a list of derp servers to connect to via a config file). The connection with the local server and its [`MeshClient`] is managed by the [`PacketForwarderHandler`].
///
/// The [`MeshClient`] receives a message from the remote server every time that server connects to a new iroh node. This message includes the [`PublicKey`] of the node it has just connected to.
/// `test_run_mesh_client` tests the interactions between a remote server and a [`MeshClient`], using the [`PacketForwardHandler`] to inspect that we are getting the expected [`AddPacketForwarder`] messages from the remote.
/// to test this we:
/// - set up a remote server
/// - create a mesh client (by adding the same mesh key that the server has) and give it the url of the server
/// - create a `PacketForwardHandler` by hand (usually done by the local server as a bridge between the MeshClient and the local server)
/// - mesh the mesh client with the server
/// - ensure it's meshed when we received a `MeshClientEvent::Meshed` message
/// - create a normal client and connect it to the server
/// - test we receive an `AddPacketForwarder` message from the server. This translates to "Add me as a packet forwarder for the given key"
/// - close the normal client
/// - tet that we receive a `RemovePacketForwarder` message from the server
#[tokio::test]
async fn test_run_mesh_client() -> Result<()> {
tracing_subscriber::registry()
Expand Down Expand Up @@ -1549,8 +1563,6 @@ mod tests {
info!("dropped normal client, waiting for packet forwarder to be removed");

// wait for "remove packet forwarder" message
// potentially may get another `PeerPresent` message about ourselves, this is
// non deterministic
match server_channel_r.recv().await.unwrap() {
ServerMessage::RemovePacketForwarder(key) => {
debug!("received `ServerMessage::RemovePacketForwarder` for {key:?}");
Expand Down