fix(site-runtime): retry the startup deployed-config load on SQLite failure (S5) — no more silent zero-instance node

This commit is contained in:
Joseph Doherty
2026-07-09 00:17:36 -04:00
parent b126fda22e
commit 2dabbbdde0
2 changed files with 107 additions and 4 deletions
@@ -15,6 +15,7 @@ using ZB.MOM.WW.ScadaBridge.SiteRuntime.Persistence;
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts;
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.TestSupport;
using System.Text.Json;
using System.Threading;
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Actors;
@@ -266,6 +267,46 @@ public class DeploymentManagerActorTests : TestKit, IDisposable
Assert.DoesNotContain(configs, c => c.InstanceUniqueName == "bad-instance");
}
// ── S5: startup deployed-config load is retried on transient failure ──
[Fact]
public void StartupLoadFailure_IsRetried_UntilSuccess()
{
// The first startup load throws (transient SQLite failure); the second
// succeeds and returns one enabled config. The DM must retry rather than
// stall as a silent zero-instance node — so the Instance Actor eventually
// exists.
var calls = 0;
Func<Task<List<DeployedInstance>>> loader = () =>
Interlocked.Increment(ref calls) == 1
? Task.FromException<List<DeployedInstance>>(new IOException("db locked"))
: Task.FromResult(new List<DeployedInstance>
{
new()
{
InstanceUniqueName = "inst-1",
ConfigJson = MakeConfigJson("inst-1"),
DeploymentId = "d1",
RevisionHash = "h1",
IsEnabled = true
}
});
var dm = ActorOf(Props.Create(() => new DeploymentManagerActor(
_storage, _compilationService, _sharedScriptLibrary, null,
new SiteRuntimeOptions(), NullLogger<DeploymentManagerActor>.Instance,
null, null, null, null, null, null,
TimeSpan.FromMilliseconds(200), loader)));
AwaitAssert(() =>
{
Assert.True(Volatile.Read(ref calls) >= 2,
$"expected the load to be retried; calls={Volatile.Read(ref calls)}");
Sys.ActorSelection(dm.Path / "inst-1").Tell(new Identify(1));
Assert.NotNull(ExpectMsg<ActorIdentity>(TimeSpan.FromSeconds(1)).Subject);
}, TimeSpan.FromSeconds(10));
}
// ── M1.6: site event log `deployment` category ─────────────────────────
[Fact]