third_party/rust/tokio-core/tests/timeout.rs
author Bastien Orivel <eijebong@bananium.fr>
Wed, 22 Aug 2018 20:19:04 +0200
changeset 488156 03df1a267ea54f1024d3f015f4bf781477262c92
parent 452753 33873f5e18b985b326cfd61ec605856b59df88f2
permissions -rw-r--r--
Bug 1484462 - Revendor Rust dependencies. r=ato

extern crate env_logger;
extern crate futures;
extern crate tokio_core;

use std::time::{Instant, Duration};

use tokio_core::reactor::{Core, Timeout};

macro_rules! t {
    ($e:expr) => (match $e {
        Ok(e) => e,
        Err(e) => panic!("{} failed with {:?}", stringify!($e), e),
    })
}

#[test]
fn smoke() {
    drop(env_logger::init());
    let mut l = t!(Core::new());
    let dur = Duration::from_millis(10);
    let start = Instant::now();
    let timeout = t!(Timeout::new(dur, &l.handle()));
    t!(l.run(timeout));
    assert!(start.elapsed() >= (dur / 2));
}

#[test]
fn two() {
    drop(env_logger::init());

    let mut l = t!(Core::new());
    let dur = Duration::from_millis(10);
    let timeout = t!(Timeout::new(dur, &l.handle()));
    t!(l.run(timeout));
    let timeout = t!(Timeout::new(dur, &l.handle()));
    t!(l.run(timeout));
}