Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jbialobr/3148d90ff556dba603cf to your computer and use it in GitHub Desktop.
Save jbialobr/3148d90ff556dba603cf to your computer and use it in GitHub Desktop.
public void CanConcurrentlyDeleteFilesWhileStatusIsBeingCalculated()
{
string repoPath = InitNewRepository();
using (var repo = new Repository(repoPath))
{
var paths = new List<string>();
const int numberOfFiles = 3000;
for (var i = 0; i < numberOfFiles; i++)
{
string s = i.ToString(CultureInfo.InvariantCulture);
string path = Path.Combine(repo.Info.WorkingDirectory, s + ".txt");
File.AppendAllText(path, s);
repo.Index.Stage(path);
paths.Add(path);
}
bool deletionDone = false;
Assert.Equal(0, repo.Index.RetrieveStatus().Missing.Count());
Task task = Task.Factory.StartNew(() =>
{
var loops = 0;
while (!deletionDone)
{
var filePaths = repo.Index.RetrieveStatus().Where(entry => entry.State != FileStatus.Ignored).ToArray();
Assert.NotNull(filePaths);
loops++;
}
});
foreach (var path in paths)
{
File.Delete(path);
}
deletionDone = true;
task.Wait();
Assert.True(loops > 0);
Assert.Equal(numberOfFiles, repo.Index.RetrieveStatus().Missing.Count());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment