Get chat integration tests passing

* Don't send a chat message before the previous chat message
  is acknowledged.
* Fix emitting of notifications in RPC server

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-02-14 12:37:17 -08:00
parent bf6ae0d8f8
commit 7b666af0cf
2 changed files with 10 additions and 3 deletions

View file

@ -4,6 +4,7 @@ use super::{
Client, Status, Subscription, TypedEnvelope, Client, Status, Subscription, TypedEnvelope,
}; };
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use futures::lock::Mutex;
use gpui::{ use gpui::{
AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task, WeakModelHandle, AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task, WeakModelHandle,
}; };
@ -40,6 +41,7 @@ pub struct Channel {
next_pending_message_id: usize, next_pending_message_id: usize,
user_store: ModelHandle<UserStore>, user_store: ModelHandle<UserStore>,
rpc: Arc<Client>, rpc: Arc<Client>,
outgoing_messages_lock: Arc<Mutex<()>>,
rng: StdRng, rng: StdRng,
_subscription: Subscription, _subscription: Subscription,
} }
@ -214,6 +216,7 @@ impl Channel {
details, details,
user_store, user_store,
rpc, rpc,
outgoing_messages_lock: Default::default(),
messages: Default::default(), messages: Default::default(),
loaded_all_messages: false, loaded_all_messages: false,
next_pending_message_id: 0, next_pending_message_id: 0,
@ -259,13 +262,16 @@ impl Channel {
); );
let user_store = self.user_store.clone(); let user_store = self.user_store.clone();
let rpc = self.rpc.clone(); let rpc = self.rpc.clone();
let outgoing_messages_lock = self.outgoing_messages_lock.clone();
Ok(cx.spawn(|this, mut cx| async move { Ok(cx.spawn(|this, mut cx| async move {
let outgoing_message_guard = outgoing_messages_lock.lock().await;
let request = rpc.request(proto::SendChannelMessage { let request = rpc.request(proto::SendChannelMessage {
channel_id, channel_id,
body, body,
nonce: Some(nonce.into()), nonce: Some(nonce.into()),
}); });
let response = request.await?; let response = request.await?;
drop(outgoing_message_guard);
let message = ChannelMessage::from_proto( let message = ChannelMessage::from_proto(
response.message.ok_or_else(|| anyhow!("invalid message"))?, response.message.ok_or_else(|| anyhow!("invalid message"))?,
&user_store, &user_store,

View file

@ -191,16 +191,17 @@ impl Server {
log::info!("rpc message received. connection:{}, type:{}", connection_id, type_name); log::info!("rpc message received. connection:{}, type:{}", connection_id, type_name);
if let Some(handler) = this.handlers.get(&message.payload_type_id()) { if let Some(handler) = this.handlers.get(&message.payload_type_id()) {
let handle_message = (handler)(this.clone(), message); let handle_message = (handler)(this.clone(), message);
let notifications = this.notifications.clone();
executor.spawn_detached(async move { executor.spawn_detached(async move {
if let Err(err) = handle_message.await { if let Err(err) = handle_message.await {
log::error!("rpc message error. connection:{}, type:{}, error:{:?}", connection_id, type_name, err); log::error!("rpc message error. connection:{}, type:{}, error:{:?}", connection_id, type_name, err);
} else { } else {
log::info!("rpc message handled. connection:{}, type:{}, duration:{:?}", connection_id, type_name, start_time.elapsed()); log::info!("rpc message handled. connection:{}, type:{}, duration:{:?}", connection_id, type_name, start_time.elapsed());
} }
if let Some(mut notifications) = notifications {
let _ = notifications.send(()).await;
}
}); });
if let Some(mut notifications) = this.notifications.clone() {
let _ = notifications.send(()).await;
}
} else { } else {
log::warn!("unhandled message: {}", type_name); log::warn!("unhandled message: {}", type_name);
} }