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 <noreply@anthropic.com>
This commit is contained in:
Roman Ettlinger
2026-10-27 07:24:16 +01:00
co-authored by Claude Opus 5.5
parent 3703ad0967
commit 53617e4900
@@ -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);
}
/// <summary>
@@ -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);
}
/// <summary>