Skip to content

Commit

Permalink
simplify project not found test, add logging for tracking the issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Aug 4, 2023
1 parent 71f1165 commit 3f79da4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
7 changes: 5 additions & 2 deletions backend/LexBoxApi/Services/HgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ public class HgService : IHgService
{
private readonly IOptions<HgConfig> _options;
private readonly IHttpClientFactory _clientFactory;
private readonly ILogger<HgService> _logger;

public HgService(IOptions<HgConfig> options, IHttpClientFactory clientFactory)
public HgService(IOptions<HgConfig> options, IHttpClientFactory clientFactory, ILogger<HgService> logger)
{
_options = options;
_clientFactory = clientFactory;
_logger = logger;
}

public async Task InitRepo(string code)
Expand Down Expand Up @@ -72,11 +74,12 @@ public async Task<Changeset[]> GetChangesets(string projectCode)

public async Task WaitForRepoReady(string projectCode)
{
_logger.LogInformation("Waiting for repository {Code} to be ready...", projectCode);
var (success, response) = await WaitFor(async () =>
{
var client = _clientFactory.CreateClient("hgWeg");
var response = await client.GetAsync($"{_options.Value.HgWebUrl}/hg/{projectCode}/log?style=json-lex&rev=tip");
Console.WriteLine("Response code: " + response.StatusCode);
_logger.LogInformation("Waiting for {Code}, Response code: {StatusCode}", projectCode, response.StatusCode);
return (response.IsSuccessStatusCode, response);
});

Expand Down
62 changes: 31 additions & 31 deletions backend/Testing/ApiTests/NewProjectRaceCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@ public class NewProjectRaceCondition : ApiTestBase
public async Task CanCreateProjectAndQueryItRightAway()
{
await LoginAs("admin", "pass");
//force the hg refresh to trigger, then the first new repo will fail instead of the second
await HttpClient.GetAsync($"http://{Host}/api/project/lastCommitForRepo?code=sena-3");

for (var i = 0; i < 2; i++)
{
var projectId = Guid.NewGuid();
var projectCode = "test-race-flex--" + projectId.ToString().Split('-')[0];
var projectId = Guid.NewGuid();
var projectCode = "test-race-flex--" + projectId.ToString().Split('-')[0];

try
{
var response = await ExecuteGql($$"""
mutation {
createProject(input: {
name: "Test race condition",
type: FL_EX,
id: "{{projectId}}",
code: "{{projectCode}}",
description: "this is just a testing project for testing a race condition",
retentionPolicy: DEV
}) {
project {
name
changesets {
desc
}
try
{
var response = await ExecuteGql($$"""
mutation {
createProject(input: {
name: "Test race condition",
type: FL_EX,
id: "{{projectId}}",
code: "{{projectCode}}",
description: "this is just a testing project for testing a race condition",
retentionPolicy: DEV
}) {
project {
name
changesets {
desc
}
}
}
}
""");
var project = response["data"]!["createProject"]!["project"].ShouldBeOfType<JsonObject>();
project["name"]!.GetValue<string>().ShouldBe("Test race condition");
}
}
}
""");
var project = response["data"]!["createProject"]!["project"].ShouldBeOfType<JsonObject>();
project["name"]!.GetValue<string>().ShouldBe("Test race condition");
}
finally
{
await HttpClient.DeleteAsync($"http://{Host}/api/project/project/{projectId}");
}
finally
{
await HttpClient.DeleteAsync($"http://{Host}/api/project/project/{projectId}");
}

}
}

0 comments on commit 3f79da4

Please sign in to comment.