Skip to content

Commit

Permalink
with callback, but is still cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
katarinagud committed Jun 17, 2024
1 parent 78ba546 commit 2ff849c
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Threading.Tasks;
using Machine.Specifications;
using Opc.Ua;
using Moq;
using It = Machine.Specifications.It;

namespace RaaLabs.Edge.Connectors.OPCUA.for_Reader.when_reading_nodes_forever;

Expand All @@ -18,14 +20,11 @@ public class and_datavalue_found : given.a_reader
Establish context = async () =>

Check warning on line 20 in Specifications/for_Reader/when_reading_nodes_forever/and_datavalue_found.cs

View workflow job for this annotation

GitHub Actions / dotnet / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 20 in Specifications/for_Reader/when_reading_nodes_forever/and_datavalue_found.cs

View workflow job for this annotation

GitHub Actions / dotnet / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 20 in Specifications/for_Reader/when_reading_nodes_forever/and_datavalue_found.cs

View workflow job for this annotation

GitHub Actions / sonarcloud / Sonarcloud

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 20 in Specifications/for_Reader/when_reading_nodes_forever/and_datavalue_found.cs

View workflow job for this annotation

GitHub Actions / sonarcloud / Sonarcloud

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 20 in Specifications/for_Reader/when_reading_nodes_forever/and_datavalue_found.cs

View workflow job for this annotation

GitHub Actions / sonarcloud / Sonarcloud

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
nodes = [(new NodeId(321), TimeSpan.FromSeconds(1))];

connection
.Setup(_ => _.ReadValueAsync(new NodeId(321), Moq.It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(new DataValue("reading value")));


connection
.Setup(_ => _.ReadValueAsync(new NodeId(321), Moq.It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(new DataValue("reading value 2")));
.Callback(() => cancellation_token_source.Cancel())
.ReturnsAsync(new DataValue("reading value"));

handled_values = [];

Expand All @@ -34,15 +33,11 @@ public class and_datavalue_found : given.a_reader
handled_values.Add(_);
return Task.CompletedTask;
};

cancellation_token_source.CancelAfter(TimeSpan.FromSeconds(2));

};

Because of = async () =>
{
await reader.ReadNodesForever(connection.Object, nodes, handler, cancellation_token_source.Token);
connection.Object.Close();
};

It should_have_read_the_values = () => handled_values.ShouldContainOnly(new NodeValue(new (321), new ("reading value")));
Expand Down

0 comments on commit 2ff849c

Please sign in to comment.