Adjust diagnostic transformation test to not wait for two buffer notifications

This commit is contained in:
Max Brunsfeld 2023-05-26 11:40:15 -07:00
parent 02b95ef320
commit 2db57b5139
5 changed files with 22 additions and 5 deletions

View file

@ -434,7 +434,9 @@ impl<T: Entity> ModelHandle<T> {
Duration::from_secs(1) Duration::from_secs(1)
}; };
let executor = cx.background().clone();
async move { async move {
executor.start_waiting();
let notification = crate::util::timeout(duration, rx.next()) let notification = crate::util::timeout(duration, rx.next())
.await .await
.expect("next notification timed out"); .expect("next notification timed out");

View file

@ -876,6 +876,14 @@ impl Background {
} }
} }
} }
#[cfg(any(test, feature = "test-support"))]
pub fn start_waiting(&self) {
match self {
Self::Deterministic { executor, .. } => executor.start_waiting(),
_ => panic!("this method can only be called on a deterministic executor"),
}
}
} }
impl Default for Background { impl Default for Background {

View file

@ -796,6 +796,12 @@ impl LanguageRegistry {
http_client: Arc<dyn HttpClient>, http_client: Arc<dyn HttpClient>,
cx: &mut AppContext, cx: &mut AppContext,
) -> Option<PendingLanguageServer> { ) -> Option<PendingLanguageServer> {
let server_id = self.state.write().next_language_server_id();
log::info!(
"starting language server name:{}, path:{root_path:?}, id:{server_id}",
adapter.name.0
);
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
if language.fake_adapter.is_some() { if language.fake_adapter.is_some() {
let task = cx.spawn(|cx| async move { let task = cx.spawn(|cx| async move {
@ -825,7 +831,6 @@ impl LanguageRegistry {
Ok(server) Ok(server)
}); });
let server_id = self.state.write().next_language_server_id();
return Some(PendingLanguageServer { server_id, task }); return Some(PendingLanguageServer { server_id, task });
} }
@ -834,7 +839,6 @@ impl LanguageRegistry {
.clone() .clone()
.ok_or_else(|| anyhow!("language server download directory has not been assigned")) .ok_or_else(|| anyhow!("language server download directory has not been assigned"))
.log_err()?; .log_err()?;
let this = self.clone(); let this = self.clone();
let language = language.clone(); let language = language.clone();
let http_client = http_client.clone(); let http_client = http_client.clone();
@ -843,7 +847,6 @@ impl LanguageRegistry {
let adapter = adapter.clone(); let adapter = adapter.clone();
let lsp_binary_statuses = self.lsp_binary_statuses_tx.clone(); let lsp_binary_statuses = self.lsp_binary_statuses_tx.clone();
let login_shell_env_loaded = self.login_shell_env_loaded.clone(); let login_shell_env_loaded = self.login_shell_env_loaded.clone();
let server_id = self.state.write().next_language_server_id();
let task = cx.spawn(|cx| async move { let task = cx.spawn(|cx| async move {
login_shell_env_loaded.await; login_shell_env_loaded.await;

View file

@ -849,10 +849,12 @@ impl FakeLanguageServer {
T: request::Request, T: request::Request,
T::Result: 'static + Send, T::Result: 'static + Send,
{ {
self.server.executor.start_waiting();
self.server.request::<T>(params).await self.server.request::<T>(params).await
} }
pub async fn receive_notification<T: notification::Notification>(&mut self) -> T::Params { pub async fn receive_notification<T: notification::Notification>(&mut self) -> T::Params {
self.server.executor.start_waiting();
self.try_receive_notification::<T>().await.unwrap() self.try_receive_notification::<T>().await.unwrap()
} }

View file

@ -1193,7 +1193,7 @@ async fn test_toggling_enable_language_server(cx: &mut gpui::TestAppContext) {
.await; .await;
} }
#[gpui::test] #[gpui::test(iterations = 3)]
async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) { async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {
init_test(cx); init_test(cx);
@ -1273,7 +1273,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {
// The diagnostics have moved down since they were created. // The diagnostics have moved down since they were created.
buffer.next_notification(cx).await; buffer.next_notification(cx).await;
buffer.next_notification(cx).await; cx.foreground().run_until_parked();
buffer.read_with(cx, |buffer, _| { buffer.read_with(cx, |buffer, _| {
assert_eq!( assert_eq!(
buffer buffer
@ -1352,6 +1352,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {
}); });
buffer.next_notification(cx).await; buffer.next_notification(cx).await;
cx.foreground().run_until_parked();
buffer.read_with(cx, |buffer, _| { buffer.read_with(cx, |buffer, _| {
assert_eq!( assert_eq!(
buffer buffer
@ -1444,6 +1445,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {
}); });
buffer.next_notification(cx).await; buffer.next_notification(cx).await;
cx.foreground().run_until_parked();
buffer.read_with(cx, |buffer, _| { buffer.read_with(cx, |buffer, _| {
assert_eq!( assert_eq!(
buffer buffer