AvevaPrerequisites.CheckAllAsync walks eight probe categories producing PrerequisiteCheck rows each with Name (e.g. 'service:aaBootstrap', 'sql:ZB', 'com:LMXProxy', 'registry:ArchestrA.Framework'), Category (AvevaCoreService / AvevaSoftService / AvevaInstall / MxAccessCom / GalaxyRepository / AvevaHistorian / OtOpcUaService / Environment), Status (Pass / Warn / Fail / Skip), and operator-facing Detail message. Report aggregates them: IsLivetestReady (no Fails anywhere) and IsAvevaSideReady (AVEVA-side categories pass, our v2 services can be absent while still considering the environment AVEVA-ready) so different test tiers can use the right threshold.
Individual probes: ServiceProbe.Check queries the Windows Service Control Manager via System.ServiceProcess.ServiceController — treats DemandStart+Stopped as Warn (NmxSvc is DemandStart by design; master pulls it up) but AutoStart+Stopped as Fail; not-installed is Fail for hard-required services, Warn for soft ones; non-Windows hosts get Skip; transitional states like StartPending get Warn with a 'try again' hint. RegistryProbe reads HKLM\SOFTWARE\WOW6432Node\ArchestrA\{Framework,Framework\Platform,MSIInstall} — Framework key presence + populated InstallPath/RootPath values mean System Platform installed; PfeConfigOptions in the Platform subkey (format 'PlatformId=N,EngineId=N,...') indicates a Platform has been deployed from the IDE (PlatformId=0 means never deployed — MXAccess will connect but every subscription will be Bad quality); RebootRequired='True' under MSIInstall surfaces as a loud warn since post-patch behavior is undefined. MxAccessComProbe resolves the LMXProxy.LMXProxyServer ProgID → CLSID → HKLM\SOFTWARE\Classes\WOW6432Node\CLSID\{guid}\InprocServer32, verifying the registered file exists on disk (catches the orphan-registry case where a previous uninstall left the ProgID registered but the DLL is gone — distinguishes it from the 'totally not installed' case by message); also emits a Warn when the test process is 64-bit (MXAccess COM activation fails with REGDB_E_CLASSNOTREG 0x80040154 regardless of registration, so seeing this warning tells operators why the activation would fail even on a fully-installed machine). SqlProbe tests Galaxy Repository via Microsoft.Data.SqlClient using the Windows-auth localhost connection string the repo code defaults to — distinguishes 'SQL Server unreachable' (connection fails) from 'ZB database does not exist' (SELECT DB_ID('ZB') returns null) because they have different remediation paths (sc.exe start MSSQLSERVER vs. restore from .cab backup); a secondary CheckDeployedObjectCountAsync query on 'gobject WHERE deployed_version > 0' warns when the count is zero because discovery smoke tests will return empty hierarchies. NamedPipeProbe opens a 2s NamedPipeClientStream against OtOpcUaGalaxyHost's pipe ('OtOpcUaGalaxy' per the installer default) — pipe accepting a connection proves the Host service is listening; disconnects immediately so we don't consume a session slot.
Service lists kept as internal static data so tests can inspect + override: CoreServices (aaBootstrap + aaGR + NmxSvc + MSSQLSERVER — hard fail if missing), SoftServices (aaLogger + aaUserValidator + aaGlobalDataCacheMonitorSvr — warn only; stack runs without them but diagnostics/auth are degraded), HistorianServices (aahClientAccessPoint + aahGateway — opt-in via Options.CheckHistorian, only matters for HistoryRead IPC paths), OtOpcUaServices (our OtOpcUaGalaxyHost hard-required for end-to-end live tests + OtOpcUa warn + GLAuth warn). Narrower entry points CheckRepositoryOnlyAsync and CheckGalaxyHostPipeOnlyAsync for tests that only care about specific subsystems — avoid paying the full probe cost on every GalaxyRepositoryLiveSmokeTests fact.
Multi-targeting mechanics: System.ServiceProcess.ServiceController + Microsoft.Win32.Registry are NuGet packages on net10 but in-box BCL references on net48; csproj conditions Package vs Reference by TargetFramework. Microsoft.Data.SqlClient v6 supports both frameworks so single PackageReference. Net48Polyfills.cs provides IsExternalInit shim (records/init-only setters) and SupportedOSPlatformAttribute stub so the same Probe sources compile on both frameworks without per-callsite preprocessor guards — lets Roslyn's platform-compatibility analyzer stay useful on net10 without breaking net48 builds.
Existing GalaxyRepositoryLiveSmokeTests updated to delegate its skip decision to AvevaPrerequisites.CheckRepositoryOnlyAsync (legacy ZbReachableAsync kept as a compatibility adapter so the in-test 'if (!await ZbReachableAsync()) return;' pattern keeps working while the surrounding fixtures gradually migrate to Assert.Skip-with-reason). Slnx file registers the new project.
Tests — AvevaPrerequisitesLiveTests (8 new Integration cases, Category=LiveGalaxy): the helper correctly reports Framework install (registry pass), aaBootstrap Running (service pass), aaGR Running (service pass), MxAccess COM registered (com pass), ZB database reachable (sql pass), deployed-object count > 0 (warn-upgraded-to-pass because this box has 49 objects deployed), the AVEVA side is ready even when our own services (OtOpcUaGalaxyHost) aren't installed yet (IsAvevaSideReady=true), and the helper emits rows for OtOpcUaGalaxyHost + OtOpcUa + GLAuth even when not installed (regression guard — nobody can accidentally ship a check that omits our own services). Full Galaxy.Host.Tests Category=LiveGalaxy suite: 13 pass (5 prior smoke + 8 new prerequisites). Full solution build clean, 0 errors.
What's NOT in this PR: end-to-end Galaxy stack smoke (Proxy → Host pipe → MXAccess → real Galaxy tag). That's the next PR — this one is the gate the end-to-end smoke will call first to produce actionable skip messages instead of silent returns.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
112 lines
4.5 KiB
C#
112 lines
4.5 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Host.Backend;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Host.Backend.Galaxy;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Shared.Contracts;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.TestSupport;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Host.Tests
|
|
{
|
|
/// <summary>
|
|
/// Live smoke against the Galaxy <c>ZB</c> repository. Skipped when ZB is unreachable so
|
|
/// CI / dev boxes without an AVEVA install still pass. Exercises the ported
|
|
/// <see cref="GalaxyRepository"/> + <see cref="DbBackedGalaxyBackend"/> against the same
|
|
/// SQL the v1 Host uses, proving the lift is byte-for-byte equivalent at the
|
|
/// <c>DiscoverHierarchyResponse</c> shape.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Since PR 36, skip logic is delegated to <see cref="AvevaPrerequisites.CheckRepositoryOnlyAsync"/>
|
|
/// so operators see exactly why a test skipped ("ZB db not found" vs "SQL Server
|
|
/// unreachable") instead of a silent return.
|
|
/// </remarks>
|
|
[Trait("Category", "LiveGalaxy")]
|
|
public sealed class GalaxyRepositoryLiveSmokeTests
|
|
{
|
|
private static GalaxyRepositoryOptions DevZbOptions() => new()
|
|
{
|
|
ConnectionString =
|
|
"Server=localhost;Database=ZB;Integrated Security=True;TrustServerCertificate=True;Encrypt=False;Connect Timeout=2;",
|
|
CommandTimeoutSeconds = 10,
|
|
};
|
|
|
|
private static async Task<string?> RepositorySkipReasonAsync()
|
|
{
|
|
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(4));
|
|
var report = await AvevaPrerequisites.CheckRepositoryOnlyAsync(
|
|
DevZbOptions().ConnectionString, cts.Token);
|
|
return report.SkipReason;
|
|
}
|
|
|
|
private static async Task<bool> ZbReachableAsync()
|
|
{
|
|
// Legacy silent-skip adapter — keeps the existing tests compiling while
|
|
// gradually migrating to the Skip-with-reason pattern. Returns true when the
|
|
// prerequisite check has no Fail entries.
|
|
return (await RepositorySkipReasonAsync()) is null;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task TestConnection_returns_true_against_live_ZB()
|
|
{
|
|
if (!await ZbReachableAsync()) return;
|
|
|
|
var repo = new GalaxyRepository(DevZbOptions());
|
|
(await repo.TestConnectionAsync()).ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetHierarchy_returns_at_least_one_deployed_gobject()
|
|
{
|
|
if (!await ZbReachableAsync()) return;
|
|
|
|
var repo = new GalaxyRepository(DevZbOptions());
|
|
var rows = await repo.GetHierarchyAsync();
|
|
|
|
rows.Count.ShouldBeGreaterThan(0,
|
|
"the dev Galaxy has at least the WinPlatform + AppEngine deployed");
|
|
rows.ShouldAllBe(r => !string.IsNullOrEmpty(r.TagName));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetAttributes_returns_attributes_for_deployed_objects()
|
|
{
|
|
if (!await ZbReachableAsync()) return;
|
|
|
|
var repo = new GalaxyRepository(DevZbOptions());
|
|
var attrs = await repo.GetAttributesAsync();
|
|
|
|
attrs.Count.ShouldBeGreaterThan(0);
|
|
attrs.ShouldAllBe(a => !string.IsNullOrEmpty(a.FullTagReference) && a.FullTagReference.Contains("."));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetLastDeployTime_returns_a_value()
|
|
{
|
|
if (!await ZbReachableAsync()) return;
|
|
|
|
var repo = new GalaxyRepository(DevZbOptions());
|
|
var ts = await repo.GetLastDeployTimeAsync();
|
|
ts.ShouldNotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task DbBackedBackend_DiscoverAsync_returns_objects_with_attributes_and_categories()
|
|
{
|
|
if (!await ZbReachableAsync()) return;
|
|
|
|
var backend = new DbBackedGalaxyBackend(new GalaxyRepository(DevZbOptions()));
|
|
var resp = await backend.DiscoverAsync(new DiscoverHierarchyRequest { SessionId = 1 }, CancellationToken.None);
|
|
|
|
resp.Success.ShouldBeTrue(resp.Error);
|
|
resp.Objects.Length.ShouldBeGreaterThan(0);
|
|
|
|
var firstWithAttrs = System.Linq.Enumerable.FirstOrDefault(resp.Objects, o => o.Attributes.Length > 0);
|
|
firstWithAttrs.ShouldNotBeNull("at least one gobject in the dev Galaxy carries dynamic attributes");
|
|
firstWithAttrs!.TemplateCategory.ShouldNotBeNullOrEmpty();
|
|
}
|
|
}
|
|
}
|