From 731f792686f1f94286bc1e6315d1bab364b2a210 Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Sat, 28 Dec 2019 07:34:33 +0100 Subject: [PATCH] Fix updating outgoing client state This also allows us to simplify the channel_tracking_names_part test. --- src/client/mod.rs | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index f0c6058..c7307ac 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -496,7 +496,7 @@ impl ClientState { fn new(sender: Sender, config: Config) -> ClientState { ClientState { sender, - config: config, + config, chanlists: RwLock::new(HashMap::new()), alt_nick_index: RwLock::new(0), default_ghost_sequence: vec![String::from("GHOST")], @@ -1056,7 +1056,7 @@ impl Client { /// # } /// ``` pub fn send>(&self, msg: M) -> error::Result<()> { - self.sender.send(msg) + self.state.send(msg) } /// Sends a CAP END, NICK and USER to identify. @@ -1363,7 +1363,6 @@ mod test { #[cfg(not(feature = "nochanlists"))] async fn channel_tracking_names_part() -> Result<()> { use crate::proto::command::Command::PART; - use futures::prelude::*; let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n"; let mut client = Client::from_config(Config { @@ -1372,32 +1371,13 @@ mod test { }) .await?; - let mut stream = client.stream()?; - let (shutdown_tx, shutdown_rx) = futures::channel::oneshot::channel(); + client.stream()?.collect().await?; - // TODO: Add the necessary testing hooks to drive this more - // deterministically, like "wait until one outgoing message has been - // processed". We currently more-or-less rely on the test executor being - // singlethreaded (tokio without rt-threaded feature), but even that is - // a bit shaky. - let task = tokio::spawn(async move { - let mut shutdown_rx = shutdown_rx.fuse(); - - loop { - futures::select! { - _ = stream.next() => { - } - _ = shutdown_rx => { - break; - } - } - } - }); - - assert!(client.send(PART(format!("#test"), None)).is_ok()); - assert!(client.list_channels().unwrap().is_empty()); - shutdown_tx.send(()).expect("send to work"); - task.await?; + assert_eq!(client.list_channels(), Some(vec!["#test".to_owned()])); + // we ignore the result, as soon as we queue an outgoing message we + // update client state, regardless if the queue is available or not. + let _ = client.send(PART(format!("#test"), None)); + assert_eq!(client.list_channels(), Some(vec![])); Ok(()) }