mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-12 04:11:09 +00:00
cargo fmt
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
use test_utils::{
|
||||
feed_message_de::{ FeedMessage, NodeDetails },
|
||||
server::{ self, Server },
|
||||
assert_contains_matches
|
||||
};
|
||||
use common::node_types::BlockHash;
|
||||
use serde_json::json;
|
||||
use std::time::Duration;
|
||||
use common::node_types::{ BlockHash };
|
||||
use test_utils::{
|
||||
assert_contains_matches,
|
||||
feed_message_de::{FeedMessage, NodeDetails},
|
||||
server::{self, Server},
|
||||
};
|
||||
|
||||
async fn cargo_run_server() -> Server {
|
||||
Server::start(server::StartOpts {
|
||||
shard_command: server::cargo_run_commands::telemetry_shard().expect("valid shard command"),
|
||||
core_command: server::cargo_run_commands::telemetry_core().expect("valid core command")
|
||||
}).await.unwrap()
|
||||
core_command: server::cargo_run_commands::telemetry_core().expect("valid core command"),
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -23,7 +25,11 @@ async fn feed_sent_version_on_connect() {
|
||||
|
||||
// Expect a version response of 31:
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
assert_eq!(feed_messages, vec![FeedMessage::Version(31)], "expecting version");
|
||||
assert_eq!(
|
||||
feed_messages,
|
||||
vec![FeedMessage::Version(31)],
|
||||
"expecting version"
|
||||
);
|
||||
|
||||
// Tidy up:
|
||||
server.shutdown().await;
|
||||
@@ -41,7 +47,12 @@ async fn feed_ping_responded_to_with_pong() {
|
||||
|
||||
// Expect a pong response:
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
assert!(feed_messages.contains(&FeedMessage::Pong { msg: "hello!".to_owned() }), "Expecting pong");
|
||||
assert!(
|
||||
feed_messages.contains(&FeedMessage::Pong {
|
||||
msg: "hello!".to_owned()
|
||||
}),
|
||||
"Expecting pong"
|
||||
);
|
||||
|
||||
// Tidy up:
|
||||
server.shutdown().await;
|
||||
@@ -54,57 +65,56 @@ async fn feed_add_and_remove_node() {
|
||||
let shard_id = server.add_shard().await.unwrap();
|
||||
|
||||
// Connect a node to the shard:
|
||||
let (mut node_tx, _node_rx) = server.get_shard(shard_id)
|
||||
let (mut node_tx, _node_rx) = server
|
||||
.get_shard(shard_id)
|
||||
.unwrap()
|
||||
.connect()
|
||||
.await
|
||||
.expect("can connect to shard");
|
||||
|
||||
// Send a "system connected" message:
|
||||
node_tx.send_json_text(json!(
|
||||
{
|
||||
"id":1,
|
||||
"ts":"2021-07-12T10:37:47.714666+01:00",
|
||||
"payload": {
|
||||
"authority":true,
|
||||
"chain":"Local Testnet",
|
||||
"config":"",
|
||||
"genesis_hash": BlockHash::from_low_u64_ne(1),
|
||||
"implementation":"Substrate Node",
|
||||
"msg":"system.connected",
|
||||
"name":"Alice",
|
||||
"network_id":"12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp",
|
||||
"startup_time":"1625565542717",
|
||||
"version":"2.0.0-07a1af348-aarch64-macos"
|
||||
},
|
||||
}
|
||||
)).await.unwrap();
|
||||
node_tx
|
||||
.send_json_text(json!(
|
||||
{
|
||||
"id":1,
|
||||
"ts":"2021-07-12T10:37:47.714666+01:00",
|
||||
"payload": {
|
||||
"authority":true,
|
||||
"chain":"Local Testnet",
|
||||
"config":"",
|
||||
"genesis_hash": BlockHash::from_low_u64_ne(1),
|
||||
"implementation":"Substrate Node",
|
||||
"msg":"system.connected",
|
||||
"name":"Alice",
|
||||
"network_id":"12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp",
|
||||
"startup_time":"1625565542717",
|
||||
"version":"2.0.0-07a1af348-aarch64-macos"
|
||||
},
|
||||
}
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Wait a little for this message to propagate to the core
|
||||
// (so that our feed connects after the core knows and not before).
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
|
||||
// Connect a feed.
|
||||
let (_feed_tx, mut feed_rx) = server.get_core().connect()
|
||||
.await.unwrap();
|
||||
let (_feed_tx, mut feed_rx) = server.get_core().connect().await.unwrap();
|
||||
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
assert!(feed_messages.contains(
|
||||
&FeedMessage::AddedChain {
|
||||
name: "Local Testnet".to_owned(),
|
||||
node_count: 1
|
||||
}
|
||||
));
|
||||
assert!(feed_messages.contains(&FeedMessage::AddedChain {
|
||||
name: "Local Testnet".to_owned(),
|
||||
node_count: 1
|
||||
}));
|
||||
|
||||
// Disconnect the node:
|
||||
node_tx.close().await.unwrap();
|
||||
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
assert!(feed_messages.contains(
|
||||
&FeedMessage::RemovedChain {
|
||||
name: "Local Testnet".to_owned(),
|
||||
}
|
||||
));
|
||||
assert!(feed_messages.contains(&FeedMessage::RemovedChain {
|
||||
name: "Local Testnet".to_owned(),
|
||||
}));
|
||||
|
||||
// Tidy up:
|
||||
server.shutdown().await;
|
||||
@@ -115,36 +125,40 @@ async fn feed_add_and_remove_shard() {
|
||||
let mut server = cargo_run_server().await;
|
||||
|
||||
let mut shards = vec![];
|
||||
for id in 1 ..= 2 {
|
||||
for id in 1..=2 {
|
||||
// Add a shard:
|
||||
let shard_id = server.add_shard().await.unwrap();
|
||||
|
||||
// Connect a node to it:
|
||||
let (mut node_tx, _node_rx) = server.get_shard(shard_id)
|
||||
let (mut node_tx, _node_rx) = server
|
||||
.get_shard(shard_id)
|
||||
.unwrap()
|
||||
.connect()
|
||||
.await
|
||||
.expect("can connect to shard");
|
||||
|
||||
// Send a "system connected" message:
|
||||
node_tx.send_json_text(json!(
|
||||
{
|
||||
"id":id,
|
||||
"ts":"2021-07-12T10:37:47.714666+01:00",
|
||||
"payload": {
|
||||
"authority":true,
|
||||
"chain": format!("Local Testnet {}", id),
|
||||
"config":"",
|
||||
"genesis_hash": BlockHash::from_low_u64_ne(id),
|
||||
"implementation":"Substrate Node",
|
||||
"msg":"system.connected",
|
||||
"name":"Alice",
|
||||
"network_id":"12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp",
|
||||
"startup_time":"1625565542717",
|
||||
"version":"2.0.0-07a1af348-aarch64-macos"
|
||||
},
|
||||
}
|
||||
)).await.unwrap();
|
||||
node_tx
|
||||
.send_json_text(json!(
|
||||
{
|
||||
"id":id,
|
||||
"ts":"2021-07-12T10:37:47.714666+01:00",
|
||||
"payload": {
|
||||
"authority":true,
|
||||
"chain": format!("Local Testnet {}", id),
|
||||
"config":"",
|
||||
"genesis_hash": BlockHash::from_low_u64_ne(id),
|
||||
"implementation":"Substrate Node",
|
||||
"msg":"system.connected",
|
||||
"name":"Alice",
|
||||
"network_id":"12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp",
|
||||
"startup_time":"1625565542717",
|
||||
"version":"2.0.0-07a1af348-aarch64-macos"
|
||||
},
|
||||
}
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Keep what we need to to keep connection alive and let us kill a shard:
|
||||
shards.push((shard_id, node_tx));
|
||||
@@ -155,30 +169,25 @@ async fn feed_add_and_remove_shard() {
|
||||
|
||||
// The feed should be told about both of the chains that we've sent info about:
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
assert!(feed_messages.contains(
|
||||
&FeedMessage::AddedChain {
|
||||
name: "Local Testnet 1".to_owned(),
|
||||
node_count: 1
|
||||
}
|
||||
));
|
||||
assert!(feed_messages.contains(
|
||||
&FeedMessage::AddedChain {
|
||||
name: "Local Testnet 2".to_owned(),
|
||||
node_count: 1
|
||||
}
|
||||
));
|
||||
assert!(feed_messages.contains(&FeedMessage::AddedChain {
|
||||
name: "Local Testnet 1".to_owned(),
|
||||
node_count: 1
|
||||
}));
|
||||
assert!(feed_messages.contains(&FeedMessage::AddedChain {
|
||||
name: "Local Testnet 2".to_owned(),
|
||||
node_count: 1
|
||||
}));
|
||||
|
||||
// Disconnect the first shard:
|
||||
server.kill_shard(shards[0].0).await;
|
||||
|
||||
// We should be told about the node connected to that shard disconnecting:
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
assert!(feed_messages.contains(
|
||||
&FeedMessage::RemovedChain {
|
||||
name: "Local Testnet 1".to_owned(),
|
||||
}
|
||||
));
|
||||
assert!(!feed_messages.contains( // Spot the "!"; this chain was not removed.
|
||||
assert!(feed_messages.contains(&FeedMessage::RemovedChain {
|
||||
name: "Local Testnet 1".to_owned(),
|
||||
}));
|
||||
assert!(!feed_messages.contains(
|
||||
// Spot the "!"; this chain was not removed.
|
||||
&FeedMessage::RemovedChain {
|
||||
name: "Local Testnet 2".to_owned(),
|
||||
}
|
||||
@@ -199,24 +208,27 @@ async fn feed_can_subscribe_and_unsubscribe_from_chain() {
|
||||
|
||||
// Send a "system connected" message for a few nodes/chains:
|
||||
for id in 1..=3 {
|
||||
node_tx.send_json_text(json!(
|
||||
{
|
||||
"id":id,
|
||||
"ts":"2021-07-12T10:37:47.714666+01:00",
|
||||
"payload": {
|
||||
"authority":true,
|
||||
"chain":format!("Local Testnet {}", id),
|
||||
"config":"",
|
||||
"genesis_hash": BlockHash::from_low_u64_ne(id),
|
||||
"implementation":"Substrate Node",
|
||||
"msg":"system.connected",
|
||||
"name":format!("Alice {}", id),
|
||||
"network_id":"12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp",
|
||||
"startup_time":"1625565542717",
|
||||
"version":"2.0.0-07a1af348-aarch64-macos"
|
||||
},
|
||||
}
|
||||
)).await.unwrap();
|
||||
node_tx
|
||||
.send_json_text(json!(
|
||||
{
|
||||
"id":id,
|
||||
"ts":"2021-07-12T10:37:47.714666+01:00",
|
||||
"payload": {
|
||||
"authority":true,
|
||||
"chain":format!("Local Testnet {}", id),
|
||||
"config":"",
|
||||
"genesis_hash": BlockHash::from_low_u64_ne(id),
|
||||
"implementation":"Substrate Node",
|
||||
"msg":"system.connected",
|
||||
"name":format!("Alice {}", id),
|
||||
"network_id":"12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp",
|
||||
"startup_time":"1625565542717",
|
||||
"version":"2.0.0-07a1af348-aarch64-macos"
|
||||
},
|
||||
}
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// Connect a feed
|
||||
@@ -226,7 +238,10 @@ async fn feed_can_subscribe_and_unsubscribe_from_chain() {
|
||||
assert_contains_matches!(feed_messages, AddedChain { name, node_count: 1 } if name == "Local Testnet 1");
|
||||
|
||||
// Subscribe it to a chain
|
||||
feed_tx.send_command("subscribe", "Local Testnet 1").await.unwrap();
|
||||
feed_tx
|
||||
.send_command("subscribe", "Local Testnet 1")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
assert_contains_matches!(
|
||||
@@ -257,7 +272,10 @@ async fn feed_can_subscribe_and_unsubscribe_from_chain() {
|
||||
.expect_err("Timeout should elapse since no messages sent");
|
||||
|
||||
// We can change our subscription:
|
||||
feed_tx.send_command("subscribe", "Local Testnet 2").await.unwrap();
|
||||
feed_tx
|
||||
.send_command("subscribe", "Local Testnet 2")
|
||||
.await
|
||||
.unwrap();
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
|
||||
// We are told about the subscription change and given similar on-subscribe messages to above.
|
||||
@@ -282,4 +300,4 @@ async fn feed_can_subscribe_and_unsubscribe_from_chain() {
|
||||
|
||||
// Tidy up:
|
||||
server.shutdown().await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user