fix(admin-ui): distinguish deployment acceptance and application progress
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
using Bunit;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
||||
|
||||
/// <summary>Acceptance, recorded application state, unavailable reads and no-change outcomes stay distinct.</summary>
|
||||
[Trait("Category","Unit")]
|
||||
public sealed class DeploymentFeedbackTests : BunitContext
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(DeploymentStatus.Dispatching)]
|
||||
[InlineData(DeploymentStatus.AwaitingApplyAcks)]
|
||||
public void AcceptedRequest_IsNotCompletedApplication(DeploymentStatus status)
|
||||
{
|
||||
var cut=Render<DeploymentFeedback>(p=>p.Add(x=>x.RequestOutcome,StartDeploymentOutcome.Accepted).Add(x=>x.Status,status));
|
||||
cut.Find("[role=status]").TextContent.ShouldContain("in progress");
|
||||
cut.Find("[role=status]").TextContent.ShouldNotContain("completed");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(DeploymentStatus.Dispatching,"Dispatching")]
|
||||
[InlineData(DeploymentStatus.AwaitingApplyAcks,"Awaiting apply acknowledgements")]
|
||||
[InlineData(DeploymentStatus.Sealed,"Sealed")]
|
||||
[InlineData(DeploymentStatus.PartiallyFailed,"Partially failed")]
|
||||
[InlineData(DeploymentStatus.TimedOut,"Timed out")]
|
||||
public void RealRecordedStatuses_RemainDistinct(DeploymentStatus status,string label)
|
||||
{
|
||||
var cut=Render<DeploymentFeedback>(p=>p.Add(x=>x.Status,status));
|
||||
cut.Find("[role=status]").TextContent.ShouldContain(label);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SealedWithReason_IsDegraded_AndFullReasonIsOutsideLiveAnnouncement()
|
||||
{
|
||||
var text="<script>ignored()</script>"+new string('x',2000);
|
||||
var cut=Render<DeploymentFeedback>(p=>p.Add(x=>x.Status,DeploymentStatus.Sealed).Add(x=>x.FailureReason,text));
|
||||
cut.Find("[role=status]").TextContent.ShouldContain("Sealed (degraded)");
|
||||
cut.Find("pre").TextContent.ShouldBe(text);
|
||||
cut.FindAll("script").ShouldBeEmpty();
|
||||
cut.FindAll("[role=status] pre").ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoChanges_IsInformational_AndKeepsPriorRecordedStatus()
|
||||
{
|
||||
var cut=Render<DeploymentFeedback>(p=>p.Add(x=>x.RequestOutcome,StartDeploymentOutcome.NoChanges).Add(x=>x.Status,DeploymentStatus.TimedOut));
|
||||
var text=cut.Find("[role=status]").TextContent;
|
||||
text.ShouldContain("No configuration changes");text.ShouldContain("Timed out");text.ShouldNotContain("rejected");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitialPending_IsNotEmptyHistory()
|
||||
{
|
||||
var cut=Render<DeploymentFeedback>(p=>p.Add(x=>x.InitialLoading,true));
|
||||
cut.Find("[role=status]").TextContent.ShouldContain("Loading deployment history");
|
||||
cut.Find("[role=status]").TextContent.ShouldNotContain("No deployment history");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FailedInitialRead_IsNotEmptyHistory()
|
||||
{
|
||||
var cut=Render<DeploymentFeedback>(p=>p.Add(x=>x.HistoryAvailable,false));
|
||||
cut.Find("[role=status]").TextContent.ShouldContain("history is unavailable");
|
||||
cut.Find("[role=status]").TextContent.ShouldNotContain("No deployment history");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfirmedEmptyRead_IsExplicitEmptyHistory()
|
||||
{
|
||||
var cut=Render<DeploymentFeedback>();
|
||||
cut.Find("[role=status]").TextContent.ShouldContain("No deployment history");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AcceptedButNotYetObserved_IsNotEmptyHistory()
|
||||
{
|
||||
var cut=Render<DeploymentFeedback>(p=>p.Add(x=>x.RequestOutcome,StartDeploymentOutcome.Accepted));
|
||||
var text=cut.Find("[role=status]").TextContent;text.ShouldContain("Request accepted");text.ShouldContain("not yet observed");text.ShouldNotContain("No deployment history");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransportFailure_DoesNotInventRejectionOrSuccess()
|
||||
{
|
||||
var cut=Render<DeploymentFeedback>(p=>p.Add(x=>x.RequestResultUnavailable,true));
|
||||
var text=cut.Find("[role=status]").TextContent;text.ShouldContain("could not be confirmed");text.ShouldNotContain("Request rejected");text.ShouldNotContain("Request accepted");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(StartDeploymentOutcome.Rejected,"Request rejected")]
|
||||
[InlineData(StartDeploymentOutcome.AnotherDeploymentInFlight,"This request was not started")]
|
||||
public void KnownUnacceptedRequest_IsExplicit(StartDeploymentOutcome outcome,string expected)
|
||||
{
|
||||
var cut=Render<DeploymentFeedback>(p=>p.Add(x=>x.RequestOutcome,outcome));
|
||||
cut.Find("[role=status]").TextContent.ShouldContain(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WaitingForActorReply_IsNotAcceptance()
|
||||
{
|
||||
var cut=Render<DeploymentFeedback>(p=>p.Add(x=>x.RequestPending,true));
|
||||
var text=cut.Find("[role=status]").TextContent;text.ShouldContain("Waiting for request acceptance");text.ShouldNotContain("Request accepted");
|
||||
}
|
||||
[Fact]
|
||||
public void RejectedWithoutReason_DoesNotPromiseAMissingDisclosure()
|
||||
{
|
||||
var cut=Render<DeploymentFeedback>(p=>p.Add(x=>x.RequestOutcome,StartDeploymentOutcome.Rejected));
|
||||
cut.Find("[role=status]").TextContent.ShouldContain("No reason was supplied");
|
||||
cut.FindAll("details").ShouldBeEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System.Data.Common;
|
||||
using System.Reflection;
|
||||
using Bunit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Deployments;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
||||
using DeploymentPage = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Deployments;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
||||
|
||||
/// <summary>Real-provider page reads stay bounded and exclude whole-fleet artifact payloads.</summary>
|
||||
[Collection(nameof(AdminUiSqlServerCollection))]
|
||||
public sealed class DeploymentPageSqlServerTests(AdminUiSqlServerFixture sql) : BunitContext
|
||||
{
|
||||
[SqlServerFact]
|
||||
public async Task HistoryRead_IsTranslatedBoundedAndDoesNotSelectArtifactBlobs()
|
||||
{
|
||||
var ids=Enumerable.Range(0,60).Select(_=>Guid.NewGuid()).ToArray();
|
||||
try
|
||||
{
|
||||
await using(var db=await sql.Factory.CreateDbContextAsync(Xunit.TestContext.Current.CancellationToken))
|
||||
{
|
||||
db.Deployments.AddRange(ids.Select((id,i)=>new Deployment {
|
||||
DeploymentId=id,RevisionHash=new string('a',64),CreatedBy="isolated-ui-fixture",
|
||||
Status=DeploymentStatus.Dispatching,CreatedAtUtc=new DateTime(4000,1,1,0,0,0,DateTimeKind.Utc).AddSeconds(i),
|
||||
ArtifactBlob=new byte[64*1024] }));
|
||||
await db.SaveChangesAsync(Xunit.TestContext.Current.CancellationToken);
|
||||
}
|
||||
var commands=new ReadCommands();
|
||||
var options=new DbContextOptionsBuilder<OtOpcUaConfigDbContext>().UseSqlServer(sql.ConnectionString).AddInterceptors(commands).Options;
|
||||
var factory=new SqlFactory(options);
|
||||
AddAuthorization().SetAuthorized("isolated-fixture");
|
||||
Services.AddSingleton<IDbContextFactory<OtOpcUaConfigDbContext>>(factory);
|
||||
Services.AddSingleton(new DeploymentDriftProbe(factory,_=>Task.FromResult(new string('a',64))));
|
||||
Services.AddSingleton(DispatchProxy.Create<IAdminOperationsClient, DeploymentRefreshTests.RequestProxy>());
|
||||
var cut=Render<DeploymentPage>();
|
||||
cut.WaitForAssertion(()=>cut.FindAll("tbody tr").Count.ShouldBe(50),TimeSpan.FromSeconds(10));
|
||||
commands.Text.ShouldNotBeEmpty();
|
||||
string.Join("\n",commands.Text).ShouldNotContain("ArtifactBlob");
|
||||
}
|
||||
finally
|
||||
{
|
||||
await using var cleanup=await sql.Factory.CreateDbContextAsync(Xunit.TestContext.Current.CancellationToken);
|
||||
await cleanup.Deployments.Where(d=>ids.Contains(d.DeploymentId)).ExecuteDeleteAsync(Xunit.TestContext.Current.CancellationToken);
|
||||
}
|
||||
}
|
||||
private sealed class SqlFactory(DbContextOptions<OtOpcUaConfigDbContext> options) : IDbContextFactory<OtOpcUaConfigDbContext>
|
||||
{
|
||||
public OtOpcUaConfigDbContext CreateDbContext()=>new(options);
|
||||
public Task<OtOpcUaConfigDbContext> CreateDbContextAsync(CancellationToken ct=default)=>Task.FromResult(CreateDbContext());
|
||||
}
|
||||
private sealed class ReadCommands : DbCommandInterceptor
|
||||
{
|
||||
public List<string> Text {get;}=[];
|
||||
public override ValueTask<InterceptionResult<DbDataReader>> ReaderExecutingAsync(DbCommand command,CommandEventData eventData,InterceptionResult<DbDataReader> result,CancellationToken cancellationToken=default)
|
||||
{Text.Add(command.CommandText);return ValueTask.FromResult(result);}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
using System.Reflection;
|
||||
using Bunit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Deployments;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
||||
using DeploymentPage = ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Deployments;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
||||
|
||||
/// <summary>Manual deployment status reads and request replies retain their independent meanings.</summary>
|
||||
[Trait("Category","Unit")]
|
||||
public sealed class DeploymentRefreshTests : BunitContext
|
||||
{
|
||||
private readonly string _database = "deployment-ui-"+Guid.NewGuid().ToString("N");
|
||||
private ControlledFactory Configure(bool seed=true)
|
||||
{
|
||||
AddAuthorization().SetAuthorized("fixture");
|
||||
if (seed)
|
||||
{
|
||||
using var db=RawTreeTestDb.CreateNamed(_database);
|
||||
db.Deployments.Add(new Deployment { DeploymentId=Guid.Parse("4ffec608-caa6-47f4-a9ca-71815c791648"), RevisionHash=new string('a',64), CreatedBy="fixture", Status=DeploymentStatus.AwaitingApplyAcks });
|
||||
db.SaveChanges();
|
||||
}
|
||||
var factory=new ControlledFactory(_database);
|
||||
Services.AddSingleton<IDbContextFactory<OtOpcUaConfigDbContext>>(factory);
|
||||
Services.AddSingleton(new DeploymentDriftProbe(factory,_=>Task.FromResult(new string('a',64))));
|
||||
Services.AddSingleton(DispatchProxy.Create<IAdminOperationsClient, RequestProxy>());
|
||||
return factory;
|
||||
}
|
||||
private RequestProxy Request => (RequestProxy)Services.GetRequiredService<IAdminOperationsClient>();
|
||||
|
||||
[Fact]
|
||||
public void ManualRefresh_ObservesLaterApplicationStatusWithoutReloadingPage()
|
||||
{
|
||||
Configure();var cut=Render<DeploymentPage>();
|
||||
using (var db=RawTreeTestDb.CreateNamed(_database)) { var row=db.Deployments.Single();row.Status=DeploymentStatus.Sealed;row.SealedAtUtc=DateTime.UtcNow;db.SaveChanges(); }
|
||||
cut.Find("[data-testid=deployment-refresh]").Click();
|
||||
cut.WaitForAssertion(()=>cut.Find("[role=status]").TextContent.ShouldContain("Sealed"));
|
||||
cut.Find("[data-testid=deployment-last-fetched]").TextContent.ShouldContain("UTC");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FailedInitialHistoryRead_DoesNotBecomeEmptyOrKillThePage()
|
||||
{
|
||||
var factory=Configure(false);factory.Read=_=>Task.FromException<OtOpcUaConfigDbContext>(new IOException("Synthetic read failure"));
|
||||
var cut=Render<DeploymentPage>();
|
||||
cut.WaitForAssertion(()=>cut.Find("[role=status]").TextContent.ShouldContain("history is unavailable"));
|
||||
cut.Find("[role=status]").TextContent.ShouldNotContain("No deployment history");
|
||||
factory.Read=null;cut.Find("[data-testid=deployment-refresh]").Click();
|
||||
cut.WaitForAssertion(()=>cut.Find("[role=status]").TextContent.ShouldContain("No deployment history"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AcceptedRequest_RemainsAcceptedWhenFollowingHistoryReadFails()
|
||||
{
|
||||
var factory=Configure();var cut=Render<DeploymentPage>();
|
||||
Request.Start=()=> { factory.Read=_=>Task.FromException<OtOpcUaConfigDbContext>(new IOException("Synthetic follow-up read failure"));return Task.FromResult(new StartDeploymentResult(StartDeploymentOutcome.Accepted,new(Guid.NewGuid()),new(new string('b',64)),null,new(Guid.NewGuid()))); };
|
||||
cut.Find("[data-testid=deployment-request]").Click();
|
||||
cut.WaitForAssertion(()=>cut.Find("[role=status]").TextContent.ShouldContain("Request accepted"));
|
||||
cut.Find("[role=status]").TextContent.ShouldContain("not yet observed");
|
||||
cut.Markup.ShouldNotContain("Deploy failed");cut.FindAll("tbody tr").Count.ShouldBe(1);cut.Markup.ShouldContain(new string('b',64));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PendingRefresh_BlocksQueuedRefreshAndRequestReentry()
|
||||
{
|
||||
var factory=Configure();var cut=Render<DeploymentPage>();
|
||||
var entered=new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var pending=new TaskCompletionSource<OtOpcUaConfigDbContext>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
factory.Read=_=>{entered.TrySetResult();return pending.Task;};
|
||||
var refreshing=cut.Find("[data-testid=deployment-refresh]").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await entered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
try
|
||||
{
|
||||
await cut.Find("[data-testid=deployment-refresh]").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await cut.Find("[data-testid=deployment-request]").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
factory.Attempts.ShouldBe(2);Request.Calls.ShouldBe(0);
|
||||
}
|
||||
finally {factory.Read=null;pending.TrySetResult(RawTreeTestDb.CreateNamed(_database));await refreshing;}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PendingRequest_BlocksQueuedRequestsAndStatusRefresh()
|
||||
{
|
||||
var factory=Configure();var cut=Render<DeploymentPage>();
|
||||
var entered=new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var pending=new TaskCompletionSource<StartDeploymentResult>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
Request.Start=()=>{entered.TrySetResult();return pending.Task;};
|
||||
var submitting=cut.Find("[data-testid=deployment-request]").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await entered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
try
|
||||
{
|
||||
await cut.Find("[data-testid=deployment-request]").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await cut.Find("[data-testid=deployment-refresh]").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
Request.Calls.ShouldBe(1);factory.Attempts.ShouldBe(1);
|
||||
}
|
||||
finally { pending.TrySetResult(new StartDeploymentResult(StartDeploymentOutcome.NoChanges,null,null,null,new(Guid.NewGuid())));await submitting; }
|
||||
cut.Find("[role=status]").TextContent.ShouldContain("No configuration changes");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MissingActorReply_IsUnconfirmedRatherThanRejected()
|
||||
{
|
||||
Configure();var cut=Render<DeploymentPage>();Request.Start=()=>Task.FromException<StartDeploymentResult>(new IOException("Synthetic unknown reply"));
|
||||
cut.Find("[data-testid=deployment-request]").Click();
|
||||
cut.WaitForAssertion(()=>cut.Find("[role=status]").TextContent.ShouldContain("could not be confirmed"));
|
||||
cut.Find("[role=status]").TextContent.ShouldNotContain("Request rejected");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DelayedInitialHistory_ComposesDriftOnceAfterRowsBecomeAvailable()
|
||||
{
|
||||
var factory=Configure();
|
||||
using (var db=RawTreeTestDb.CreateNamed(_database)) {db.Deployments.Single().Status=DeploymentStatus.Sealed;db.SaveChanges();}
|
||||
var pending=new TaskCompletionSource<OtOpcUaConfigDbContext>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
factory.Read=_=>pending.Task;
|
||||
var compositions=0;
|
||||
Services.AddSingleton(new DeploymentDriftProbe(factory,_=>{compositions++;return Task.FromResult(new string('a',64));}));
|
||||
var cut=Render<DeploymentPage>();
|
||||
cut.Find("[role=status]").TextContent.ShouldContain("Loading deployment history");
|
||||
compositions.ShouldBe(0);
|
||||
factory.Read=null;pending.SetResult(RawTreeTestDb.CreateNamed(_database));
|
||||
cut.WaitForAssertion(()=>cut.Find("[data-testid=drift-chip]").TextContent.ShouldBe("In sync"));
|
||||
compositions.ShouldBe(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FailedRefresh_PreservesLastSuccessfulRowsAndFetchedTime()
|
||||
{
|
||||
var factory=Configure();var cut=Render<DeploymentPage>();
|
||||
var fetched=cut.Find("[data-testid=deployment-last-fetched]").GetAttribute("datetime");
|
||||
factory.Read=_=>Task.FromException<OtOpcUaConfigDbContext>(new IOException("Synthetic stale read"));
|
||||
cut.Find("[data-testid=deployment-refresh]").Click();
|
||||
cut.WaitForAssertion(()=>cut.Find("[role=alert]").TextContent.ShouldContain("last successful reading"));
|
||||
cut.Find("[data-testid=deployment-last-fetched]").GetAttribute("datetime").ShouldBe(fetched);
|
||||
cut.FindAll("tbody tr").Count.ShouldBe(1);
|
||||
cut.Find("[role=status]").TextContent.ShouldContain("Awaiting apply acknowledgements");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Disposal_CancelsOnlyTheViewOwnedHistoryRead()
|
||||
{
|
||||
var factory=Configure(false);
|
||||
var canceled=new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var pending=new TaskCompletionSource<OtOpcUaConfigDbContext>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
factory.Read=async ct=>
|
||||
{
|
||||
try {return await pending.Task.WaitAsync(ct);}
|
||||
catch(OperationCanceledException) {canceled.TrySetResult();throw;}
|
||||
};
|
||||
var cut=Render<DeploymentPage>();
|
||||
cut.Find("[role=status]").TextContent.ShouldContain("Loading deployment history");
|
||||
await DisposeComponentsAsync();
|
||||
await canceled.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
Renderer.UnhandledException.IsCompletedSuccessfully.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Disposal_DoesNotCancelOrReplayAnAlreadyDispatchedRequest()
|
||||
{
|
||||
var factory=Configure();var cut=Render<DeploymentPage>();var client=Request;
|
||||
var entered=new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var pending=new TaskCompletionSource<StartDeploymentResult>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var completed=false;
|
||||
client.Start=async ()=>{entered.TrySetResult();var reply=await pending.Task;completed=true;return reply;};
|
||||
var submitting=cut.Find("[data-testid=deployment-request]").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await entered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
await DisposeComponentsAsync();
|
||||
pending.SetResult(new StartDeploymentResult(StartDeploymentOutcome.Accepted,new(Guid.NewGuid()),new(new string('b',64)),null,new(Guid.NewGuid())));
|
||||
await submitting;
|
||||
completed.ShouldBeTrue();client.Calls.ShouldBe(1);client.LastToken.CanBeCanceled.ShouldBeFalse();factory.Attempts.ShouldBe(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DisposalDuringUsernameRead_DoesNotDispatchANewRequest()
|
||||
{
|
||||
Configure();
|
||||
var state=new TaskCompletionSource<AuthenticationState>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
Services.AddSingleton<AuthenticationStateProvider>(new DeferredState(state.Task));
|
||||
var cut=Render<DeploymentPage>();var client=Request;
|
||||
var submitting=cut.Find("[data-testid=deployment-request]").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await DisposeComponentsAsync();
|
||||
state.SetResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity([new Claim(ClaimTypes.Name,"fixture")],"fixture"))));
|
||||
await submitting;client.Calls.ShouldBe(0);
|
||||
}
|
||||
|
||||
private sealed class DeferredState(Task<AuthenticationState> state) : AuthenticationStateProvider
|
||||
{public override Task<AuthenticationState> GetAuthenticationStateAsync()=>state;}
|
||||
|
||||
public sealed class ControlledFactory(string name) : IDbContextFactory<OtOpcUaConfigDbContext>
|
||||
{
|
||||
public int Attempts {get;private set;}
|
||||
public Func<CancellationToken,Task<OtOpcUaConfigDbContext>>? Read {get;set;}
|
||||
public OtOpcUaConfigDbContext CreateDbContext()=>RawTreeTestDb.CreateNamed(name);
|
||||
public Task<OtOpcUaConfigDbContext> CreateDbContextAsync(CancellationToken ct=default)
|
||||
{Attempts++;return Read?.Invoke(ct)??Task.FromResult(CreateDbContext());}
|
||||
}
|
||||
public class RequestProxy : DispatchProxy
|
||||
{
|
||||
public int Calls {get;private set;}
|
||||
public CancellationToken LastToken {get;private set;}
|
||||
public Func<Task<StartDeploymentResult>> Start {get;set;}=()=>Task.FromException<StartDeploymentResult>(new NotSupportedException("Synthetic operation not configured"));
|
||||
protected override object? Invoke(MethodInfo? method,object?[]? args)
|
||||
{
|
||||
if(method?.Name!=nameof(IAdminOperationsClient.StartDeploymentAsync))throw new NotSupportedException("Synthetic fixture rejects other operations");
|
||||
Calls++;LastToken=(CancellationToken)args![1]!;return Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user