Get project2 tests green
This commit is contained in:
parent
401ddc6f49
commit
53066df522
5 changed files with 31 additions and 23 deletions
|
@ -3,8 +3,8 @@ use crate::{
|
||||||
ForegroundExecutor, Model, ModelContext, Result, Task, TestDispatcher, TestPlatform,
|
ForegroundExecutor, Model, ModelContext, Result, Task, TestDispatcher, TestPlatform,
|
||||||
WindowContext,
|
WindowContext,
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::{anyhow, bail};
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures::{SinkExt, Stream, StreamExt};
|
||||||
use std::{cell::RefCell, future::Future, rc::Rc, sync::Arc, time::Duration};
|
use std::{cell::RefCell, future::Future, rc::Rc, sync::Arc, time::Duration};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -140,7 +140,25 @@ impl TestAppContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscribe<T: 'static + EventEmitter>(
|
pub fn notifications<T: 'static>(&mut self, entity: &Model<T>) -> impl Stream<Item = ()> {
|
||||||
|
let (tx, rx) = futures::channel::mpsc::unbounded();
|
||||||
|
|
||||||
|
entity.update(self, move |_, cx: &mut ModelContext<T>| {
|
||||||
|
cx.observe(entity, {
|
||||||
|
let tx = tx.clone();
|
||||||
|
move |_, _, _| {
|
||||||
|
let _ = tx.unbounded_send(());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
cx.on_release(move |_, _| tx.close_channel()).detach();
|
||||||
|
});
|
||||||
|
|
||||||
|
rx
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn events<T: 'static + EventEmitter>(
|
||||||
&mut self,
|
&mut self,
|
||||||
entity: &Model<T>,
|
entity: &Model<T>,
|
||||||
) -> futures::channel::mpsc::UnboundedReceiver<T::Event>
|
) -> futures::channel::mpsc::UnboundedReceiver<T::Event>
|
||||||
|
@ -160,36 +178,24 @@ impl TestAppContext {
|
||||||
rx
|
rx
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn condition<T: EventEmitter + 'static>(
|
pub async fn condition<T: 'static>(
|
||||||
&mut self,
|
&mut self,
|
||||||
model: &Model<T>,
|
model: &Model<T>,
|
||||||
mut predicate: impl FnMut(&mut T, &mut ModelContext<T>) -> bool,
|
mut predicate: impl FnMut(&mut T, &mut ModelContext<T>) -> bool,
|
||||||
) {
|
) {
|
||||||
let (mut tx, mut rx) = futures::channel::mpsc::unbounded::<()>();
|
|
||||||
let timer = self.executor().timer(Duration::from_secs(3));
|
let timer = self.executor().timer(Duration::from_secs(3));
|
||||||
|
let mut notifications = self.notifications(model);
|
||||||
let subscriptions = model.update(self, move |_, cx| {
|
|
||||||
(
|
|
||||||
cx.observe(model, move |_, _, _| {
|
|
||||||
// let _ = tx.send(());
|
|
||||||
}),
|
|
||||||
cx.subscribe(model, move |_, _, _, _| {
|
|
||||||
let _ = tx.send(());
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
use futures::FutureExt as _;
|
use futures::FutureExt as _;
|
||||||
use smol::future::FutureExt as _;
|
use smol::future::FutureExt as _;
|
||||||
|
|
||||||
async {
|
async {
|
||||||
while rx.next().await.is_some() {
|
while notifications.next().await.is_some() {
|
||||||
if model.update(self, &mut predicate) {
|
if model.update(self, &mut predicate) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drop(subscriptions);
|
bail!("model dropped")
|
||||||
unreachable!()
|
|
||||||
}
|
}
|
||||||
.race(timer.map(|_| Err(anyhow!("condition timed out"))))
|
.race(timer.map(|_| Err(anyhow!("condition timed out"))))
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -947,7 +947,7 @@ async fn test_disk_based_diagnostics_progress(cx: &mut gpui2::TestAppContext) {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut events = cx.subscribe(&project);
|
let mut events = cx.events(&project);
|
||||||
|
|
||||||
let fake_server = fake_servers.next().await.unwrap();
|
let fake_server = fake_servers.next().await.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -1078,7 +1078,7 @@ async fn test_restarting_server_with_diagnostics_running(cx: &mut gpui2::TestApp
|
||||||
project.update(cx, |project, cx| {
|
project.update(cx, |project, cx| {
|
||||||
project.restart_language_servers_for_buffers([buffer], cx);
|
project.restart_language_servers_for_buffers([buffer], cx);
|
||||||
});
|
});
|
||||||
let mut events = cx.subscribe(&project);
|
let mut events = cx.events(&project);
|
||||||
|
|
||||||
// Simulate the newly started server sending more diagnostics.
|
// Simulate the newly started server sending more diagnostics.
|
||||||
let fake_server = fake_servers.next().await.unwrap();
|
let fake_server = fake_servers.next().await.unwrap();
|
||||||
|
@ -2788,6 +2788,7 @@ async fn test_rescan_and_remote_updates(cx: &mut gpui2::TestAppContext) {
|
||||||
});
|
});
|
||||||
|
|
||||||
let remote = cx.update(|cx| Worktree::remote(1, 1, metadata, rpc.clone(), cx));
|
let remote = cx.update(|cx| Worktree::remote(1, 1, metadata, rpc.clone(), cx));
|
||||||
|
|
||||||
cx.executor().run_until_parked();
|
cx.executor().run_until_parked();
|
||||||
|
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
|
|
|
@ -4065,6 +4065,7 @@ impl WorktreeModelHandle for Model<Worktree> {
|
||||||
fs.create_file(&root_path.join(file_name), Default::default())
|
fs.create_file(&root_path.join(file_name), Default::default())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
cx.condition(&tree, |tree, _| tree.entry_for_path(file_name).is_some())
|
cx.condition(&tree, |tree, _| tree.entry_for_path(file_name).is_some())
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl<V: 'static> Pane<V> {
|
||||||
.id("drag-target")
|
.id("drag-target")
|
||||||
.drag_over::<ExternalPaths>(|d| d.bg(red()))
|
.drag_over::<ExternalPaths>(|d| d.bg(red()))
|
||||||
.on_drop(|_, files: View<ExternalPaths>, cx| {
|
.on_drop(|_, files: View<ExternalPaths>, cx| {
|
||||||
dbg!("dropped files!", files.read(cx));
|
eprintln!("dropped files! {:?}", files.read(cx));
|
||||||
})
|
})
|
||||||
.absolute()
|
.absolute()
|
||||||
.inset_0(),
|
.inset_0(),
|
||||||
|
|
|
@ -130,7 +130,7 @@ impl Tab {
|
||||||
.on_drag(move |_view, cx| cx.build_view(|cx| drag_state.clone()))
|
.on_drag(move |_view, cx| cx.build_view(|cx| drag_state.clone()))
|
||||||
.drag_over::<TabDragState>(|d| d.bg(black()))
|
.drag_over::<TabDragState>(|d| d.bg(black()))
|
||||||
.on_drop(|_view, state: View<TabDragState>, cx| {
|
.on_drop(|_view, state: View<TabDragState>, cx| {
|
||||||
dbg!(state.read(cx));
|
eprintln!("{:?}", state.read(cx));
|
||||||
})
|
})
|
||||||
.px_2()
|
.px_2()
|
||||||
.py_0p5()
|
.py_0p5()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue