From 3f79da497750b39cf244b474e1a5b41ca7a6c4d3 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Fri, 4 Aug 2023 10:15:25 +0700 Subject: [PATCH] simplify project not found test, add logging for tracking the issue. --- backend/LexBoxApi/Services/HgService.cs | 7 ++- .../ApiTests/NewProjectRaceCondition.cs | 62 +++++++++---------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/backend/LexBoxApi/Services/HgService.cs b/backend/LexBoxApi/Services/HgService.cs index 676abe7af..d15c924dd 100644 --- a/backend/LexBoxApi/Services/HgService.cs +++ b/backend/LexBoxApi/Services/HgService.cs @@ -13,11 +13,13 @@ public class HgService : IHgService { private readonly IOptions _options; private readonly IHttpClientFactory _clientFactory; + private readonly ILogger _logger; - public HgService(IOptions options, IHttpClientFactory clientFactory) + public HgService(IOptions options, IHttpClientFactory clientFactory, ILogger logger) { _options = options; _clientFactory = clientFactory; + _logger = logger; } public async Task InitRepo(string code) @@ -72,11 +74,12 @@ public async Task 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); }); diff --git a/backend/Testing/ApiTests/NewProjectRaceCondition.cs b/backend/Testing/ApiTests/NewProjectRaceCondition.cs index c9fae9aac..25bf08ca7 100644 --- a/backend/Testing/ApiTests/NewProjectRaceCondition.cs +++ b/backend/Testing/ApiTests/NewProjectRaceCondition.cs @@ -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(); + project["name"]!.GetValue().ShouldBe("Test race condition"); } - } -} -"""); - var project = response["data"]!["createProject"]!["project"].ShouldBeOfType(); - project["name"]!.GetValue().ShouldBe("Test race condition"); - } - finally - { - await HttpClient.DeleteAsync($"http://{Host}/api/project/project/{projectId}"); - } + finally + { + await HttpClient.DeleteAsync($"http://{Host}/api/project/project/{projectId}"); } + } }