Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
fix(stress test): fix sent probe messages counter
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Jan 12, 2021
1 parent fc5eecf commit b9b7530
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions examples/stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const PROBE_WINDOW: Duration = Duration::from_secs(60);
/// Stress test for sn-routing.
#[derive(Debug, StructOpt)]
struct Options {
/// Enable logging. Takes path to a file to log to or "-" to log to stdout.
/// Enable logging. Takes path to a file to log to or "-" to log to stdout. If omitted, logging
/// is disabled.
#[structopt(short, long, name = "PATH")]
log: Option<String>,
/// How many probe messages to send per second.
Expand Down Expand Up @@ -398,7 +399,8 @@ impl Network {

// Send messages to probe network health.
async fn send_probes(&mut self) -> Result<()> {
// Cache the (src, dst) pairs of already sent messages.
// Cache the (src, dst) pairs of sent messages to ensure every node from the same
// section sends the same message.
let mut cache = BTreeMap::new();

let nodes = self.nodes.values().filter_map(|node| match node {
Expand All @@ -412,8 +414,10 @@ impl Network {
let dst = *cache
.entry(prefix)
.or_insert_with(|| prefix.substituted_in(rand::random()));
self.try_send_probe(node, *name, dst).await?;
self.probe_tracker.send(*prefix, dst);

if self.try_send_probe(node, *name, dst).await? {
self.probe_tracker.send(*prefix, dst);
}
}

self.probe_tracker.prune();
Expand All @@ -423,12 +427,12 @@ impl Network {
Ok(())
}

async fn try_send_probe(&self, node: &Routing, src: XorName, dst: XorName) -> Result<()> {
async fn try_send_probe(&self, node: &Routing, src: XorName, dst: XorName) -> Result<bool> {
let public_key_set = if let Ok(public_key_set) = node.public_key_set().await {
public_key_set
} else {
// The node doesn't have BLS keys. Skip.
return Ok(());
return Ok(false);
};

// The message dst is unique so we use it also as its indentifier.
Expand All @@ -449,7 +453,7 @@ impl Network {
node.send_message(SrcLocation::Node(src), DstLocation::Section(dst), bytes)
.await?;

Ok(())
Ok(true)
}

fn try_print_status(&mut self) {
Expand Down

0 comments on commit b9b7530

Please sign in to comment.