File tree Expand file tree Collapse file tree 2 files changed +20
-10
lines changed
crates/cargo-test-support/src Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -1259,6 +1259,8 @@ pub trait TestEnv: Sized {
1259
1259
. env ( "__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS" , "stable" )
1260
1260
// Keeps cargo within its sandbox.
1261
1261
. env ( "__CARGO_TEST_DISABLE_GLOBAL_KNOWN_HOST" , "1" )
1262
+ // Set retry sleep to 1 millisecond.
1263
+ . env ( "__CARGO_TEST_FIXED_RETRY_SLEEP_MS" , "1" )
1262
1264
// Incremental generates a huge amount of data per test, which we
1263
1265
// don't particularly need. Tests that specifically need to check
1264
1266
// the incremental behavior should turn this back on.
Original file line number Diff line number Diff line change @@ -56,21 +56,29 @@ impl<'a> Retry<'a> {
56
56
return RetryResult :: Err ( e) ;
57
57
}
58
58
self . retries += 1 ;
59
- let sleep = if self . retries == 1 {
60
- let mut rng = rand:: thread_rng ( ) ;
61
- INITIAL_RETRY_SLEEP_BASE_MS + rng. gen_range ( 0 ..INITIAL_RETRY_JITTER_MS )
62
- } else {
63
- min (
64
- ( ( self . retries - 1 ) * 3 ) * 1000 + INITIAL_RETRY_SLEEP_BASE_MS ,
65
- MAX_RETRY_SLEEP_MS ,
66
- )
67
- } ;
68
- RetryResult :: Retry ( sleep)
59
+ RetryResult :: Retry ( self . next_sleep_ms ( ) )
69
60
}
70
61
Err ( e) => RetryResult :: Err ( e) ,
71
62
Ok ( r) => RetryResult :: Success ( r) ,
72
63
}
73
64
}
65
+
66
+ /// Gets the next sleep duration in milliseconds.
67
+ fn next_sleep_ms ( & self ) -> u64 {
68
+ if let Ok ( sleep) = self . config . get_env ( "__CARGO_TEST_FIXED_RETRY_SLEEP_MS" ) {
69
+ return sleep. parse ( ) . expect ( "a u64" )
70
+ }
71
+
72
+ if self . retries == 1 {
73
+ let mut rng = rand:: thread_rng ( ) ;
74
+ INITIAL_RETRY_SLEEP_BASE_MS + rng. gen_range ( 0 ..INITIAL_RETRY_JITTER_MS )
75
+ } else {
76
+ min (
77
+ ( ( self . retries - 1 ) * 3 ) * 1000 + INITIAL_RETRY_SLEEP_BASE_MS ,
78
+ MAX_RETRY_SLEEP_MS ,
79
+ )
80
+ }
81
+ }
74
82
}
75
83
76
84
fn maybe_spurious ( err : & Error ) -> bool {
You can’t perform that action at this time.
0 commit comments