diff --git a/backend/LexBoxApi/Services/HgService.cs b/backend/LexBoxApi/Services/HgService.cs index a6b534e43..632d79cd4 100644 --- a/backend/LexBoxApi/Services/HgService.cs +++ b/backend/LexBoxApi/Services/HgService.cs @@ -273,26 +273,24 @@ public async Task ExecuteHgRecover(string code, CancellationToken t return response; } - public Task InvalidateDirCache(string code) + public Task InvalidateDirCache(string code) { - // Try very hard to fail tests again - // var repoPath = Path.Join(PrefixRepoFilePath(code)); - // if (Directory.Exists(repoPath)) - // { - // // Invalidate NFS directory cache by forcing a write and re-read of the repo directory - // var randomPath = Path.Join(repoPath, Path.GetRandomFileName()); - // while (File.Exists(randomPath) || Directory.Exists(randomPath)) { randomPath = Path.Join(repoPath, Path.GetRandomFileName()); } - // try - // { - // // Create and delete a directory since that's slightly safer than a file - // var d = Directory.CreateDirectory(randomPath); - // d.Delete(); - // } - // catch (Exception) { } - // } - return Task.CompletedTask; - // var result = ExecuteHgCommandServerCommand(code, "invalidatedircache", default); - // return result; + var repoPath = Path.Join(PrefixRepoFilePath(code)); + if (Directory.Exists(repoPath)) + { + // Invalidate NFS directory cache by forcing a write and re-read of the repo directory + var randomPath = Path.Join(repoPath, Path.GetRandomFileName()); + while (File.Exists(randomPath) || Directory.Exists(randomPath)) { randomPath = Path.Join(repoPath, Path.GetRandomFileName()); } + try + { + // Create and delete a directory since that's slightly safer than a file + var d = Directory.CreateDirectory(randomPath); + d.Delete(); + } + catch (Exception) { } + } + var result = ExecuteHgCommandServerCommand(code, "invalidatedircache", default); + return result; } public async Task GetTipHash(string code) @@ -307,15 +305,14 @@ public async Task WaitForRepoEmptyState(string code, RepoEmptyState expectedStat var done = false; while (!done) { - done = true; // Deliberately try to fail tests - // var hash = await GetTipHash(code); - // var isEmpty = hash == AllZeroHash; - // done = expectedState switch - // { - // RepoEmptyState.Empty => isEmpty, - // RepoEmptyState.NonEmpty => !isEmpty - // }; - // if (!done) await Task.Delay(2500); + var hash = await GetTipHash(code); + var isEmpty = hash == AllZeroHash; + done = expectedState switch + { + RepoEmptyState.Empty => isEmpty, + RepoEmptyState.NonEmpty => !isEmpty + }; + if (!done) await Task.Delay(2500); } } diff --git a/backend/LexCore/ServiceInterfaces/IHgService.cs b/backend/LexCore/ServiceInterfaces/IHgService.cs index 9435226d2..7b77d747d 100644 --- a/backend/LexCore/ServiceInterfaces/IHgService.cs +++ b/backend/LexCore/ServiceInterfaces/IHgService.cs @@ -19,7 +19,7 @@ public interface IHgService Task GetLexEntryCount(string code, ProjectType projectType); Task GetRepositoryIdentifier(Project project); Task ExecuteHgRecover(string code, CancellationToken token); - Task InvalidateDirCache(string code); + Task InvalidateDirCache(string code); bool HasAbandonedTransactions(string projectCode); Task HgCommandHealth(); }