2022-06-16 10:39:39 -05:00
|
|
|
use std::{
|
|
|
|
io::ErrorKind,
|
|
|
|
sync::OnceLock,
|
|
|
|
thread::{self, Builder, ThreadId},
|
|
|
|
};
|
2021-01-29 10:23:56 -06:00
|
|
|
|
2022-06-16 10:39:39 -05:00
|
|
|
static THREAD_ID: OnceLock<ThreadId> = OnceLock::new();
|
2021-01-29 10:23:56 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn spawn_thread_would_block() {
|
|
|
|
assert_eq!(Builder::new().spawn(|| unreachable!()).unwrap_err().kind(), ErrorKind::WouldBlock);
|
|
|
|
THREAD_ID.set(thread::current().id()).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_in_same_thread() {
|
|
|
|
assert_eq!(*THREAD_ID.get().unwrap(), thread::current().id());
|
|
|
|
}
|