fix: Patch coarsetime for MIPS AtomicU64 support
- Vendor coarsetime crate with portable-atomic fallback - Use portable-atomic on targets without 64-bit atomics - Patch crates.io to use local coarsetime - Fixes MIPS build failure (AtomicU64 missing)
This commit is contained in:
55
third_party/coarsetime/src/tests.rs
vendored
Normal file
55
third_party/coarsetime/src/tests.rs
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
use std::thread::sleep;
|
||||
use std::time;
|
||||
|
||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||
use super::Updater;
|
||||
use super::{Clock, Duration, Instant};
|
||||
|
||||
#[test]
|
||||
fn tests() {
|
||||
let ts = Instant::now();
|
||||
let d = Duration::from_secs(2);
|
||||
sleep(time::Duration::new(3, 0));
|
||||
let elapsed = ts.elapsed().as_secs();
|
||||
println!("Elapsed: {elapsed} secs");
|
||||
assert!(elapsed >= 2);
|
||||
assert!(elapsed < 100);
|
||||
assert!(ts.elapsed_since_recent() > d);
|
||||
|
||||
let ts = Instant::now();
|
||||
sleep(time::Duration::new(1, 0));
|
||||
assert_eq!(Instant::recent(), ts);
|
||||
Instant::update();
|
||||
assert!(Instant::recent() > ts);
|
||||
|
||||
let clock_now = Clock::recent_since_epoch();
|
||||
sleep(time::Duration::new(1, 0));
|
||||
assert_eq!(Clock::recent_since_epoch(), clock_now);
|
||||
assert!(Clock::now_since_epoch() > clock_now);
|
||||
|
||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||
tests_updater();
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
||||
#[test]
|
||||
fn tests_updater() {
|
||||
let updater = Updater::new(250)
|
||||
.start()
|
||||
.expect("Unable to start a background updater");
|
||||
let ts = Instant::recent();
|
||||
let clock_recent = Clock::recent_since_epoch();
|
||||
sleep(time::Duration::new(2, 0));
|
||||
assert!(Clock::recent_since_epoch() > clock_recent);
|
||||
assert!(Instant::recent() != ts);
|
||||
updater.stop().unwrap();
|
||||
let clock_recent = Clock::recent_since_epoch();
|
||||
sleep(time::Duration::new(1, 0));
|
||||
assert_eq!(Clock::recent_since_epoch(), clock_recent);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tests_duration() {
|
||||
let duration = Duration::from_days(1000);
|
||||
assert_eq!(duration.as_days(), 1000);
|
||||
}
|
||||
Reference in New Issue
Block a user