Phase 3B: Site I/O & Observability — Communication, DCL, Script/Alarm actors, Health, Event Logging
Communication Layer (WP-1–5): - 8 message patterns with correlation IDs, per-pattern timeouts - Central/Site communication actors, transport heartbeat config - Connection failure handling (no central buffering, debug streams killed) Data Connection Layer (WP-6–14, WP-34): - Connection actor with Become/Stash lifecycle (Connecting/Connected/Reconnecting) - OPC UA + LmxProxy adapters behind IDataConnection - Auto-reconnect, bad quality propagation, transparent re-subscribe - Write-back, tag path resolution with retry, health reporting - Protocol extensibility via DataConnectionFactory Site Runtime (WP-15–25, WP-32–33): - ScriptActor/ScriptExecutionActor (triggers, concurrent execution, blocking I/O dispatcher) - AlarmActor/AlarmExecutionActor (ValueMatch/RangeViolation/RateOfChange, in-memory state) - SharedScriptLibrary (inline execution), ScriptRuntimeContext (API) - ScriptCompilationService (Roslyn, forbidden API enforcement, execution timeout) - Recursion limit (default 10), call direction enforcement - SiteStreamManager (per-subscriber bounded buffers, fire-and-forget) - Debug view backend (snapshot + stream), concurrency serialization - Local artifact storage (4 SQLite tables) Health Monitoring (WP-26–28): - SiteHealthCollector (thread-safe counters, connection state) - HealthReportSender (30s interval, monotonic sequence numbers) - CentralHealthAggregator (offline detection 60s, online recovery) Site Event Logging (WP-29–31): - SiteEventLogger (SQLite, 6 event categories, ISO 8601 UTC) - EventLogPurgeService (30-day retention, 1GB cap) - EventLogQueryService (filters, keyword search, keyset pagination) 541 tests pass, zero warnings.
This commit is contained in:
@@ -6,6 +6,7 @@ using ScadaLink.Commons.Messages.Instance;
|
||||
using ScadaLink.Commons.Types.Flattening;
|
||||
using ScadaLink.SiteRuntime.Actors;
|
||||
using ScadaLink.SiteRuntime.Persistence;
|
||||
using ScadaLink.SiteRuntime.Scripts;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ScadaLink.SiteRuntime.Tests.Actors;
|
||||
@@ -16,6 +17,9 @@ namespace ScadaLink.SiteRuntime.Tests.Actors;
|
||||
public class InstanceActorTests : TestKit, IDisposable
|
||||
{
|
||||
private readonly SiteStorageService _storage;
|
||||
private readonly ScriptCompilationService _compilationService;
|
||||
private readonly SharedScriptLibrary _sharedScriptLibrary;
|
||||
private readonly SiteRuntimeOptions _options;
|
||||
private readonly string _dbFile;
|
||||
|
||||
public InstanceActorTests()
|
||||
@@ -25,6 +29,24 @@ public class InstanceActorTests : TestKit, IDisposable
|
||||
$"Data Source={_dbFile}",
|
||||
NullLogger<SiteStorageService>.Instance);
|
||||
_storage.InitializeAsync().GetAwaiter().GetResult();
|
||||
_compilationService = new ScriptCompilationService(
|
||||
NullLogger<ScriptCompilationService>.Instance);
|
||||
_sharedScriptLibrary = new SharedScriptLibrary(
|
||||
_compilationService, NullLogger<SharedScriptLibrary>.Instance);
|
||||
_options = new SiteRuntimeOptions();
|
||||
}
|
||||
|
||||
private IActorRef CreateInstanceActor(string instanceName, FlattenedConfiguration config)
|
||||
{
|
||||
return ActorOf(Props.Create(() => new InstanceActor(
|
||||
instanceName,
|
||||
JsonSerializer.Serialize(config),
|
||||
_storage,
|
||||
_compilationService,
|
||||
_sharedScriptLibrary,
|
||||
null, // no stream manager in tests
|
||||
_options,
|
||||
NullLogger<InstanceActor>.Instance)));
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
@@ -46,11 +68,7 @@ public class InstanceActorTests : TestKit, IDisposable
|
||||
]
|
||||
};
|
||||
|
||||
var actor = ActorOf(Props.Create(() => new InstanceActor(
|
||||
"Pump1",
|
||||
JsonSerializer.Serialize(config),
|
||||
_storage,
|
||||
NullLogger<InstanceActor>.Instance)));
|
||||
var actor = CreateInstanceActor("Pump1", config);
|
||||
|
||||
// Query for an attribute that exists
|
||||
actor.Tell(new GetAttributeRequest(
|
||||
@@ -71,11 +89,7 @@ public class InstanceActorTests : TestKit, IDisposable
|
||||
Attributes = []
|
||||
};
|
||||
|
||||
var actor = ActorOf(Props.Create(() => new InstanceActor(
|
||||
"Pump1",
|
||||
JsonSerializer.Serialize(config),
|
||||
_storage,
|
||||
NullLogger<InstanceActor>.Instance)));
|
||||
var actor = CreateInstanceActor("Pump1", config);
|
||||
|
||||
actor.Tell(new GetAttributeRequest(
|
||||
"corr-2", "Pump1", "NonExistent", DateTimeOffset.UtcNow));
|
||||
@@ -97,13 +111,9 @@ public class InstanceActorTests : TestKit, IDisposable
|
||||
]
|
||||
};
|
||||
|
||||
var actor = ActorOf(Props.Create(() => new InstanceActor(
|
||||
"Pump1",
|
||||
JsonSerializer.Serialize(config),
|
||||
_storage,
|
||||
NullLogger<InstanceActor>.Instance)));
|
||||
var actor = CreateInstanceActor("Pump1", config);
|
||||
|
||||
// Set a static attribute — response comes async via PipeTo
|
||||
// Set a static attribute -- response comes async via PipeTo
|
||||
actor.Tell(new SetStaticAttributeCommand(
|
||||
"corr-3", "Pump1", "Temperature", "100.0", DateTimeOffset.UtcNow));
|
||||
|
||||
@@ -131,11 +141,7 @@ public class InstanceActorTests : TestKit, IDisposable
|
||||
]
|
||||
};
|
||||
|
||||
var actor = ActorOf(Props.Create(() => new InstanceActor(
|
||||
"PumpPersist1",
|
||||
JsonSerializer.Serialize(config),
|
||||
_storage,
|
||||
NullLogger<InstanceActor>.Instance)));
|
||||
var actor = CreateInstanceActor("PumpPersist1", config);
|
||||
|
||||
actor.Tell(new SetStaticAttributeCommand(
|
||||
"corr-persist", "PumpPersist1", "Temperature", "100.0", DateTimeOffset.UtcNow));
|
||||
@@ -166,11 +172,7 @@ public class InstanceActorTests : TestKit, IDisposable
|
||||
]
|
||||
};
|
||||
|
||||
var actor = ActorOf(Props.Create(() => new InstanceActor(
|
||||
"PumpOverride1",
|
||||
JsonSerializer.Serialize(config),
|
||||
_storage,
|
||||
NullLogger<InstanceActor>.Instance)));
|
||||
var actor = CreateInstanceActor("PumpOverride1", config);
|
||||
|
||||
// Wait for the async override loading to complete (PipeTo)
|
||||
await Task.Delay(1000);
|
||||
@@ -200,7 +202,7 @@ public class InstanceActorTests : TestKit, IDisposable
|
||||
overrides = await _storage.GetStaticOverridesAsync("PumpRedeploy");
|
||||
Assert.Empty(overrides);
|
||||
|
||||
// Create actor with fresh config — should NOT have the override
|
||||
// Create actor with fresh config -- should NOT have the override
|
||||
var config = new FlattenedConfiguration
|
||||
{
|
||||
InstanceUniqueName = "PumpRedeploy",
|
||||
@@ -210,11 +212,7 @@ public class InstanceActorTests : TestKit, IDisposable
|
||||
]
|
||||
};
|
||||
|
||||
var actor = ActorOf(Props.Create(() => new InstanceActor(
|
||||
"PumpRedeploy",
|
||||
JsonSerializer.Serialize(config),
|
||||
_storage,
|
||||
NullLogger<InstanceActor>.Instance)));
|
||||
var actor = CreateInstanceActor("PumpRedeploy", config);
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user