We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 93e4ce0 commit baf7d1dCopy full SHA for baf7d1d
library/std/tests/thread.rs
@@ -1,6 +1,8 @@
1
+#![feature(thread_sleep_until)]
2
+
3
use std::sync::{Arc, Mutex};
4
use std::thread;
-use std::time::Duration;
5
+use std::time::{Duration, Instant};
6
7
#[test]
8
#[cfg_attr(target_os = "emscripten", ignore)]
@@ -14,3 +16,19 @@ fn sleep() {
14
16
thread::sleep(Duration::from_millis(100));
15
17
assert_eq!(*finished.lock().unwrap(), false);
18
}
19
20
+#[test]
21
+fn sleep_until() {
22
+ let now = Instant::now();
23
+ let period = Duration::from_millis(100);
24
+ let deadline = now + period;
25
+ thread::sleep_until(deadline);
26
27
+ let margin = Duration::from_micros(100);
28
+ let elapsed = now.elapsed();
29
+ assert!(
30
+ (period..period + margin).contains(&elapsed),
31
+ "elapsed: {} microseconds, expected 100_000 to 100_100",
32
+ elapsed.as_micros()
33
+ );
34
+}
0 commit comments