Fix: test corpus_inaccessible panic (#10019)

If system uptime is less than the duration in the test, thread
will panic due to: 'overflow when subtracting duration from instant'.

Changed duration to 20 seconds to make it unlikely the test will
fail due to this condition.

Since no operations that carry a similar risk of panic occur outside
of the tests, it doesn't seem warranted to depend on an external crate
to fix this.
This commit is contained in:
mattrutherford 2018-12-05 15:38:55 +00:00 committed by GitHub
parent 349098e7b2
commit 2e0246a6c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -179,14 +179,15 @@ mod tests {
#[test] #[test]
fn corpus_inaccessible() { fn corpus_inaccessible() {
let mut cache = Cache::new(Default::default(), Duration::from_secs(5 * 3600)); let duration = Duration::from_secs(20);
let mut cache = Cache::new(Default::default(), duration.clone());
cache.set_gas_price_corpus(vec![].into()); cache.set_gas_price_corpus(vec![].into());
assert_eq!(cache.gas_price_corpus(), Some(vec![].into())); assert_eq!(cache.gas_price_corpus(), Some(vec![].into()));
{ {
let corpus_time = &mut cache.corpus.as_mut().unwrap().1; let corpus_time = &mut cache.corpus.as_mut().unwrap().1;
*corpus_time = *corpus_time - Duration::from_secs(5 * 3600); *corpus_time = *corpus_time - duration;
} }
assert!(cache.gas_price_corpus().is_none()); assert!(cache.gas_price_corpus().is_none());
} }