From 53617e49005f408f3ef575bc695be5e9718da878 Mon Sep 17 00:00:00 2001 From: Roman Ettlinger Date: Tue, 27 Oct 2026 07:24:16 +0100 Subject: [PATCH] Server tests: keep the admitted event alive in identity conflict tests EventManager holds an admitted event identity only weakly, through the admitted event. ChangedNativeCoreStateIsRejectedAfterAdmissionIsRequired and LegacyNativeConflictMakesLaterOptionalAdmissionUnavailable admitted a temporary event, so a GC before the conflicting admission (other tests in the process call GC.Collect) released the identity and the changed event was accepted. The net48 Release JIT does not extend the temporary's lifetime, which made test-windows-net48 fail on PR #4916. Hold the first event and GC.KeepAlive it, as the neighbouring tests already do. Co-Authored-By: Claude Opus 5.5 --- .../NodeManager/EventIdentityAdmissionTests.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/Opc.Ua.Server.Tests/NodeManager/EventIdentityAdmissionTests.cs b/tests/Opc.Ua.Server.Tests/NodeManager/EventIdentityAdmissionTests.cs index 8836a37c82..6b9b5a973e 100644 --- a/tests/Opc.Ua.Server.Tests/NodeManager/EventIdentityAdmissionTests.cs +++ b/tests/Opc.Ua.Server.Tests/NodeManager/EventIdentityAdmissionTests.cs @@ -257,13 +257,17 @@ namespace Opc.Ua.Server.Tests.NodeManager { using var fixture = new IdentityFixture(); EnableAdmission(fixture); - fixture.Manager.AdmitEvent(fixture.Context, Event(s_id)); + // The manager holds the admitted identity only while the admitted + // event is reachable; keep it alive so a GC cannot release it. + BaseEventState first = Event(s_id); + fixture.Manager.AdmitEvent(fixture.Context, first); BaseEventState changed = Event(s_id); changed.Severity!.Value = 999; AssertStatus(() => fixture.Manager.AdmitEvent(fixture.Context, changed), StatusCodes.BadSecurityChecksFailed); fixture.Manager.AdmitEvent(fixture.Context, Event(s_id)); + GC.KeepAlive(first); } /// @@ -308,7 +312,8 @@ namespace Opc.Ua.Server.Tests.NodeManager public void LegacyNativeConflictMakesLaterOptionalAdmissionUnavailable() { using var fixture = new IdentityFixture(); - fixture.Manager.AdmitEvent(fixture.Context, Event(s_id)); + BaseEventState first = Event(s_id); + fixture.Manager.AdmitEvent(fixture.Context, first); BaseEventState changed = Event(s_id); changed.Severity!.Value = 999; fixture.Manager.AdmitEvent(fixture.Context, changed); @@ -316,6 +321,7 @@ namespace Opc.Ua.Server.Tests.NodeManager Assert.That(fixture.Manager.EventIdentityAdmissionStatus, Is.EqualTo(StatusCodes.BadNotSupported)); AssertStatus(() => fixture.Manager.ReserveEventIdentity(s_otherId, new Origin()).Dispose(), StatusCodes.BadNotSupported); + GC.KeepAlive(first); } ///