fixed broadcast(message) in sandbox::helpers
@@ -297,22 +297,26 @@ impl Sandbox {
}
}
+ pub fn broadcast<T: Message>(&self, msg: T)
+ {
+ let addresses = Vec::from_iter(self.addresses.iter().skip(1));
+ self.broadcast_to_addrs(msg, addresses);
+ }
+
// TODO: add self-test for broadcasting?
- pub fn broadcast<T: Message>(&self, msg: T) {
+ pub fn broadcast_to_addrs<'a, T: Message, I>(&self, msg: T, addresses: I)
+ where I: IntoIterator<Item = &'a SocketAddr>
+ {
let any_expected_msg = Any::from_raw(msg.raw().clone()).unwrap();
// If node is excluded from validators, then it still will broadcast messages.
// So in that case we should not skip addresses and validators count.
- let skip_validators = if self.validators().contains(&self.node_public_key()) {
- 1
- } else {
- 0
- };
+ let mut expected_set: HashSet<_> =
+ HashSet::from_iter(addresses.into_iter());
+ let count_addr = expected_set.len();
- let mut set: HashSet<_> =
- HashSet::from_iter(self.addresses.iter().skip(skip_validators).cloned());
- for _ in 0..self.n_validators() - skip_validators {
+ for _ in 0..count_addr {
let sended = self.inner.lock().unwrap().sent.pop_front();
if let Some((real_addr, real_msg)) = sended {
let any_real_msg = Any::from_raw(real_msg.clone()).expect("Send incorrect message");
@@ -322,18 +326,18 @@ impl Sandbox {
any_real_msg,
real_addr)
}
- if !set.contains(&real_addr) {
+ if !expected_set.contains(&real_addr) {
panic!("Double send the same message {:?} to {:?} during broadcasting",
any_expected_msg,
real_addr)
} else {
- set.remove(&real_addr);
+ expected_set.remove(&real_addr);
}
} else {
panic!("Expected to broadcast the message {:?} but someone don't recieve \
messages: {:?}",
any_expected_msg,
- set);
+ expected_set);
}
}
}
