Skip to content

Commit

Permalink
Merge branch 'libp2p/master' into all-peers-on-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Apr 16, 2020
2 parents f2d49d8 + 77a34c0 commit 6ea7f23
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion protocols/kad/src/query/peers/closest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ impl ClosestPeersIter {
/// k closest nodes it has not already queried".
fn at_capacity(&self) -> bool {
match self.state {
State::Stalled => self.num_waiting >= self.config.num_results,
State::Stalled => self.num_waiting >= usize::max(
self.config.num_results, self.config.parallelism
),
State::Iterating { .. } => self.num_waiting >= self.config.parallelism,
State::Finished => true
}
Expand Down Expand Up @@ -718,4 +720,28 @@ mod tests {
two peers, see (*).",
);
}

fn stalled_at_capacity() {
fn prop(mut iter: ClosestPeersIter) {
iter.state = State::Stalled;

for i in 0..usize::max(iter.config.parallelism, iter.config.num_results) {
iter.num_waiting = i;
assert!(
!iter.at_capacity(),
"Iterator should not be at capacity if less than \
`max(parallelism, num_results)` requests are waiting.",
)
}

iter.num_waiting = usize::max(iter.config.parallelism, iter.config.num_results);
assert!(
iter.at_capacity(),
"Iterator should be at capacity if `max(parallelism, num_results)` requests are \
waiting.",
)
}

QuickCheck::new().tests(10).quickcheck(prop as fn(_))
}
}

0 comments on commit 6ea7f23

Please sign in to comment.