Deliver portable native Architecture B deployment and final verification
This commit is contained in:
1 parent
f451b55de1
commit
36740d2492
92 files changed
+10939
-926
No files matched your search
@@ -7,70 +7,72 @@ using Npgsql;
|
||||
using Observation.AcceptanceTests;
|
||||
using Xunit;
|
||||
namespace HealthApp.AcceptanceTests;
|
||||
|
||||
public sealed class OperationalTests(ObservationApiFixture fixture) : IClassFixture<ObservationApiFixture>
|
||||
{
|
||||
[Fact]
|
||||
public async Task Readiness_uses_configured_schemas_and_guidance_remains_public_during_database_outage()
|
||||
{
|
||||
var token=await AuthenticatedTestClient.LoginAsync(fixture.RawClient);
|
||||
async Task<HttpResponseMessage> Ready(){using var q=new HttpRequestMessage(HttpMethod.Get,"/health/ready");q.Headers.Authorization=new AuthenticationHeaderValue("Bearer",token);return await fixture.RawClient.SendAsync(q);}
|
||||
using(var ready=await Ready())Assert.Equal(HttpStatusCode.OK,ready.StatusCode);
|
||||
await fixture.StopObservationServiceAsync();
|
||||
try
|
||||
{
|
||||
using var notReady=await Ready();Assert.Equal(HttpStatusCode.ServiceUnavailable,notReady.StatusCode);
|
||||
using var guidance=await fixture.RawClient.GetAsync("/api/measurement-guidance");Assert.Equal(HttpStatusCode.OK,guidance.StatusCode);
|
||||
Assert.NotEmpty(await AuthenticatedTestClient.LoginAsync(fixture.RawClient));
|
||||
}
|
||||
finally{await fixture.RestartHostsAsync();}
|
||||
}
|
||||
[Fact]
|
||||
public async Task Deadline_cancels_locked_write_without_changing_profile()
|
||||
{
|
||||
using var create=await fixture.Client.PostAsJsonAsync("/api/patients",new{name="Keep",dateOfBirth="1980-01-01"});var p=(await create.Content.ReadFromJsonAsync<PatientDto>())!;
|
||||
fixture.AdditionalGatewayConfiguration["Resources:RequestDeadlineSeconds"]="0.2";await fixture.RestartHostsAsync();
|
||||
await using var c=new NpgsqlConnection(fixture.ConnectionString);await c.OpenAsync();await using var t=await c.BeginTransactionAsync();
|
||||
await new NpgsqlCommand("SELECT patient_id FROM profile.patient WHERE patient_id=@id FOR UPDATE",c,t){Parameters={new NpgsqlParameter("id",p.PatientId)}}.ExecuteScalarAsync();
|
||||
try
|
||||
{
|
||||
using var timed=await fixture.Client.PutAsJsonAsync($"/api/patients/{p.PatientId}",new{name="Must not persist"});
|
||||
Assert.Equal(HttpStatusCode.GatewayTimeout,timed.StatusCode);
|
||||
await t.RollbackAsync();var saved=(await fixture.Client.GetFromJsonAsync<PatientDto>($"/api/patients/{p.PatientId}"))!;Assert.Equal("Keep",saved.Name);
|
||||
}
|
||||
finally{fixture.AdditionalGatewayConfiguration.Remove("Resources:RequestDeadlineSeconds");await fixture.RestartHostsAsync();}
|
||||
}
|
||||
[Fact]
|
||||
public async Task Assessment_admission_does_not_block_guidance_and_overload_is_explicit()
|
||||
{
|
||||
using var create=await fixture.Client.PostAsJsonAsync("/api/patients",new{name="Budget",dateOfBirth="1980-01-01"});var p=(await create.Content.ReadFromJsonAsync<PatientDto>())!;
|
||||
fixture.AdditionalGatewayConfiguration["Resources:MaxConcurrentAssessments"]="1";await fixture.RestartHostsAsync();
|
||||
var held=new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);var release=new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
fixture.ConfigureServices=services=>{
|
||||
var descriptor=services.Last(d=>d.ServiceType==typeof(ProfileQueries));services.Remove(descriptor);
|
||||
services.AddScoped<ProfileQueries>(sp=>new PausedProfile((ProfileQueries)descriptor.ImplementationFactory!(sp),async()=>{held.TrySetResult();await release.Task;}));
|
||||
};await fixture.RestartHostsAsync();
|
||||
try
|
||||
{
|
||||
var path=$"/api/patients/{p.PatientId}/overview?from=2026-09-01&to=2026-09-30";var first=fixture.Client.GetAsync(path);await held.Task.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
using var second=await fixture.Client.GetAsync(path);Assert.Equal(HttpStatusCode.ServiceUnavailable,second.StatusCode);Assert.NotNull(second.Headers.RetryAfter);
|
||||
using var guidance=await fixture.RawClient.GetAsync("/api/measurement-guidance");Assert.Equal(HttpStatusCode.OK,guidance.StatusCode);
|
||||
release.SetResult();using var completed=await first;Assert.Equal(HttpStatusCode.OK,completed.StatusCode);
|
||||
}
|
||||
finally{release.TrySetResult();fixture.ConfigureServices=null;fixture.AdditionalGatewayConfiguration.Remove("Resources:MaxConcurrentAssessments");await fixture.RestartHostsAsync();}
|
||||
}
|
||||
private sealed class PausedProfile(ProfileQueries inner,Func<Task> pause) : ProfileQueries
|
||||
{
|
||||
public Task<Guid?> ResolveAccountAsync(string a,CancellationToken ct)=>inner.ResolveAccountAsync(a,ct);
|
||||
public async Task<PatientDto?> GetAsync(AuthorizedPatientContext scope,CancellationToken ct){var p=await inner.GetAsync(scope,ct);await pause();return p;}
|
||||
}
|
||||
[Fact]
|
||||
public async Task Remote_connection_without_hostname_verified_tls_is_rejected_before_start()
|
||||
{
|
||||
fixture.AdditionalGatewayConfiguration["Database:Remote"]="true";
|
||||
try
|
||||
{
|
||||
var e=await Assert.ThrowsAsync<InvalidOperationException>(()=>fixture.RestartHostsAsync());Assert.Contains("verified TLS",e.Message);
|
||||
}
|
||||
finally{fixture.AdditionalGatewayConfiguration.Remove("Database:Remote");await fixture.RestartHostsAsync();}
|
||||
}
|
||||
[Fact]
|
||||
public async Task Readiness_uses_configured_schemas_and_guidance_remains_public_during_database_outage()
|
||||
{
|
||||
var token = await AuthenticatedTestClient.LoginAsync(fixture.RawClient);
|
||||
async Task<HttpResponseMessage> Ready() { using var q = new HttpRequestMessage(HttpMethod.Get, "/health/ready"); q.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); return await fixture.RawClient.SendAsync(q); }
|
||||
using (var ready = await Ready()) Assert.Equal(HttpStatusCode.OK, ready.StatusCode);
|
||||
await fixture.StopObservationServiceAsync();
|
||||
try
|
||||
{
|
||||
using var notReady = await Ready(); Assert.Equal(HttpStatusCode.ServiceUnavailable, notReady.StatusCode);
|
||||
using var guidance = await fixture.RawClient.GetAsync("/api/measurement-guidance"); Assert.Equal(HttpStatusCode.OK, guidance.StatusCode);
|
||||
Assert.NotEmpty(await AuthenticatedTestClient.LoginAsync(fixture.RawClient));
|
||||
}
|
||||
finally { await fixture.RestartHostsAsync(); }
|
||||
}
|
||||
[Fact]
|
||||
public async Task Deadline_cancels_locked_write_without_changing_profile()
|
||||
{
|
||||
using var create = await fixture.Client.PostAsJsonAsync("/api/patients", new { name = "Keep", dateOfBirth = "1980-01-01" }); var p = (await create.Content.ReadFromJsonAsync<PatientDto>())!;
|
||||
fixture.AdditionalGatewayConfiguration["Resources:RequestDeadlineSeconds"] = "0.2"; await fixture.RestartHostsAsync();
|
||||
await using var c = new NpgsqlConnection(fixture.ConnectionString); await c.OpenAsync(); await using var t = await c.BeginTransactionAsync();
|
||||
await new NpgsqlCommand("SELECT patient_id FROM profile.patient WHERE patient_id=@id FOR UPDATE", c, t) { Parameters = { new NpgsqlParameter("id", p.PatientId) } }.ExecuteScalarAsync();
|
||||
try
|
||||
{
|
||||
using var timed = await fixture.Client.PutAsJsonAsync($"/api/patients/{p.PatientId}", new { name = "Must not persist" });
|
||||
Assert.Equal(HttpStatusCode.GatewayTimeout, timed.StatusCode);
|
||||
await t.RollbackAsync(); var saved = (await fixture.Client.GetFromJsonAsync<PatientDto>($"/api/patients/{p.PatientId}"))!; Assert.Equal("Keep", saved.Name);
|
||||
}
|
||||
finally { fixture.AdditionalGatewayConfiguration.Remove("Resources:RequestDeadlineSeconds"); await fixture.RestartHostsAsync(); }
|
||||
}
|
||||
[Fact]
|
||||
public async Task Assessment_admission_does_not_block_guidance_and_overload_is_explicit()
|
||||
{
|
||||
using var create = await fixture.Client.PostAsJsonAsync("/api/patients", new { name = "Budget", dateOfBirth = "1980-01-01" }); var p = (await create.Content.ReadFromJsonAsync<PatientDto>())!;
|
||||
fixture.AdditionalGatewayConfiguration["Resources:MaxConcurrentAssessments"] = "1"; await fixture.RestartHostsAsync();
|
||||
var held = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var release = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
fixture.ConfigureServices = services =>
|
||||
{
|
||||
var descriptor = services.Last(d => d.ServiceType == typeof(ProfileQueries)); services.Remove(descriptor);
|
||||
services.AddScoped<ProfileQueries>(sp => new PausedProfile((ProfileQueries)descriptor.ImplementationFactory!(sp), async () => { held.TrySetResult(); await release.Task; }));
|
||||
}; await fixture.RestartHostsAsync();
|
||||
try
|
||||
{
|
||||
var path = $"/api/patients/{p.PatientId}/overview?from=2026-09-01&to=2026-09-30"; var first = fixture.Client.GetAsync(path); await held.Task.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
using var second = await fixture.Client.GetAsync(path); Assert.Equal(HttpStatusCode.ServiceUnavailable, second.StatusCode); Assert.NotNull(second.Headers.RetryAfter);
|
||||
using var guidance = await fixture.RawClient.GetAsync("/api/measurement-guidance"); Assert.Equal(HttpStatusCode.OK, guidance.StatusCode);
|
||||
release.SetResult(); using var completed = await first; Assert.Equal(HttpStatusCode.OK, completed.StatusCode);
|
||||
}
|
||||
finally { release.TrySetResult(); fixture.ConfigureServices = null; fixture.AdditionalGatewayConfiguration.Remove("Resources:MaxConcurrentAssessments"); await fixture.RestartHostsAsync(); }
|
||||
}
|
||||
private sealed class PausedProfile(ProfileQueries inner, Func<Task> pause) : ProfileQueries
|
||||
{
|
||||
public Task<Guid?> ResolveAccountAsync(string a, CancellationToken ct) => inner.ResolveAccountAsync(a, ct);
|
||||
public async Task<PatientDto?> GetAsync(AuthorizedPatientContext scope, CancellationToken ct) { var p = await inner.GetAsync(scope, ct); await pause(); return p; }
|
||||
}
|
||||
[Fact]
|
||||
public async Task Remote_connection_without_hostname_verified_tls_is_rejected_before_start()
|
||||
{
|
||||
fixture.AdditionalGatewayConfiguration["Database:Remote"] = "true";
|
||||
try
|
||||
{
|
||||
var e = await Assert.ThrowsAsync<InvalidOperationException>(() => fixture.RestartHostsAsync()); Assert.Contains("verified TLS", e.Message);
|
||||
}
|
||||
finally { fixture.AdditionalGatewayConfiguration.Remove("Database:Remote"); await fixture.RestartHostsAsync(); }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user