project: Try to make git tests less flaky (#32234)

Closes #ISSUE

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Ben Kunkle 2025-06-06 08:01:42 -05:00 committed by GitHub
parent 3da1de2a48
commit 508b604b67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7507,7 +7507,8 @@ async fn test_repository_and_path_for_project_path(
let project = Project::test(fs.clone(), [path!("/root").as_ref()], cx).await; let project = Project::test(fs.clone(), [path!("/root").as_ref()], cx).await;
let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
let tree_id = tree.read_with(cx, |tree, _| tree.id()); let tree_id = tree.read_with(cx, |tree, _| tree.id());
tree.read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.run_until_parked(); cx.run_until_parked();
@ -7585,7 +7586,9 @@ async fn test_home_dir_as_git_repository(cx: &mut gpui::TestAppContext) {
let project = Project::test(fs.clone(), [path!("/root/home/project").as_ref()], cx).await; let project = Project::test(fs.clone(), [path!("/root/home/project").as_ref()], cx).await;
let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
let tree_id = tree.read_with(cx, |tree, _| tree.id()); let tree_id = tree.read_with(cx, |tree, _| tree.id());
tree.read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete())
project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
@ -7600,7 +7603,8 @@ async fn test_home_dir_as_git_repository(cx: &mut gpui::TestAppContext) {
let project = Project::test(fs.clone(), [path!("/root/home").as_ref()], cx).await; let project = Project::test(fs.clone(), [path!("/root/home").as_ref()], cx).await;
let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
let tree_id = tree.read_with(cx, |tree, _| tree.id()); let tree_id = tree.read_with(cx, |tree, _| tree.id());
tree.read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
@ -7654,7 +7658,8 @@ async fn test_git_repository_status(cx: &mut gpui::TestAppContext) {
let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -7687,7 +7692,8 @@ async fn test_git_repository_status(cx: &mut gpui::TestAppContext) {
std::fs::write(work_dir.join("c.txt"), "some changes").unwrap(); std::fs::write(work_dir.join("c.txt"), "some changes").unwrap();
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -7721,14 +7727,16 @@ async fn test_git_repository_status(cx: &mut gpui::TestAppContext) {
git_remove_index(Path::new("d.txt"), &repo); git_remove_index(Path::new("d.txt"), &repo);
git_commit("Another commit", &repo); git_commit("Another commit", &repo);
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
std::fs::remove_file(work_dir.join("a.txt")).unwrap(); std::fs::remove_file(work_dir.join("a.txt")).unwrap();
std::fs::remove_file(work_dir.join("b.txt")).unwrap(); std::fs::remove_file(work_dir.join("b.txt")).unwrap();
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -7777,7 +7785,8 @@ async fn test_git_status_postprocessing(cx: &mut gpui::TestAppContext) {
let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -7908,7 +7917,8 @@ async fn test_conflicted_cherry_pick(cx: &mut gpui::TestAppContext) {
let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -7938,7 +7948,8 @@ async fn test_conflicted_cherry_pick(cx: &mut gpui::TestAppContext) {
collections::HashMap::from_iter([("a.txt".to_owned(), git2::Status::CONFLICTED)]) collections::HashMap::from_iter([("a.txt".to_owned(), git2::Status::CONFLICTED)])
); );
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
let conflicts = repository.update(cx, |repository, _| { let conflicts = repository.update(cx, |repository, _| {
@ -7994,7 +8005,8 @@ async fn test_update_gitignore(cx: &mut gpui::TestAppContext) {
let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -8064,7 +8076,8 @@ async fn test_rename_work_directory(cx: &mut gpui::TestAppContext) {
let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -8164,7 +8177,8 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -8192,7 +8206,8 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
// Modify a file in the working copy. // Modify a file in the working copy.
std::fs::write(work_dir.join(A_TXT), "aa").unwrap(); std::fs::write(work_dir.join(A_TXT), "aa").unwrap();
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -8209,6 +8224,9 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
git_add(B_TXT, &repo); git_add(B_TXT, &repo);
git_commit("Committing modified and added", &repo); git_commit("Committing modified and added", &repo);
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
// The worktree detects that the files' git status have changed. // The worktree detects that the files' git status have changed.
@ -8228,6 +8246,9 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
std::fs::write(work_dir.join(E_TXT), "eeee").unwrap(); std::fs::write(work_dir.join(E_TXT), "eeee").unwrap();
std::fs::write(work_dir.join(BUILD_FILE), "this should be ignored").unwrap(); std::fs::write(work_dir.join(BUILD_FILE), "this should be ignored").unwrap();
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
// Check that more complex repo changes are tracked // Check that more complex repo changes are tracked
@ -8268,6 +8289,9 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
.unwrap(); .unwrap();
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
repository.read_with(cx, |repository, _cx| { repository.read_with(cx, |repository, _cx| {
@ -8289,6 +8313,9 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
.unwrap(); .unwrap();
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
repository.read_with(cx, |repository, _cx| { repository.read_with(cx, |repository, _cx| {
@ -8327,10 +8354,10 @@ async fn test_repos_in_invisible_worktrees(
.await; .await;
let project = Project::test(fs.clone(), [path!("/root/dir1/dep1").as_ref()], cx).await; let project = Project::test(fs.clone(), [path!("/root/dir1/dep1").as_ref()], cx).await;
let visible_worktree = let _visible_worktree =
project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
visible_worktree project
.read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete()) .update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
let repos = project.read_with(cx, |project, cx| { let repos = project.read_with(cx, |project, cx| {
@ -8342,7 +8369,7 @@ async fn test_repos_in_invisible_worktrees(
}); });
pretty_assertions::assert_eq!(repos, [Path::new(path!("/root/dir1/dep1")).into()]); pretty_assertions::assert_eq!(repos, [Path::new(path!("/root/dir1/dep1")).into()]);
let (invisible_worktree, _) = project let (_invisible_worktree, _) = project
.update(cx, |project, cx| { .update(cx, |project, cx| {
project.worktree_store.update(cx, |worktree_store, cx| { project.worktree_store.update(cx, |worktree_store, cx| {
worktree_store.find_or_create_worktree(path!("/root/dir1/b.txt"), false, cx) worktree_store.find_or_create_worktree(path!("/root/dir1/b.txt"), false, cx)
@ -8350,8 +8377,8 @@ async fn test_repos_in_invisible_worktrees(
}) })
.await .await
.expect("failed to create worktree"); .expect("failed to create worktree");
invisible_worktree project
.read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete()) .update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
let repos = project.read_with(cx, |project, cx| { let repos = project.read_with(cx, |project, cx| {
@ -8405,7 +8432,8 @@ async fn test_rescan_with_gitignore(cx: &mut gpui::TestAppContext) {
let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -8546,16 +8574,7 @@ async fn test_git_worktrees_and_submodules(cx: &mut gpui::TestAppContext) {
.await; .await;
let project = Project::test(fs.clone(), [path!("/project").as_ref()], cx).await; let project = Project::test(fs.clone(), [path!("/project").as_ref()], cx).await;
let scan_complete = project.update(cx, |project, cx| { let scan_complete = project.update(cx, |project, cx| project.git_scans_complete(cx));
project
.worktrees(cx)
.next()
.unwrap()
.read(cx)
.as_local()
.unwrap()
.scan_complete()
});
scan_complete.await; scan_complete.await;
let mut repositories = project.update(cx, |project, cx| { let mut repositories = project.update(cx, |project, cx| {
@ -8690,7 +8709,8 @@ async fn test_repository_deduplication(cx: &mut gpui::TestAppContext) {
let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap()); let tree = project.read_with(cx, |project, cx| project.worktrees(cx).next().unwrap());
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) project
.update(cx, |project, cx| project.git_scans_complete(cx))
.await; .await;
cx.executor().run_until_parked(); cx.executor().run_until_parked();
@ -9015,11 +9035,9 @@ async fn test_find_project_path_abs(
.await; .await;
// Make sure the worktrees are fully initialized // Make sure the worktrees are fully initialized
for worktree in project.read_with(cx, |project, cx| project.worktrees(cx).collect::<Vec<_>>()) { project
worktree .update(cx, |project, cx| project.git_scans_complete(cx))
.read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete()) .await;
.await;
}
cx.run_until_parked(); cx.run_until_parked();
let (project1_abs_path, project1_id, project2_abs_path, project2_id) = let (project1_abs_path, project1_id, project2_abs_path, project2_id) =