Skip to content

Commit

Permalink
Fixed compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jan 12, 2024
1 parent 0e11ea0 commit 14154e1
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/DotNext.Tests/Buffers/BufferWriterSlimTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void GrowableBuffer()
Span<int> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/DotNext.Tests/IO/DataTransferObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ 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);
True(empty.IsReusable);
True(empty.TryGetMemory(out var memory));
True(memory.IsEmpty);

Empty(empty.ToByteArrayAsync().Result);
Empty(await empty.ToByteArrayAsync());

var writer = new ArrayBufferWriter<byte>();
True(empty.WriteToAsync(IAsyncBinaryWriter.Create(writer), CancellationToken.None).IsCompletedSuccessfully);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public static async Task SnapshotInstallation(bool useCaching)
False(readResult[2].IsSnapshot);
return default;
};
await state.As<IRaftLog>().ReadAsync(new LogEntryConsumer(checker), 6, 9, CancellationToken.None).ConfigureAwait(false);
await state.As<IRaftLog>().ReadAsync(new LogEntryConsumer(checker), 6, 9);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/DotNext.Tests/Net/Cluster/Messaging/MessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 14 additions & 14 deletions src/DotNext.Tests/SpanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static unsafe void SortingUsingPointer()
[Fact]
public static void IndexOf()
{
ReadOnlySpan<ulong> span = new ulong[] { 3, 2, 6, 4 };
ReadOnlySpan<ulong> span = [3, 2, 6, 4];
Equal(1, span.IndexOf(2UL, 0, EqualityComparer<ulong>.Default.Equals));
Equal(3, span.IndexOf(4UL, 0, EqualityComparer<ulong>.Default.Equals));
Equal(3UL, span[0]);
Expand All @@ -65,7 +65,7 @@ public static void ForEach()
[Fact]
public static void TrimByLength1()
{
Span<int> span = new int[] { 1, 2, 3 };
Span<int> span = [1, 2, 3];
span = span.TrimLength(4);
Equal(3, span.Length);
span = span.TrimLength(2);
Expand All @@ -77,7 +77,7 @@ public static void TrimByLength1()
[Fact]
public static void TrimByLength2()
{
ReadOnlySpan<int> span = new int[] { 1, 2, 3 };
ReadOnlySpan<int> span = [1, 2, 3];
span = span.TrimLength(4);
Equal(3, span.Length);
span = span.TrimLength(2);
Expand Down Expand Up @@ -468,8 +468,8 @@ public static void SwapElements()
Span<byte> 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]
Expand All @@ -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<ArgumentException>(() => new int[] { 1, 2, 3, 4, 5, 6 }.AsSpan().Swap(0..2, 1..3));
Expand All @@ -520,16 +520,16 @@ public static void MoveRange()
// move from left to right
Span<int> 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<ArgumentOutOfRangeException>(() => new int[] { 1, 2, 3, 4, 5, 6 }.AsSpan().Move(0..2, 1));
Expand Down
8 changes: 4 additions & 4 deletions src/DotNext.Tests/Threading/Tasks/ConversionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
16 changes: 9 additions & 7 deletions src/DotNext.Tests/Threading/Tasks/TaskCompletionPipeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down

0 comments on commit 14154e1

Please sign in to comment.