use std::sync::mpsc;
use std::time::Duration;

use dope_runtime::DefaultBackend;
use dope_runtime::executor::{LocalExecutor, Throughput};
use dope_runtime::runtime::Runtime;

#[test]
fn shutdown_drains_spawned_tasks() {
    let (tx, rx) = mpsc::channel();
    let mut rt =
        Runtime::<LocalExecutor<DefaultBackend, Throughput>>::new_local().expect("runtime");

    rt.spawn(async move {
        let _ = tx.send(1usize);
    });
    rt.shutdown();

    let got = rx
        .recv_timeout(Duration::from_millis(200))
        .expect("drained task");
    assert_eq!(got, 1);
}
