2018-11-20 00:04:55 +01:00
|
|
|
extern crate futures;
|
|
|
|
|
extern crate tokio_executor;
|
|
|
|
|
extern crate tokio_timer;
|
|
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
|
mod support;
|
|
|
|
|
use support::*;
|
|
|
|
|
|
2019-02-21 11:56:15 -08:00
|
|
|
use futures::{prelude::*, sync::mpsc};
|
2019-03-19 14:58:59 -07:00
|
|
|
use tokio_timer::throttle::Throttle;
|
2018-11-20 00:04:55 +01:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn throttle() {
|
|
|
|
|
mocked(|timer, _| {
|
|
|
|
|
let (tx, rx) = mpsc::unbounded();
|
2019-03-19 14:58:59 -07:00
|
|
|
let mut stream = Throttle::new(rx, ms(1));
|
2018-11-20 00:04:55 +01:00
|
|
|
|
|
|
|
|
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();
|
2019-03-19 14:58:59 -07:00
|
|
|
let mut stream = Throttle::new(rx, ms(0));
|
2018-11-20 00:04:55 +01:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
}
|