8000 Delete directories in reverse order to make the CanConcurrentlyDelete… · GiTechLab/libgit2sharp@9923794 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9923794

Browse files
committed
Delete directories in reverse order to make the CanConcurrentlyDeleteFilesWhileStatusIsBeingCalculated test fail.
1 parent 583a672 commit 9923794

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

LibGit2Sharp.Tests/StatusFixture.cs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -544,44 +544,48 @@ public void CanExcludeStatusOfFilesInSubmodule()
544544
public void CanConcurrentlyDeleteFilesWhileStatusIsBeingCalculated()
545545
{
546546
string repoPath = InitNewRepository();
547-
548547
using (var repo = new Repository(repoPath))
549548
{
550-
var paths = new List<string>();
549+
var files = new List<string>();
550+
var dirs = new List<string>();
551551
const int numberOfFiles = 3000;
552-
552+
string dirFormat = "D" + Math.Ceiling(Math.Log10(numberOfFiles));
553553
for (var i = 0; i < numberOfFiles; i++)
554554
{
555-
string s = i.ToString(CultureInfo.InvariantCulture);
556-
string path = Path.Combine(repo.Info.WorkingDirectory, s + ".txt");
557-
File.AppendAllText(path, s);
558-
repo.Index.Stage(path);
559-
paths.Add(path);
555+
string s = i.ToString(dirFormat, CultureInfo.InvariantCulture);
556+
string dirPath = Path.Combine(repo.Info.WorkingDirectory, s);
557+
Directory.CreateDirectory(dirPath);
558+
string filePath = Path.Combine(dirPath, s + ".txt");
559+
File.AppendAllText(filePath, s);
560+
files.Add(filePath);
561+
dirs.Add(dirPath);
560562
}
561-
562563
bool deletionDone = false;
563-
Assert.Equal(0, repo.Index.RetrieveStatus().Missing.Count());
564-
565-
Task.Factory.StartNew(() =>
564+
var loops = 0;
565+
Assert.Equal(numberOfFiles, repo.Index.RetrieveStatus().Untracked.Count());
566+
Task task = Task.Factory.StartNew(() =>
566567
{
567-
foreach (var path in paths)
568+
while (!deletionDone)
568569
{
569-
File.Delete(path);
570+
var filePaths = repo.Index.RetrieveStatus().Where(entry => entry.State != FileStatus.Ignored).ToArray();
571+
Assert.NotNull(filePaths);
572+
loops++;
570573
}
571-
572-
deletionDone = true;
573574
});
574575

575-
var loops = 0;
576-
while (!deletionDone)
576+
dirs.Reverse();
577+
578+
foreach (var path in dirs)
577579
{
578-
var filePaths = repo.Index.RetrieveStatus().Where(entry => entry.State != FileStatus.Ignored).ToArray();
579-
Assert.NotNull(filePaths);
580-
loops++;
580+
Directory.Delete(path, true);
581+
System.Threading.Thread.Sleep(3);
581582
}
583+
deletionDone = true;
584+
585+
task.Wait();
582586

583587
Assert.True(loops > 0);
584-
Assert.Equal(numberOfFiles, repo.Index.RetrieveStatus().Missing.Count());
588+
Assert.Equal(0, repo.Index.RetrieveStatus().Untracked.Count());
585589
}
586590
}
587591
}

0 commit comments

Comments
 (0)
0