@@ -175,7 +175,6 @@ impl Iterator for Backoff {
175
175
#[ cfg( test) ]
176
176
mod tests {
177
177
use super :: * ;
178
- use rand:: rngs:: mock:: StepRng ;
179
178
180
179
#[ test]
181
180
fn test_backoff ( ) {
@@ -190,18 +189,18 @@ mod tests {
190
189
deadline : None ,
191
190
} ;
192
191
193
- let assert_fuzzy_eq = |a : f64 , b : f64 | assert ! ( ( b - a) . abs( ) < 0.0001 , "{} != {}" , a , b ) ;
192
+ let assert_fuzzy_eq = |a : f64 , b : f64 | assert ! ( ( b - a) . abs( ) < 0.0001 , "{a } != {b}" ) ;
194
193
195
194
// Create a static rng that takes the minimum of the range
196
- let rng = Box :: new ( StepRng :: new ( 0 , 0 ) ) ;
195
+ let rng = Box :: new ( ConstantRng :: new ( 0 ) ) ;
197
196
let mut backoff = Backoff :: new_with_rng ( & config, Some ( rng) ) ;
198
197
199
198
for _ in 0 ..20 {
200
199
assert_eq ! ( backoff. next( ) . unwrap( ) . as_secs_f64( ) , init_backoff_secs) ;
201
200
}
202
201
203
202
// Create a static rng that takes the maximum of the range
204
- let rng = Box :: new ( StepRng :: new ( u64:: MAX , 0 ) ) ;
203
+ let rng = Box :: new ( ConstantRng :: new ( u64:: MAX ) ) ;
205
204
let mut backoff = Backoff :: new_with_rng ( & config, Some ( rng) ) ;
206
205
207
206
for i in 0 ..20 {
@@ -210,7 +209,7 @@ mod tests {
210
209
}
211
210
212
211
// Create a static rng that takes the mid point of the range
213
- let rng = Box :: new ( StepRng :: new ( u64:: MAX / 2 , 0 ) ) ;
212
+ let rng = Box :: new ( ConstantRng :: new ( u64:: MAX / 2 ) ) ;
214
213
let mut backoff = Backoff :: new_with_rng ( & config, Some ( rng) ) ;
215
214
216
215
let mut value = init_backoff_secs;
@@ -221,7 +220,7 @@ mod tests {
221
220
}
222
221
223
222
// deadline
224
- let rng = Box :: new ( StepRng :: new ( u64:: MAX , 0 ) ) ;
223
+ let rng = Box :: new ( ConstantRng :: new ( u64:: MAX ) ) ;
225
224
let deadline = Duration :: from_secs_f64 ( init_backoff_secs) ;
226
225
let mut backoff = Backoff :: new_with_rng (
227
226
& BackoffConfig {
@@ -232,4 +231,29 @@ mod tests {
232
231
) ;
233
232
assert_eq ! ( backoff. next( ) , None ) ;
234
233
}
234
+
235
+ /// A simple RNG that always returns the same value
236
+ struct ConstantRng {
237
+ value : u64 ,
238
+ }
239
+
240
+ impl ConstantRng {
241
+ fn new ( value : u64 ) -> Self {
242
+ Self { value }
243
+ }
244
+ }
245
+
246
+ impl RngCore for ConstantRng {
247
+ fn next_u32 ( & mut self ) -> u32 {
248
+ ( self . value >> 32 ) as u32
249
+ }
250
+
251
+ fn next_u64 ( & mut self ) -> u64 {
252
+ self . value
253
+ }
254
+
255
+ fn fill_bytes ( & mut self , _dest : & mut [ u8 ] ) {
256
+ unimplemented ! ( )
257
+ }
258
+ }
235
259
}
0 commit comments