Skip to content

Commit

Permalink
Go back to running proper HgService code
Browse files Browse the repository at this point in the history
Stop trying to make tests fail, and try to make them pass again
  • Loading branch information
rmunn committed May 29, 2024
1 parent 28201a6 commit 1141de1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
53 changes: 25 additions & 28 deletions backend/LexBoxApi/Services/HgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,26 +273,24 @@ public async Task<HttpContent> ExecuteHgRecover(string code, CancellationToken t
return response;
}

public Task InvalidateDirCache(string code)
public Task<HttpContent> 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<string> GetTipHash(string code)
Expand All @@ -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

Check warning on line 310 in backend/LexBoxApi/Services/HgService.cs

View workflow job for this annotation

GitHub Actions / Build API / publish-api

The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. For example, the pattern '(LexBoxApi.Services.RepoEmptyState)2' is not covered.
{
RepoEmptyState.Empty => isEmpty,
RepoEmptyState.NonEmpty => !isEmpty
};
if (!done) await Task.Delay(2500);
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/LexCore/ServiceInterfaces/IHgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IHgService
Task<int?> GetLexEntryCount(string code, ProjectType projectType);
Task<string?> GetRepositoryIdentifier(Project project);
Task<HttpContent> ExecuteHgRecover(string code, CancellationToken token);
Task InvalidateDirCache(string code);
Task<HttpContent> InvalidateDirCache(string code);
bool HasAbandonedTransactions(string projectCode);
Task<string> HgCommandHealth();
}

0 comments on commit 1141de1

Please sign in to comment.