Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make NodeStateCollectionConcurrencyTests more robust #2594

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using Assert = NUnit.Framework.Legacy.ClassicAssert;
Expand All @@ -17,7 +18,8 @@ namespace Opc.Ua.Core.Tests.Stack.State
public class NodeStateCollectionConcurrencyTests
{
[Test]
public void NodeStateReferencesCollectionConcurrencyTest()
[CancelAfter(10000)]
public void NodeStateReferencesCollectionConcurrencyTest(CancellationToken cancellationToken)
{
var testNodeState = new AnalogUnitRangeState(null);
var serviceMessageContext = new ServiceMessageContext();
Expand Down Expand Up @@ -56,13 +58,13 @@ public void NodeStateReferencesCollectionConcurrencyTest()

});

while (referenceTargets.TryTake(out ExpandedNodeId target, TimeSpan.FromSeconds(1)))
foreach (var target in referenceTargets.GetConsumingEnumerable(cancellationToken))
{
var removeReferenceSuccess = testNodeState.RemoveReference(ReferenceTypeIds.HasComponent, false, target);
Assert.IsTrue(removeReferenceSuccess);
}

task.Wait();
task.Wait(cancellationToken);

references.Clear();
testNodeState.GetReferences(systemContext, references);
Expand All @@ -72,7 +74,8 @@ public void NodeStateReferencesCollectionConcurrencyTest()
}

[Test]
public void NodeStateNotifiersCollectionConcurrencyTest()
[CancelAfter(10000)]
public void NodeStateNotifiersCollectionConcurrencyTest(CancellationToken cancellationToken)
{
var serviceMessageContext = new ServiceMessageContext();
var systemContext = new SystemContext() { NamespaceUris = serviceMessageContext.NamespaceUris };
Expand Down Expand Up @@ -120,12 +123,12 @@ public void NodeStateNotifiersCollectionConcurrencyTest()

});

while (notifierTargets.TryTake(out NodeState target, TimeSpan.FromSeconds(1)))
foreach(var target in notifierTargets.GetConsumingEnumerable(cancellationToken))
{
testNodeState.RemoveNotifier(systemContext, target, false);
}

task.Wait();
task.Wait(cancellationToken);

notifiers.Clear();
testNodeState.GetNotifiers(systemContext, notifiers);
Expand All @@ -135,7 +138,8 @@ public void NodeStateNotifiersCollectionConcurrencyTest()
}

[Test]
public void NodeStateChildrenCollectionConcurrencyTest()
[CancelAfter(10000)]
public void NodeStateChildrenCollectionConcurrencyTest(CancellationToken cancellationToken)
{
var serviceMessageContext = new ServiceMessageContext();
var systemContext = new SystemContext() { NamespaceUris = serviceMessageContext.NamespaceUris };
Expand Down Expand Up @@ -183,12 +187,12 @@ public void NodeStateChildrenCollectionConcurrencyTest()

});

while (childrenCollection.TryTake(out BaseInstanceState child, TimeSpan.FromSeconds(1)))
foreach (var child in childrenCollection.GetConsumingEnumerable(cancellationToken))
{
testNodeState.RemoveChild(child);
}

task.Wait();
task.Wait(cancellationToken);

children.Clear();
testNodeState.GetChildren(systemContext, children);
Expand Down