Skip to content

Commit

Permalink
Fix tests (see tokio-rs/tokio#3350)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gelbpunkt committed Apr 19, 2021
1 parent 1bb1eb1 commit d88f8e3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions gateway/src/shard/processor/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,18 @@ impl Emitter {
mod tests {
use super::Emitter;
use crate::{listener::Listeners, Event, EventTypeFlags};
use tokio::time::{Duration, timeout};

#[test]
fn test_bytes_send() {
#[tokio::test]
async fn test_bytes_send() {
let listeners = Listeners::default();
let mut rx = listeners.add(EventTypeFlags::SHARD_PAYLOAD);
let emitter = Emitter::new(listeners);
emitter.bytes(&[1]);
assert_eq!(1, emitter.listeners.len());

assert!(matches!(rx.try_next(), Ok(Some(_))));
assert!(rx.try_next().is_err());
assert!(rx.recv().await.is_some());
assert!(timeout(Duration::from_millis(10), rx.recv()).await.is_err());
}

#[test]
Expand All @@ -215,20 +216,20 @@ mod tests {
assert!(emitter.listeners.all().is_empty());
}

#[test]
fn test_event_sends_to_rxs() {
#[tokio::test]
async fn test_event_sends_to_rxs() {
let listeners = Listeners::default();
let mut rx1 = listeners.add(EventTypeFlags::default());
let mut rx2 = listeners.add(EventTypeFlags::default());
let emitter = Emitter::new(listeners);
emitter.event(Event::GatewayReconnect);
assert_eq!(2, emitter.listeners.len());

assert!(matches!(rx1.try_next(), Ok(Some(_))));
assert!(matches!(rx2.try_next(), Ok(Some(_))));
assert!(rx1.recv().await.is_some());
assert!(rx2.recv().await.is_some());

// now check that they didn't send the event twice
assert!(rx1.try_next().is_err());
assert!(rx2.try_next().is_err());
assert!(timeout(Duration::from_millis(10), rx1.recv()).await.is_err());
assert!(timeout(Duration::from_millis(10), rx2.recv()).await.is_err());
}
}

0 comments on commit d88f8e3

Please sign in to comment.