mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-28 20:01:33 +00:00
Fix integration test verifying the rename behavior
Specifically, the test now ensures that the host's worktree observes a/file1's change event *before* the rename occurs, otherwise when interpreting the change event it will mistakenly think that the file has been deleted (because its path has changed) and will subsequently fail to detect the rename, causing the test to fail.
This commit is contained in:
parent
7b9ff42679
commit
f2b4a0665f
2 changed files with 19 additions and 6 deletions
|
@ -2124,7 +2124,7 @@ struct UpdateIgnoreStatusJob {
|
|||
}
|
||||
|
||||
pub trait WorktreeHandle {
|
||||
#[cfg(test)]
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
fn flush_fs_events<'a>(
|
||||
&self,
|
||||
cx: &'a gpui::TestAppContext,
|
||||
|
@ -2138,7 +2138,7 @@ impl WorktreeHandle for ModelHandle<Worktree> {
|
|||
//
|
||||
// This function mutates the worktree's directory and waits for those mutations to be picked up,
|
||||
// to ensure that all redundant FS events have already been processed.
|
||||
#[cfg(test)]
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
fn flush_fs_events<'a>(
|
||||
&self,
|
||||
cx: &'a gpui::TestAppContext,
|
||||
|
@ -2146,14 +2146,22 @@ impl WorktreeHandle for ModelHandle<Worktree> {
|
|||
use smol::future::FutureExt;
|
||||
|
||||
let filename = "fs-event-sentinel";
|
||||
let root_path = cx.read(|cx| self.read(cx).as_local().unwrap().abs_path().clone());
|
||||
let tree = self.clone();
|
||||
let (fs, root_path) = self.read_with(cx, |tree, _| {
|
||||
let tree = tree.as_local().unwrap();
|
||||
(tree.fs.clone(), tree.abs_path().clone())
|
||||
});
|
||||
|
||||
async move {
|
||||
std::fs::write(root_path.join(filename), "").unwrap();
|
||||
fs.create_file(&root_path.join(filename), Default::default())
|
||||
.await
|
||||
.unwrap();
|
||||
tree.condition(&cx, |tree, _| tree.entry_for_path(filename).is_some())
|
||||
.await;
|
||||
|
||||
std::fs::remove_file(root_path.join(filename)).unwrap();
|
||||
fs.remove_file(&root_path.join(filename), Default::default())
|
||||
.await
|
||||
.unwrap();
|
||||
tree.condition(&cx, |tree, _| tree.entry_for_path(filename).is_none())
|
||||
.await;
|
||||
|
||||
|
|
|
@ -1238,7 +1238,7 @@ mod tests {
|
|||
LanguageConfig, LanguageRegistry, LanguageServerConfig, Point,
|
||||
},
|
||||
lsp,
|
||||
project::{DiagnosticSummary, Project, ProjectPath},
|
||||
project::{worktree::WorktreeHandle, DiagnosticSummary, Project, ProjectPath},
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -1608,6 +1608,11 @@ mod tests {
|
|||
buffer_b.read_with(&cx_b, |buf, _| assert!(!buf.is_dirty()));
|
||||
buffer_c.condition(&cx_c, |buf, _| !buf.is_dirty()).await;
|
||||
|
||||
// Ensure worktree observes a/file1's change event *before* the rename occurs, otherwise
|
||||
// when interpreting the change event it will mistakenly think that the file has been
|
||||
// deleted (because its path has changed) and will subsequently fail to detect the rename.
|
||||
worktree_a.flush_fs_events(&cx_a).await;
|
||||
|
||||
// Make changes on host's file system, see those changes on guest worktrees.
|
||||
fs.rename(
|
||||
"/a/file1".as_ref(),
|
||||
|
|
Loading…
Reference in a new issue