A little more testing for tor_rtcompat::mock::time.

This commit is contained in:
Nick Mathewson 2021-04-20 08:26:41 -04:00
parent a910627e92
commit 4a761f55ea
1 changed files with 25 additions and 0 deletions

View File

@ -127,6 +127,14 @@ impl SleepProvider for MockSleepProvider {
provider: Arc::downgrade(&self.state),
}
}
fn now(&self) -> Instant {
self.state.lock().unwrap().instant
}
fn wallclock(&self) -> SystemTime {
self.state.lock().unwrap().wallclock
}
}
impl PartialEq for SleepEntry {
@ -173,6 +181,23 @@ mod test {
use super::*;
use crate::test_with_runtime;
#[test]
fn basics_of_time_travel() {
let w1 = SystemTime::now();
let sp = MockSleepProvider::new(w1);
let i1 = sp.now();
assert_eq!(sp.wallclock(), w1);
let interval = Duration::new(4 * 3600 + 13 * 60, 0);
sp.advance(interval);
assert_eq!(sp.now(), i1 + interval);
assert_eq!(sp.wallclock(), w1 + interval);
sp.jump_to(w1 + interval * 3);
assert_eq!(sp.now(), i1 + interval);
assert_eq!(sp.wallclock(), w1 + interval * 3);
}
#[test]
fn time_moves_on() {
test_with_runtime(|_| async {