use safina_async_test::async_test;
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::{Duration, Instant};

static TEST_RAN: AtomicBool = AtomicBool::new(false);
#[async_test]
async fn run_test() {
    TEST_RAN.store(true, Ordering::Release);
}
#[test]
fn should_run_test() {
    let deadline = Instant::now() + Duration::from_millis(1000);
    while Instant::now() < deadline {
        if TEST_RAN.load(Ordering::Acquire) {
            return;
        }
        std::sync::atomic::spin_loop_hint();
    }
    panic!("timeout");
}

#[async_test]
async fn should_work_with_spawned_tasks() {
    safina::increase_threads_to(1);
    let (sender, receiver) = std::sync::mpsc::channel();
    safina::spawn(Box::pin(async move {
        sender.send(()).unwrap();
    }));
    receiver.recv().unwrap();
}

// // error[E0308]: mismatched types; expected `()`, found enum `std::result::Result`
// #[async_test]
// async fn dont_allow_returning_result() -> Result<(), std::sync::mpsc::RecvError> {
//     Ok(())
// }
