summaryrefslogtreecommitdiffstats
path: root/tokio-timer/tests/throttle.rs
blob: 96c384c75956ce179363fa8129f5262c4e244eb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#![deny(warnings, rust_2018_idioms)]

mod support;
use crate::support::*;

use futures::{prelude::*, sync::mpsc};
use tokio_timer::throttle::Throttle;

#[test]
fn throttle() {
    mocked(|timer, _| {
        let (tx, rx) = mpsc::unbounded();
        let mut stream = Throttle::new(rx, ms(1));

        assert_not_ready!(stream);

        for i in 0..3 {
            tx.unbounded_send(i).unwrap();
        }
        for i in 0..3 {
            assert_ready_eq!(stream, Some(i));
            assert_not_ready!(stream);

            advance(timer, ms(1));
        }

        assert_not_ready!(stream);
    });
}

#[test]
fn throttle_dur_0() {
    mocked(|_, _| {
        let (tx, rx) = mpsc::unbounded();
        let mut stream = Throttle::new(rx, ms(0));

        assert_not_ready!(stream);

        for i in 0..3 {
            tx.unbounded_send(i).unwrap();
        }
        for i in 0..3 {
            assert_ready_eq!(stream, Some(i));
        }

        assert_not_ready!(stream);
    });
}