fix(scripting): give scripted-alarm predicates the configured run budget, not 250 ms (lmxopcua#779)
DriverHostActor built ScriptedAlarmEngine without a scriptTimeout, so every
production alarm predicate fell back to TimedScriptEvaluator.DefaultTimeout
(250 ms) while virtual tags and Calculation tags ran on 2 s. History shows no
decision behind it: 250 ms is the generic Phase-7 A.4 default, the VT
evaluator moved to 2 s in F8b (219d10a2) and the alarm engine was simply never
given a value.
- New node-wide Scripting:RunTimeout (default 2 s, clamped to (0, 60 s],
non-positive -> default, each clamp a startup Warning) on ScriptingOptions.
- The VT evaluator and the alarm engine default to it; DriverHostActor now
builds the engine through CreateScriptedAlarmEngine, which passes it
explicitly. Calculation keeps its per-driver runTimeoutMs.
- Docs: ScriptEditor (config table), ScriptedAlarms, VirtualTags.
Tests: ScriptedAlarmEngineBudgetTests (a 600 ms predicate now completes and
activates; default and configured budgets), ScriptedAlarmEngineBudgetWiringTests
(the host-built engine), ScriptingOptionsBindingTests (bind + clamps). The
engine and wiring tests fail with the old 250 ms default restored.
Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
+19
-1
@@ -24,6 +24,7 @@ public sealed class ScriptingOptionsBindingTests
|
||||
["Scripting:MaxAllocBytesPerRun"] = "8388608",
|
||||
["Scripting:QuarantineAfterConsecutiveTimeouts"] = "7",
|
||||
["Scripting:StuckOrphanQuarantineFactor"] = "4.5",
|
||||
["Scripting:RunTimeout"] = "00:00:05",
|
||||
// Sibling keys owned by the script-log pipeline must not disturb the bind.
|
||||
["Scripting:LogFilePath"] = "logs/x-.log",
|
||||
["Scripting:LogTopicMinLevel"] = "Warning",
|
||||
@@ -33,6 +34,7 @@ public sealed class ScriptingOptionsBindingTests
|
||||
bound.MaxAllocBytesPerRun.ShouldBe(8L * 1024 * 1024);
|
||||
bound.QuarantineAfterConsecutiveTimeouts.ShouldBe(7);
|
||||
bound.StuckOrphanQuarantineFactor.ShouldBe(4.5);
|
||||
bound.RunTimeout.ShouldBe(TimeSpan.FromSeconds(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -43,12 +45,27 @@ public sealed class ScriptingOptionsBindingTests
|
||||
["Scripting:StuckOrphanQuarantineFactor"] = "1e300",
|
||||
["Scripting:MaxAllocBytesPerRun"] = "1024",
|
||||
["Scripting:QuarantineAfterConsecutiveTimeouts"] = "0",
|
||||
["Scripting:RunTimeout"] = "00:10:00",
|
||||
}), out var adjustments);
|
||||
|
||||
bound.StuckOrphanQuarantineFactor.ShouldBe(ScriptingOptions.MaxStuckOrphanQuarantineFactor);
|
||||
bound.MaxAllocBytesPerRun.ShouldBe(ScriptingOptions.MinMaxAllocBytesPerRun);
|
||||
bound.QuarantineAfterConsecutiveTimeouts.ShouldBe(1);
|
||||
adjustments.Count.ShouldBe(3);
|
||||
bound.RunTimeout.ShouldBe(ScriptingOptions.MaxRunTimeout);
|
||||
adjustments.Count.ShouldBe(4);
|
||||
}
|
||||
|
||||
/// <summary>lmxopcua#779: a non-positive budget is not "no timeout"; it falls back to the default.</summary>
|
||||
[Theory]
|
||||
[InlineData("00:00:00")]
|
||||
[InlineData("-00:00:01")]
|
||||
public void A_non_positive_RunTimeout_becomes_the_default_and_is_reported(string value)
|
||||
{
|
||||
var bound = ScriptingOptionsBinding.Bind(Config(new() { ["Scripting:RunTimeout"] = value }), out var adjustments);
|
||||
|
||||
bound.RunTimeout.ShouldBe(ScriptingOptions.DefaultRunTimeout);
|
||||
adjustments.Count.ShouldBe(1);
|
||||
adjustments[0].ShouldContain("RunTimeout");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -60,5 +77,6 @@ public sealed class ScriptingOptionsBindingTests
|
||||
bound.MaxAllocBytesPerRun.ShouldBe(ScriptingOptions.DefaultMaxAllocBytesPerRun);
|
||||
bound.QuarantineAfterConsecutiveTimeouts.ShouldBe(ScriptingOptions.DefaultQuarantineAfterConsecutiveTimeouts);
|
||||
bound.StuckOrphanQuarantineFactor.ShouldBe(ScriptingOptions.DefaultStuckOrphanQuarantineFactor);
|
||||
bound.RunTimeout.ShouldBe(TimeSpan.FromSeconds(2));
|
||||
}
|
||||
}
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using Serilog;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.ScriptedAlarms;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Scripting;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.Drivers;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.ScriptedAlarms;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.ScriptedAlarms;
|
||||
|
||||
/// <summary>
|
||||
/// lmxopcua#779 — the engine the driver host builds for its scripted-alarm host runs predicates on the node's
|
||||
/// <c>Scripting:RunTimeout</c>, not on the 250 ms Phase-7 default it used to fall back to.
|
||||
/// </summary>
|
||||
public sealed class ScriptedAlarmEngineBudgetWiringTests
|
||||
{
|
||||
private static readonly ILogger Logger = new LoggerConfiguration().CreateLogger();
|
||||
|
||||
[Fact]
|
||||
public void The_host_built_engine_uses_the_configured_RunTimeout()
|
||||
{
|
||||
using var engine = DriverHostActor.CreateScriptedAlarmEngine(
|
||||
new DependencyMuxTagUpstreamSource(), new InMemoryAlarmStateStore(), Logger,
|
||||
new ScriptingOptions { RunTimeout = TimeSpan.FromSeconds(5) });
|
||||
|
||||
engine.ScriptTimeout.ShouldBe(TimeSpan.FromSeconds(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void With_no_Scripting_options_the_host_built_engine_gets_the_2s_default_not_250ms()
|
||||
{
|
||||
using var engine = DriverHostActor.CreateScriptedAlarmEngine(
|
||||
new DependencyMuxTagUpstreamSource(), new InMemoryAlarmStateStore(), Logger, scripting: null);
|
||||
|
||||
engine.ScriptTimeout.ShouldBe(TimeSpan.FromSeconds(2));
|
||||
engine.ScriptTimeout.ShouldNotBe(TimedScriptEvaluator<AlarmPredicateContext, bool>.DefaultTimeout);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user