fix(deploymentmanager): bulk deploy skips Disabled + reconcile circuit-breaker + probe captures pre-flatten versions (arch-review 2026-08-19 P7-2 + P7-3 + P7-4)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using NSubstitute;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
@@ -96,4 +97,72 @@ public class StaleInstanceProbeTests
|
||||
|
||||
Assert.Equal("sha256:second", await probe.GetCurrentRevisionHashAsync(InstanceId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// P7-4: a non-structural template edit landing DURING the flatten must not be
|
||||
/// captured as if it were already included.
|
||||
///
|
||||
/// <para>
|
||||
/// The memo pairs a revision hash with the watermark readings that produced it.
|
||||
/// Reading the per-template versions AFTER the flatten pairs the PRE-edit hash
|
||||
/// with the POST-edit version, and every later probe then finds the watermark
|
||||
/// unchanged and answers "not stale" forever — until an unrelated edit, a
|
||||
/// restart, or the 4096-entry overflow clears it. The staleness sweep and
|
||||
/// <c>ImportResult.StaleInstanceIds</c> both read through this memo.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// The fix is that the versions come from the session, which records each
|
||||
/// template's version at the instant it READ that template — before the edit —
|
||||
/// so the mismatch on the next probe invalidates the memo. Only the recording is
|
||||
/// changed: the mid-flatten edit still produces the pre-edit hash on this pass,
|
||||
/// which is correct, since that is the graph the flatten actually saw.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TemplateEditedDuringFlatten_InvalidatesTheMemo_RatherThanPinningTheStaleHash()
|
||||
{
|
||||
const int TemplateId = 42;
|
||||
|
||||
// The flatten reads the template through the session (recording the version
|
||||
// it read it at), and the edit lands before the flatten returns.
|
||||
_pipeline
|
||||
.FlattenAndValidateAsync(InstanceId, Arg.Any<CancellationToken>(), Arg.Any<bool>(), Arg.Any<FlattenSession?>())
|
||||
.Returns(async call =>
|
||||
{
|
||||
_flattenCount++;
|
||||
var session = call.ArgAt<FlattenSession?>(3)!;
|
||||
await session.GetTemplateAsync(TemplateId, _ => Task.FromResult<Template?>(new Template($"T{TemplateId}")));
|
||||
|
||||
// A non-structural template edit commits while the flatten is in flight.
|
||||
_watermark.BumpTemplate(TemplateId);
|
||||
_currentHash = "sha256:after-edit";
|
||||
|
||||
var config = new FlattenedConfiguration { InstanceUniqueName = "Inst-01" };
|
||||
return Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(config, "sha256:before-edit", ValidationResult.Success()));
|
||||
});
|
||||
|
||||
var probe = CreateProbe();
|
||||
|
||||
// Pass 1 legitimately returns the hash of the graph the flatten walked.
|
||||
Assert.Equal("sha256:before-edit", await probe.GetCurrentRevisionHashAsync(InstanceId));
|
||||
Assert.Equal(1, _flattenCount);
|
||||
|
||||
// Pass 2 must see the edit. Re-recording the versions after the flatten
|
||||
// would have memoised the post-edit version against the pre-edit hash, and
|
||||
// this call would still answer "sha256:before-edit" without re-flattening.
|
||||
_pipeline
|
||||
.FlattenAndValidateAsync(InstanceId, Arg.Any<CancellationToken>(), Arg.Any<bool>(), Arg.Any<FlattenSession?>())
|
||||
.Returns(_ =>
|
||||
{
|
||||
_flattenCount++;
|
||||
var config = new FlattenedConfiguration { InstanceUniqueName = "Inst-01" };
|
||||
return Result<FlatteningPipelineResult>.Success(
|
||||
new FlatteningPipelineResult(config, _currentHash, ValidationResult.Success()));
|
||||
});
|
||||
|
||||
Assert.Equal("sha256:after-edit", await probe.GetCurrentRevisionHashAsync(InstanceId));
|
||||
Assert.Equal(2, _flattenCount);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user