Skip to content

Commit

Permalink
Add some comment for rr testcase
Browse files Browse the repository at this point in the history
Includes-commit: 7e8b7fd
Replicated-from: #515
  • Loading branch information
rongyi authored and eaufavor committed Jan 30, 2025
1 parent e6b823c commit 57dbdea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .bleep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f11c835e139cb0a0468183e2af3b142742794d7b
159b358b6a92a5610b6663cddc6eb553ad22f895
8 changes: 8 additions & 0 deletions pingora-load-balancing/src/selection/weighted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,16 @@ mod test {
let mut b2 = Backend::new("1.0.0.1:80").unwrap();
b2.weight = 8; // 8x than the rest
let b3 = Backend::new("1.0.0.255:80").unwrap();
// sorted with: [b2, b3, b1]
// weighted: [0, 0, 0, 0, 0, 0, 0, 0, 1, 2]
let backends = BTreeSet::from_iter([b1.clone(), b2.clone(), b3.clone()]);
let hash: Arc<Weighted<RoundRobin>> = Arc::new(Weighted::build(&backends));

// same hash iter over
let mut iter = hash.iter(b"test");
// first, should be weighted
// weighted: [0, 0, 0, 0, 0, 0, 0, 0, 1, 2]
// ^
assert_eq!(iter.next(), Some(&b2));
// fallbacks, should be round robin
assert_eq!(iter.next(), Some(&b3));
Expand All @@ -168,6 +172,9 @@ mod test {
assert_eq!(iter.next(), Some(&b3));

// round robin, ignoring the hash key
// index advanced 5 steps
// weighted: [0, 0, 0, 0, 0, 0, 0, 0, 1, 2]
// ^
let mut iter = hash.iter(b"test1");
assert_eq!(iter.next(), Some(&b2));
let mut iter = hash.iter(b"test1");
Expand All @@ -179,6 +186,7 @@ mod test {
let mut iter = hash.iter(b"test1");
assert_eq!(iter.next(), Some(&b1));
let mut iter = hash.iter(b"test1");
// rounded
assert_eq!(iter.next(), Some(&b2));
let mut iter = hash.iter(b"test1");
assert_eq!(iter.next(), Some(&b2));
Expand Down

0 comments on commit 57dbdea

Please sign in to comment.