From 14154e17699e1298979e752c18dfe414897f805a Mon Sep 17 00:00:00 2001 From: sakno Date: Fri, 12 Jan 2024 18:25:19 +0200 Subject: [PATCH] Fixed compiler warnings --- .../Buffers/BufferWriterSlimTests.cs | 2 +- .../IO/DataTransferObjectTests.cs | 4 +-- .../Raft/DiskBasedStateMachineTests.cs | 2 +- .../Raft/Http/RaftHttpClusterTests.cs | 10 +++---- .../HyParView/Http/HttpPeerControllerTests.cs | 4 +-- .../Net/Cluster/Messaging/MessageTests.cs | 2 +- .../SpawningAsyncTaskMethodBuilderTests.cs | 2 +- src/DotNext.Tests/SpanTests.cs | 28 +++++++++---------- .../Threading/Tasks/ConversionTests.cs | 8 +++--- .../Tasks/TaskCompletionPipeTests.cs | 16 ++++++----- 10 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/DotNext.Tests/Buffers/BufferWriterSlimTests.cs b/src/DotNext.Tests/Buffers/BufferWriterSlimTests.cs index 128e9374e..4de896deb 100644 --- a/src/DotNext.Tests/Buffers/BufferWriterSlimTests.cs +++ b/src/DotNext.Tests/Buffers/BufferWriterSlimTests.cs @@ -29,7 +29,7 @@ public static void GrowableBuffer() Span result = stackalloc int[5]; builder.WrittenSpan.CopyTo(result, out var writtenCount); Equal(4, writtenCount); - Equal([10, 20, 30, 40, 0], result.ToArray()); + Equal([10, 20, 30, 40, 0], result); builder.Clear(true); Equal(0, builder.WrittenCount); diff --git a/src/DotNext.Tests/IO/DataTransferObjectTests.cs b/src/DotNext.Tests/IO/DataTransferObjectTests.cs index e5835940c..ea122513e 100644 --- a/src/DotNext.Tests/IO/DataTransferObjectTests.cs +++ b/src/DotNext.Tests/IO/DataTransferObjectTests.cs @@ -107,7 +107,7 @@ public static async Task DefaultDecodeAsync(int dataSize, bool withLength) } [Fact] - public static void EmptyObject() + public static async Task EmptyObject() { var empty = IDataTransferObject.Empty; Equal(0L, empty.Length); @@ -115,7 +115,7 @@ public static void EmptyObject() True(empty.TryGetMemory(out var memory)); True(memory.IsEmpty); - Empty(empty.ToByteArrayAsync().Result); + Empty(await empty.ToByteArrayAsync()); var writer = new ArrayBufferWriter(); True(empty.WriteToAsync(IAsyncBinaryWriter.Create(writer), CancellationToken.None).IsCompletedSuccessfully); diff --git a/src/DotNext.Tests/Net/Cluster/Consensus/Raft/DiskBasedStateMachineTests.cs b/src/DotNext.Tests/Net/Cluster/Consensus/Raft/DiskBasedStateMachineTests.cs index e34b35b00..cbbdd3831 100644 --- a/src/DotNext.Tests/Net/Cluster/Consensus/Raft/DiskBasedStateMachineTests.cs +++ b/src/DotNext.Tests/Net/Cluster/Consensus/Raft/DiskBasedStateMachineTests.cs @@ -271,7 +271,7 @@ public static async Task SnapshotInstallation(bool useCaching) False(readResult[2].IsSnapshot); return default; }; - await state.As().ReadAsync(new LogEntryConsumer(checker), 6, 9, CancellationToken.None).ConfigureAwait(false); + await state.As().ReadAsync(new LogEntryConsumer(checker), 6, 9); } } } \ No newline at end of file diff --git a/src/DotNext.Tests/Net/Cluster/Consensus/Raft/Http/RaftHttpClusterTests.cs b/src/DotNext.Tests/Net/Cluster/Consensus/Raft/Http/RaftHttpClusterTests.cs index 60e455708..480742cc9 100644 --- a/src/DotNext.Tests/Net/Cluster/Consensus/Raft/Http/RaftHttpClusterTests.cs +++ b/src/DotNext.Tests/Net/Cluster/Consensus/Raft/Http/RaftHttpClusterTests.cs @@ -87,7 +87,7 @@ public static async Task CommunicationWithLeader() await host3.StartAsync(); await listener.Task.WaitAsync(DefaultTimeout); - Equal(new UriEndPoint(GetLocalClusterView(host1).LocalMemberAddress), listener.Task.Result.EndPoint, EndPointFormatter.UriEndPointComparer); + Equal(new UriEndPoint(GetLocalClusterView(host1).LocalMemberAddress), (await listener.Task).EndPoint, EndPointFormatter.UriEndPointComparer); // add two nodes to the cluster True(await GetLocalClusterView(host1).AddMemberAsync(GetLocalClusterView(host2).LocalMemberAddress)); @@ -159,7 +159,7 @@ public static async Task MessageExchange(string protocolPath) await host2.StartAsync(); await listener.Task.WaitAsync(DefaultTimeout); - Equal(new UriEndPoint(GetLocalClusterView(host1).LocalMemberAddress), listener.Task.Result.EndPoint, EndPointFormatter.UriEndPointComparer); + Equal(new UriEndPoint(GetLocalClusterView(host1).LocalMemberAddress), (await listener.Task).EndPoint, EndPointFormatter.UriEndPointComparer); True(await GetLocalClusterView(host1).AddMemberAsync(GetLocalClusterView(host2).LocalMemberAddress)); await GetLocalClusterView(host2).Readiness.WaitAsync(DefaultTimeout); @@ -231,7 +231,7 @@ public static async Task TypedMessageExchange() await host2.StartAsync(); await listener.Task.WaitAsync(DefaultTimeout); - Equal(new UriEndPoint(GetLocalClusterView(host1).LocalMemberAddress), listener.Task.Result.EndPoint, EndPointFormatter.UriEndPointComparer); + Equal(new UriEndPoint(GetLocalClusterView(host1).LocalMemberAddress), (await listener.Task).EndPoint, EndPointFormatter.UriEndPointComparer); True(await GetLocalClusterView(host1).AddMemberAsync(GetLocalClusterView(host2).LocalMemberAddress)); await GetLocalClusterView(host2).Readiness.WaitAsync(DefaultTimeout); @@ -303,7 +303,7 @@ public static async Task Leadership() await host3.StartAsync(); await listener.Task.WaitAsync(DefaultTimeout); - Equal(new UriEndPoint(GetLocalClusterView(host1).LocalMemberAddress), listener.Task.Result.EndPoint, EndPointFormatter.UriEndPointComparer); + Equal(new UriEndPoint(GetLocalClusterView(host1).LocalMemberAddress), (await listener.Task).EndPoint, EndPointFormatter.UriEndPointComparer); // add two nodes to the cluster True(await GetLocalClusterView(host1).AddMemberAsync(GetLocalClusterView(host2).LocalMemberAddress)); @@ -437,7 +437,7 @@ public static async Task StandbyMode() await host3.StartAsync(); await listener.Task.WaitAsync(DefaultTimeout); - Equal(new UriEndPoint(GetLocalClusterView(host1).LocalMemberAddress), listener.Task.Result.EndPoint, EndPointFormatter.UriEndPointComparer); + Equal(new UriEndPoint(GetLocalClusterView(host1).LocalMemberAddress), (await listener.Task).EndPoint, EndPointFormatter.UriEndPointComparer); // add two nodes to the cluster True(await GetLocalClusterView(host1).AddMemberAsync(GetLocalClusterView(host2).LocalMemberAddress)); diff --git a/src/DotNext.Tests/Net/Cluster/Discovery/HyParView/Http/HttpPeerControllerTests.cs b/src/DotNext.Tests/Net/Cluster/Discovery/HyParView/Http/HttpPeerControllerTests.cs index 8411a68d6..98d88e393 100644 --- a/src/DotNext.Tests/Net/Cluster/Discovery/HyParView/Http/HttpPeerControllerTests.cs +++ b/src/DotNext.Tests/Net/Cluster/Discovery/HyParView/Http/HttpPeerControllerTests.cs @@ -60,8 +60,8 @@ public static async Task ConnectDisconnect() await Task.WhenAll(listener1.DiscoveryTask, listener1.DiscoveryTask).WaitAsync(DefaultTimeout); - Equal(new UriEndPoint(new("http://localhost:3362/", UriKind.Absolute)), listener2.DiscoveryTask.Result, EndPointFormatter.UriEndPointComparer); - Equal(new UriEndPoint(new("http://localhost:3363/", UriKind.Absolute)), listener1.DiscoveryTask.Result, EndPointFormatter.UriEndPointComparer); + Equal(new UriEndPoint(new("http://localhost:3362/", UriKind.Absolute)), await listener2.DiscoveryTask, EndPointFormatter.UriEndPointComparer); + Equal(new UriEndPoint(new("http://localhost:3363/", UriKind.Absolute)), await listener1.DiscoveryTask, EndPointFormatter.UriEndPointComparer); // shutdown peer gracefully await peer2.StopAsync(); diff --git a/src/DotNext.Tests/Net/Cluster/Messaging/MessageTests.cs b/src/DotNext.Tests/Net/Cluster/Messaging/MessageTests.cs index bc018b517..d87e8c095 100644 --- a/src/DotNext.Tests/Net/Cluster/Messaging/MessageTests.cs +++ b/src/DotNext.Tests/Net/Cluster/Messaging/MessageTests.cs @@ -13,7 +13,7 @@ public static async Task TextMessageUsingStream() { IMessage message = new TextMessage("Hello, world!", "msg"); using var content = new MemoryStream(1024); - await message.WriteToAsync(content).ConfigureAwait(false); + await message.WriteToAsync(content); content.Seek(0, SeekOrigin.Begin); using var reader = new StreamReader(content, Encoding.UTF8, false, 1024, true); Equal("Hello, world!", reader.ReadToEnd()); diff --git a/src/DotNext.Tests/Runtime/CompilerServices/SpawningAsyncTaskMethodBuilderTests.cs b/src/DotNext.Tests/Runtime/CompilerServices/SpawningAsyncTaskMethodBuilderTests.cs index c75f5e23b..fd16eb06a 100644 --- a/src/DotNext.Tests/Runtime/CompilerServices/SpawningAsyncTaskMethodBuilderTests.cs +++ b/src/DotNext.Tests/Runtime/CompilerServices/SpawningAsyncTaskMethodBuilderTests.cs @@ -34,7 +34,7 @@ static async Task CheckThreadId(int callerThreadId) } [Fact] - public static async void CancellationOfSpawnedMethod() + public static async Task CancellationOfSpawnedMethod() { var task = CheckThreadId(Thread.CurrentThread.ManagedThreadId, new(true)); await Task.WhenAny(task); diff --git a/src/DotNext.Tests/SpanTests.cs b/src/DotNext.Tests/SpanTests.cs index 007008190..9876cba66 100644 --- a/src/DotNext.Tests/SpanTests.cs +++ b/src/DotNext.Tests/SpanTests.cs @@ -44,7 +44,7 @@ public static unsafe void SortingUsingPointer() [Fact] public static void IndexOf() { - ReadOnlySpan span = new ulong[] { 3, 2, 6, 4 }; + ReadOnlySpan span = [3, 2, 6, 4]; Equal(1, span.IndexOf(2UL, 0, EqualityComparer.Default.Equals)); Equal(3, span.IndexOf(4UL, 0, EqualityComparer.Default.Equals)); Equal(3UL, span[0]); @@ -65,7 +65,7 @@ public static void ForEach() [Fact] public static void TrimByLength1() { - Span span = new int[] { 1, 2, 3 }; + Span span = [1, 2, 3]; span = span.TrimLength(4); Equal(3, span.Length); span = span.TrimLength(2); @@ -77,7 +77,7 @@ public static void TrimByLength1() [Fact] public static void TrimByLength2() { - ReadOnlySpan span = new int[] { 1, 2, 3 }; + ReadOnlySpan span = [1, 2, 3]; span = span.TrimLength(4); Equal(3, span.Length); span = span.TrimLength(2); @@ -468,8 +468,8 @@ public static void SwapElements() Span actual = expected.ToArray(); var midpoint = actual.Length >> 1; actual.Slice(0, midpoint).Swap(actual.Slice(midpoint)); - Equal(expected.Slice(midpoint).ToArray(), actual.Slice(0, midpoint).ToArray()); - Equal(expected.Slice(0, midpoint).ToArray(), actual.Slice(midpoint).ToArray()); + Equal(expected.Slice(midpoint), actual.Slice(0, midpoint)); + Equal(expected.Slice(0, midpoint), actual.Slice(midpoint)); } [Fact] @@ -483,32 +483,32 @@ public static void TransformElements() // left > right input = [1, 2, 3, 4, 5, 6]; input.Swap(0..3, 4..6); - Equal([5, 6, 4, 1, 2, 3], input.ToArray()); + Equal([5, 6, 4, 1, 2, 3], input); // left is zero length input = [1, 2, 3, 4, 5, 6]; input.Swap(1..1, 3..6); - Equal([1, 4, 5, 6, 2, 3], input.ToArray()); + Equal([1, 4, 5, 6, 2, 3], input); // right is zero length input = [1, 2, 3, 4, 5, 6]; input.Swap(0..2, 3..3); - Equal([3, 1, 2, 4, 5, 6], input.ToArray()); + Equal([3, 1, 2, 4, 5, 6], input); // no space between ranges input = [1, 2, 3, 4, 5, 6]; input.Swap(0..2, 2..6); - Equal([3, 4, 5, 6, 1, 2], input.ToArray()); + Equal([3, 4, 5, 6, 1, 2], input); // left == right input = [1, 2, 3, 4, 5, 6]; input.Swap(0..3, 3..6); - Equal([4, 5, 6, 1, 2, 3], input.ToArray()); + Equal([4, 5, 6, 1, 2, 3], input); // left and right are empty input = [1, 2, 3, 4, 5, 6]; input.Swap(1..1, 5..5); - Equal([1, 2, 3, 4, 5, 6], input.ToArray()); + Equal([1, 2, 3, 4, 5, 6], input); // overlapping Throws(() => new int[] { 1, 2, 3, 4, 5, 6 }.AsSpan().Swap(0..2, 1..3)); @@ -520,16 +520,16 @@ public static void MoveRange() // move from left to right Span input = [1, 2, 3, 4, 5, 6]; input.Move(0..2, 3); - Equal([3, 1, 2, 4, 5, 6], input.ToArray()); + Equal([3, 1, 2, 4, 5, 6], input); // move from left to right input = [1, 2, 3, 4, 5, 6]; input.Move(1..3, 6); - Equal([1, 4, 5, 6, 2, 3], input.ToArray()); + Equal([1, 4, 5, 6, 2, 3], input); // move from right to left input.Move(4..6, 1); - Equal([1, 2, 3, 4, 5, 6], input.ToArray()); + Equal([1, 2, 3, 4, 5, 6], input); // out of range Throws(() => new int[] { 1, 2, 3, 4, 5, 6 }.AsSpan().Move(0..2, 1)); diff --git a/src/DotNext.Tests/Threading/Tasks/ConversionTests.cs b/src/DotNext.Tests/Threading/Tasks/ConversionTests.cs index 1f673035d..0f7b4e27e 100644 --- a/src/DotNext.Tests/Threading/Tasks/ConversionTests.cs +++ b/src/DotNext.Tests/Threading/Tasks/ConversionTests.cs @@ -5,17 +5,17 @@ namespace DotNext.Threading.Tasks; public sealed class ConversionTests : Test { [Fact] - public static void Nullable() + public static async Task Nullable() { var t = Task.FromResult(10).ToNullable(); - Equal(10, t.Result); + Equal(10, await t); } [Fact] - public static void TypeConversion() + public static async Task TypeConversion() { var t = Task.FromResult("12").Convert(int.Parse); - Equal(12, t.Result); + Equal(12, await t); } [Fact] diff --git a/src/DotNext.Tests/Threading/Tasks/TaskCompletionPipeTests.cs b/src/DotNext.Tests/Threading/Tasks/TaskCompletionPipeTests.cs index 713bc3ff4..7b4038d9e 100644 --- a/src/DotNext.Tests/Threading/Tasks/TaskCompletionPipeTests.cs +++ b/src/DotNext.Tests/Threading/Tasks/TaskCompletionPipeTests.cs @@ -22,7 +22,8 @@ public static async Task StressTest() var result = 0; await foreach (var task in pipe) { - result += task.Result; + True(task.IsCompleted); + result += await task; } Equal(4200, result); @@ -50,7 +51,8 @@ public static async Task StressTest2() { if (pipe.TryRead(out var task, out var actualUserData)) { - result += task.Result; + True(task.IsCompleted); + result += await task; Same(expectedUserData, actualUserData); } } @@ -80,7 +82,7 @@ public static async Task QueueGrowth() pipe.Add(Task.FromResult(43)); True(await pipe.WaitToReadAsync()); True(pipe.TryRead(out var task)); - Equal(42, task.Result); + Equal(42, await task); pipe.Add(Task.FromResult(44)); pipe.Add(Task.FromResult(45)); @@ -89,16 +91,16 @@ public static async Task QueueGrowth() await using (var enumerator = pipe.GetAsyncEnumerator(CancellationToken.None)) { True(await enumerator.MoveNextAsync()); - Equal(43, enumerator.Current.Result); + Equal(43, await enumerator.Current); True(await enumerator.MoveNextAsync()); - Equal(44, enumerator.Current.Result); + Equal(44, await enumerator.Current); True(await enumerator.MoveNextAsync()); - Equal(45, enumerator.Current.Result); + Equal(45, await enumerator.Current); True(await enumerator.MoveNextAsync()); - Equal(46, enumerator.Current.Result); + Equal(46, await enumerator.Current); } False(pipe.TryRead(out task));