@@ -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