Skip to content

Commit 73a0b40

Browse files
committed
Add some comment for rr testcase
Includes-commit: 7e8b7fd2842bed6031e3027adc5f3113a41c53ab Replicated-from: cloudflare/pingora#515
1 parent c8e3a66 commit 73a0b40

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

.bleep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f11c835e139cb0a0468183e2af3b142742794d7b
1+
159b358b6a92a5610b6663cddc6eb553ad22f895

pingora-load-balancing/src/selection/weighted.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,16 @@ mod test {
154154
let mut b2 = Backend::new("1.0.0.1:80").unwrap();
155155
b2.weight = 8; // 8x than the rest
156156
let b3 = Backend::new("1.0.0.255:80").unwrap();
157+
// sorted with: [b2, b3, b1]
158+
// weighted: [0, 0, 0, 0, 0, 0, 0, 0, 1, 2]
157159
let backends = BTreeSet::from_iter([b1.clone(), b2.clone(), b3.clone()]);
158160
let hash: Arc<Weighted<RoundRobin>> = Arc::new(Weighted::build(&backends));
159161

160162
// same hash iter over
161163
let mut iter = hash.iter(b"test");
162164
// first, should be weighted
165+
// weighted: [0, 0, 0, 0, 0, 0, 0, 0, 1, 2]
166+
// ^
163167
assert_eq!(iter.next(), Some(&b2));
164168
// fallbacks, should be round robin
165169
assert_eq!(iter.next(), Some(&b3));
@@ -168,6 +172,9 @@ mod test {
168172
assert_eq!(iter.next(), Some(&b3));
169173

170174
// round robin, ignoring the hash key
175+
// index advanced 5 steps
176+
// weighted: [0, 0, 0, 0, 0, 0, 0, 0, 1, 2]
177+
// ^
171178
let mut iter = hash.iter(b"test1");
172179
assert_eq!(iter.next(), Some(&b2));
173180
let mut iter = hash.iter(b"test1");
@@ -179,6 +186,7 @@ mod test {
179186
let mut iter = hash.iter(b"test1");
180187
assert_eq!(iter.next(), Some(&b1));
181188
let mut iter = hash.iter(b"test1");
189+
// rounded
182190
assert_eq!(iter.next(), Some(&b2));
183191
let mut iter = hash.iter(b"test1");
184192
assert_eq!(iter.next(), Some(&b2));

0 commit comments

Comments
 (0)