Merge branch 'worktree-agent-aaec6546913f0beae' into arch-review-remediation
This commit is contained in:
@@ -7,6 +7,7 @@ using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Notifications;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
@@ -933,6 +934,71 @@ public class SiteRepositoryTests : IDisposable
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new SiteRepository(null!));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A data connection's protocol and primary/backup configuration are flattening
|
||||
/// inputs — <c>FlatteningService</c> packages them into the flattened config's
|
||||
/// <c>Connections</c> map and <c>RevisionHashService</c> folds them into the
|
||||
/// revision hash. Without a watermark bump on save, the process-wide
|
||||
/// <c>StaleInstanceProbe</c> memo and the flatten-session caches keep serving the
|
||||
/// pre-edit hash, so an instance whose deployed config genuinely drifted reads as
|
||||
/// up to date. (The bump is unattributed — a connection has no owning template —
|
||||
/// so both the global and structure counters must move.)
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task SaveChanges_DataConnectionEdit_BumpsWatermark()
|
||||
{
|
||||
var watermark = new TemplateGraphWatermark();
|
||||
var repository = new SiteRepository(_context, watermark);
|
||||
|
||||
var site = new Site("Site1", "S-001");
|
||||
await repository.AddSiteAsync(site);
|
||||
await repository.SaveChangesAsync();
|
||||
|
||||
var afterSiteOnly = (watermark.Global, watermark.StructureVersion);
|
||||
|
||||
var conn = new DataConnection("Conn1", "OpcUa", site.Id);
|
||||
await repository.AddDataConnectionAsync(conn);
|
||||
await repository.SaveChangesAsync();
|
||||
|
||||
Assert.True(watermark.Global > afterSiteOnly.Global, "adding a data connection did not bump the global watermark");
|
||||
Assert.True(watermark.StructureVersion > afterSiteOnly.StructureVersion,
|
||||
"adding a data connection did not bump the structure watermark");
|
||||
|
||||
var afterAdd = (watermark.Global, watermark.StructureVersion);
|
||||
|
||||
conn.Protocol = "MxGateway";
|
||||
await repository.UpdateDataConnectionAsync(conn);
|
||||
await repository.SaveChangesAsync();
|
||||
|
||||
Assert.True(watermark.Global > afterAdd.Global, "editing a data connection did not bump the watermark");
|
||||
|
||||
var afterUpdate = watermark.Global;
|
||||
|
||||
await repository.DeleteDataConnectionAsync(conn.Id);
|
||||
await repository.SaveChangesAsync();
|
||||
|
||||
Assert.True(watermark.Global > afterUpdate, "deleting a data connection did not bump the watermark");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The bump is scoped to the entity that actually feeds the flattener: a save
|
||||
/// that touches no data connection must leave the watermark alone, or every
|
||||
/// site/area edit would needlessly invalidate the whole flatten cache.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task SaveChanges_WithoutDataConnectionChange_DoesNotBumpWatermark()
|
||||
{
|
||||
var watermark = new TemplateGraphWatermark();
|
||||
var repository = new SiteRepository(_context, watermark);
|
||||
|
||||
var site = new Site("Site1", "S-001");
|
||||
await repository.AddSiteAsync(site);
|
||||
await repository.SaveChangesAsync();
|
||||
|
||||
Assert.Equal(0, watermark.Global);
|
||||
Assert.Equal(0, watermark.StructureVersion);
|
||||
}
|
||||
}
|
||||
|
||||
public class DeploymentManagerRepositoryTests : IDisposable
|
||||
|
||||
Reference in New Issue
Block a user