Files
T
Joseph Doherty 11a5c1d4e2
v2-ci / unit-tests (push) Has been cancelled
test: deflake load-sensitive tests (lmxopcua#769)
- NodeManagerLockTimeBenchmark: wall-clock budget enforced only with OTOPCUA_BENCH=1; default run keeps the state-correctness asserts and logs timings.
- OpcUaClientDriverWire host-status: signal (semaphore) wait that only accepts a non-Running state observed after the server is disposed.
- AbCip PollLatencyComparison: retry once on a fixture connection reset; p95 criterion enforced only with AB_LAT_ENFORCE=1.
- ScriptRunGuardTests: orphan scripts held by a ctx.Released signal instead of a 250 ms wall-clock spin that could finish inside the 60 ms budget under load; stuck-orphan wall-clock rule disabled in the tests that pin the strike counting.
- DependencyMuxReplayTests: split the inside-grace positive control (1 h grace) from the release test (control asserted before unregister), removing the 200 ms grace race.

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
2026-11-10 05:39:22 -05:00

61 lines
2.4 KiB
C#

using Serilog;
using Serilog.Core;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Core.Scripting;
namespace ZB.MOM.WW.OtOpcUa.Core.Scripting.Tests;
/// <summary>
/// In-memory <see cref="ScriptContext"/> for tests. Holds a tag dictionary + a write
/// log + a deterministic clock. Concrete subclasses in production will wire
/// GetTag/SetVirtualTag through the virtual-tag engine + driver dispatch; here they
/// hit a plain dictionary.
/// </summary>
public sealed class FakeScriptContext : ScriptContext
{
/// <summary>Gets the dictionary of tags available in this context.</summary>
public Dictionary<string, DataValueSnapshot> Tags { get; } = new(StringComparer.Ordinal);
/// <summary>Gets the log of virtual tag write operations.</summary>
public List<(string Path, object? Value)> Writes { get; } = [];
/// <summary>
/// Test gate: a "held" script spins on <c>while (!ctx.Released) { }</c> until the test releases it, so a
/// timeout/orphan scenario depends on a signal rather than a wall-clock spin racing the budget under load.
/// </summary>
public volatile bool Released;
/// <inheritdoc />
public override DateTime Now { get; } = new DateTime(2026, 1, 1, 12, 0, 0, DateTimeKind.Utc);
/// <inheritdoc />
public override ILogger Logger { get; } = new LoggerConfiguration().CreateLogger();
/// <inheritdoc />
public override DataValueSnapshot GetTag(string path)
{
return Tags.TryGetValue(path, out var v)
? v
: new DataValueSnapshot(null, 0x80340000u, null, Now); // BadNodeIdUnknown
}
/// <inheritdoc />
public override void SetVirtualTag(string path, object? value)
{
Writes.Add((path, value));
}
/// <summary>Seeds the context with a tag value for testing.</summary>
/// <param name="path">The tag path.</param>
/// <param name="value">The tag value.</param>
/// <param name="statusCode">The OPC UA status code (default: 0).</param>
/// <param name="sourceTs">The source timestamp (default: <see cref="Now"/>).</param>
/// <returns>This instance for method chaining.</returns>
public FakeScriptContext Seed(string path, object? value,
uint statusCode = 0u, DateTime? sourceTs = null)
{
Tags[path] = new DataValueSnapshot(value, statusCode, sourceTs ?? Now, Now);
return this;
}
}