Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,28 @@ await WaitForConditionAsync(
succeedConfigLog = _writer.ToString();
}

HttpResponseMessage restResult = await _testClient.GetAsync("/rest/Book");
// Retry REST request because metadata re-initialization happens asynchronously
// after the "Validated hot-reloaded configuration file" message. The metadata provider
// factory clears and re-initializes providers on the hot-reload thread, so requests
// arriving before that completes will fail.
HttpResponseMessage restResult = null;
bool restSucceeded = false;
for (int attempt = 1; attempt <= 10; attempt++)
{
restResult = await _testClient.GetAsync("/rest/Book");
if (restResult.StatusCode == HttpStatusCode.OK)
{
restSucceeded = true;
break;
}

await Task.Delay(1000);
}

// Assert
Assert.IsTrue(failedConfigLog.Contains(HOT_RELOAD_FAILURE_MESSAGE));
Assert.IsTrue(succeedConfigLog.Contains(HOT_RELOAD_SUCCESS_MESSAGE));
Assert.AreEqual(HttpStatusCode.OK, restResult.StatusCode);
Assert.IsTrue(restSucceeded, $"REST request did not return OK after hot-reload. Last status: {restResult?.StatusCode}");
}

/// <summary>
Expand Down Expand Up @@ -838,12 +854,28 @@ await WaitForConditionAsync(
succeedConfigLog = _writer.ToString();
}

HttpResponseMessage restResult = await _testClient.GetAsync("/rest/Book");
// Retry REST request because metadata re-initialization happens asynchronously
// after the "Validated hot-reloaded configuration file" message. The metadata provider
// factory clears and re-initializes providers on the hot-reload thread, so requests
// arriving before that completes will fail.
HttpResponseMessage restResult = null;
bool restSucceeded = false;
for (int attempt = 1; attempt <= 10; attempt++)
{
restResult = await _testClient.GetAsync("/rest/Book");
if (restResult.StatusCode == HttpStatusCode.OK)
{
restSucceeded = true;
break;
}

await Task.Delay(1000);
}

// Assert
Assert.IsTrue(failedConfigLog.Contains(HOT_RELOAD_FAILURE_MESSAGE));
Assert.IsTrue(succeedConfigLog.Contains(HOT_RELOAD_SUCCESS_MESSAGE));
Assert.AreEqual(HttpStatusCode.OK, restResult.StatusCode);
Assert.IsTrue(restSucceeded, $"REST request did not return OK after hot-reload. Last status: {restResult?.StatusCode}");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public async Task WriteResponseAsync(HttpContext context)
// Ensure cachedResponse is not null before calling WriteAsync
if (report != null)
{
// Set currentRole per-request (not cached) so each caller sees their own role
// Set current-role per-request (not cached) so each caller sees their own role
await context.Response.WriteAsync(SerializeReport(report with { CurrentRole = _healthCheckHelper.GetCurrentRole(roleHeader, roleToken) }));
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public record ComprehensiveHealthCheckReport
/// <summary>
/// The current role of the user making the request (e.g., "anonymous", "authenticated").
/// </summary>
[JsonPropertyName("currentRole")]
[JsonPropertyName("current-role")]
public string? CurrentRole { get; set; }

/// <summary>
Expand Down