Files
lmxopcua/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DeploymentQueriesTests.cs
T
Joseph Doherty ea976ffa81 fix(perf): #996 Wave 4 — blob-free health probes, narrow data-connections load, off-thread coordinator acks + AdminOps audit, events page cap, capped reservations page
C-6: DeploymentQueries projects Deployment without ArtifactBlob (DbHealthProbe, readiness, ClusterOverview, DriverHost boot).
C-11/A-5: DraftSnapshotFactory.FromConfigDbForDataConnectionsAsync + one-parse-per-artifact LoadAppliedAsync + capped pickers.
H-6: ConfigPublishCoordinator persists acks off the actor thread (AckPersisted); deadline backlog kicked in parallel.
H-3: Restart/Reconnect reply = dispatch; ConfigEdit audit written off-mailbox, failure logged not surfaced.
U-6: ServerHistorian:MaxEventsPerRead (default 10000) pages HistoryReadEvents; advertised as MaxReturnEventValues.
A-8: /reservations active-only by default, projected, capped at 200.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-12-03 10:58:50 -05:00

69 lines
3.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
using ZB.MOM.WW.OtOpcUa.Configuration.Queries;
namespace ZB.MOM.WW.OtOpcUa.Configuration.Tests;
/// <summary>
/// lmxopcua#996 / review C-6: the blob-free <c>Deployment</c> queries must never put <c>ArtifactBlob</c> in the SQL
/// SELECT list. The query shape is asserted against the SQL Server provider's generated text
/// (<c>ToQueryString</c> — no connection is opened), with a positive control proving the assertion can fail.
/// </summary>
[Trait("Category", "Unit")]
public sealed class DeploymentQueriesTests
{
private static OtOpcUaConfigDbContext SqlServerContext() =>
new(new DbContextOptionsBuilder<OtOpcUaConfigDbContext>()
.UseSqlServer("Server=127.0.0.1,1;Database=never;Connect Timeout=1")
.Options);
/// <summary>Positive control: the naive whole-entity read DOES select the blob.</summary>
[Fact]
public void WholeEntityQuery_SelectsArtifactBlob()
{
using var db = SqlServerContext();
db.Deployments.AsNoTracking().Take(1).ToQueryString().ShouldContain("ArtifactBlob");
}
/// <summary>The health-probe / readiness query selects only the id.</summary>
[Fact]
public void ProbeQuery_DoesNotSelectArtifactBlob()
{
using var db = SqlServerContext();
var sql = DeploymentQueries.ProbeQuery(db).ToQueryString();
sql.ShouldNotContain("ArtifactBlob");
sql.ShouldContain("DeploymentId");
}
/// <summary>The cluster-overview latest-deployment query carries the metadata but not the blob.</summary>
[Fact]
public void LatestSummary_DoesNotSelectArtifactBlob()
{
using var db = SqlServerContext();
var sql = DeploymentQueries.LatestSummary(db).ToQueryString();
sql.ShouldNotContain("ArtifactBlob");
sql.ShouldContain("RevisionHash");
sql.ShouldContain("SealedAtUtc");
}
/// <summary>The summary projection returns the right newest row.</summary>
[Fact]
public async Task LatestSummary_ReturnsNewestRow()
{
var options = new DbContextOptionsBuilder<OtOpcUaConfigDbContext>()
.UseInMemoryDatabase($"dep-q-{Guid.NewGuid():N}").Options;
await using var db = new OtOpcUaConfigDbContext(options);
db.Deployments.Add(new Deployment { RevisionHash = "old", CreatedBy = "t", CreatedAtUtc = DateTime.UtcNow.AddHours(-1), ArtifactBlob = new byte[8] });
db.Deployments.Add(new Deployment { RevisionHash = "new", CreatedBy = "t", Status = DeploymentStatus.Sealed, ArtifactBlob = new byte[8] });
await db.SaveChangesAsync(TestContext.Current.CancellationToken);
var latest = await DeploymentQueries.LatestSummary(db).SingleAsync(TestContext.Current.CancellationToken);
latest.RevisionHash.ShouldBe("new");
latest.Status.ShouldBe(DeploymentStatus.Sealed);
(await DeploymentQueries.ProbeQuery(db).ToListAsync(TestContext.Current.CancellationToken)).Count.ShouldBe(1);
}
}