Fix updating outgoing client state

This also allows us to simplify the channel_tracking_names_part test.
This commit is contained in:
John-John Tedro 2019-12-28 07:34:33 +01:00
parent 71a703c762
commit 731f792686

View file

@ -496,7 +496,7 @@ impl ClientState {
fn new(sender: Sender, config: Config) -> ClientState { fn new(sender: Sender, config: Config) -> ClientState {
ClientState { ClientState {
sender, sender,
config: config, config,
chanlists: RwLock::new(HashMap::new()), chanlists: RwLock::new(HashMap::new()),
alt_nick_index: RwLock::new(0), alt_nick_index: RwLock::new(0),
default_ghost_sequence: vec![String::from("GHOST")], default_ghost_sequence: vec![String::from("GHOST")],
@ -1056,7 +1056,7 @@ impl Client {
/// # } /// # }
/// ``` /// ```
pub fn send<M: Into<Message>>(&self, msg: M) -> error::Result<()> { pub fn send<M: Into<Message>>(&self, msg: M) -> error::Result<()> {
self.sender.send(msg) self.state.send(msg)
} }
/// Sends a CAP END, NICK and USER to identify. /// Sends a CAP END, NICK and USER to identify.
@ -1363,7 +1363,6 @@ mod test {
#[cfg(not(feature = "nochanlists"))] #[cfg(not(feature = "nochanlists"))]
async fn channel_tracking_names_part() -> Result<()> { async fn channel_tracking_names_part() -> Result<()> {
use crate::proto::command::Command::PART; use crate::proto::command::Command::PART;
use futures::prelude::*;
let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n"; let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n";
let mut client = Client::from_config(Config { let mut client = Client::from_config(Config {
@ -1372,32 +1371,13 @@ mod test {
}) })
.await?; .await?;
let mut stream = client.stream()?; client.stream()?.collect().await?;
let (shutdown_tx, shutdown_rx) = futures::channel::oneshot::channel();
// TODO: Add the necessary testing hooks to drive this more assert_eq!(client.list_channels(), Some(vec!["#test".to_owned()]));
// deterministically, like "wait until one outgoing message has been // we ignore the result, as soon as we queue an outgoing message we
// processed". We currently more-or-less rely on the test executor being // update client state, regardless if the queue is available or not.
// singlethreaded (tokio without rt-threaded feature), but even that is let _ = client.send(PART(format!("#test"), None));
// a bit shaky. assert_eq!(client.list_channels(), Some(vec![]));
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?;
Ok(()) Ok(())
} }