Skip to content

Commit d501447

Browse files
Roslynator fixes.
1 parent 81555d7 commit d501447

18 files changed

+188
-104
lines changed

Open.ChannelExtensions.Tests/AssumptionTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ public static async Task WaitCancellation()
3838
var result = await Task.WhenAny(t1.AsTask(), t2.AsTask()).ConfigureAwait(false);
3939
Assert.True(result.IsCanceled);
4040
}
41-
4241
}
4342
}

Open.ChannelExtensions.Tests/BatchTests.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ await c.Reader
5454
}
5555
await Task.Delay(500);
5656
});
57-
5857
}
5958

6059
[Fact]
@@ -104,10 +103,8 @@ await c.Reader
104103
}
105104
await Task.Delay(500);
106105
});
107-
108106
}
109107

110-
111108
[Fact]
112109
public static async Task ForceBatchTest()
113110
{
@@ -146,7 +143,6 @@ public static async Task ForceBatchTest()
146143
}
147144
await Task.Delay(500);
148145
}));
149-
150146
}
151147

152148
[Fact]
@@ -229,7 +225,6 @@ public static async Task TimeoutTest0()
229225
}));
230226
}
231227

232-
233228
[Fact]
234229
public static async Task TimeoutTest1()
235230
{
@@ -272,14 +267,13 @@ public static async Task TimeoutTest1()
272267
}));
273268
}
274269

275-
276270
#if NET5_0_OR_GREATER
277271
[Fact]
278272
public static async Task BatchReadBehavior()
279273
{
280274
var c = Channel.CreateBounded<int>(new BoundedChannelOptions(20) { SingleReader = false, SingleWriter = false });
281275
BatchingChannelReader<int> reader = c.Reader.Batch(10);
282-
276+
283277
var queue = new Queue<int>(Enumerable.Range(0, 100));
284278
int e;
285279
while(queue.TryDequeue(out e) && c.Writer.TryWrite(e))
@@ -423,4 +417,3 @@ public static async IAsyncEnumerable<IList<T>> ReadBatchEnumerableAsyncBakedIn<T
423417
}
424418
#endif
425419
}
426-

Open.ChannelExtensions.Tests/CancellationTests.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace Open.ChannelExtensions.Tests;
88

99
public static class CancellationTests
1010
{
11-
1211
[Fact]
1312
public static async Task OperationCancellationPropagation()
1413
{
@@ -71,7 +70,6 @@ await range
7170
Assert.NotEqual(testSize, total);
7271
}
7372

74-
7573
[Fact]
7674
public static async Task CancellationPropagationConcurrent()
7775
{
@@ -102,7 +100,5 @@ await range
102100

103101
Assert.Equal(1, count);
104102
Assert.NotEqual(testSize, total);
105-
106103
}
107-
108-
}
104+
}

Open.ChannelExtensions.Tests/ExceptionTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Open.ChannelExtensions.Tests;
88

99
public static class ExceptionTests
1010
{
11-
11+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1194:Implement exception constructors.")]
1212
class TestException : Exception { }
1313

1414
[Fact]
@@ -48,7 +48,6 @@ await Assert.ThrowsAsync<AggregateException>(async () =>
4848
{
4949
try
5050
{
51-
5251
await range
5352
.ToChannel()
5453
.ReadAllConcurrently(8, i =>
@@ -60,7 +59,6 @@ await range
6059
throw new TestException();
6160
}
6261
});
63-
6462
}
6563
catch (Exception ex)
6664
{

Open.ChannelExtensions.Tests/SpecialTests.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
64
using System.Threading;
75
using System.Threading.Channels;
86
using System.Threading.Tasks;
97
using Xunit;
10-
using Xunit.Abstractions;
118

129
namespace Open.ChannelExtensions.Tests;
1310

1411
public class SpecialTests
1512
{
16-
private readonly ITestOutputHelper output;
17-
18-
public SpecialTests(ITestOutputHelper outputHelper)
19-
{
20-
output = outputHelper;
21-
}
22-
2313
[Fact]
2414
public void PossibleSourceLoadingIssue()
2515
{
@@ -47,7 +37,7 @@ Task StartProcessingTask2(IEnumerable<int> source)
4737
.ReadAll(IncrementCount2)
4838
.AsTask();
4939

50-
void IncrementCount2(int c)
40+
void IncrementCount2(int _)
5141
=> Interlocked.Increment(ref count_);
5242
}
5343
}

Open.ChannelExtensions/BatchingChannelReader.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public BatchingChannelReader<T> WithTimeout(long millisecondsTimeout)
5959
{
6060
_timeout = millisecondsTimeout <= 0 ? Timeout.Infinite : millisecondsTimeout;
6161

62-
if (Buffer is null || Buffer.Reader.Completion.IsCompleted)
62+
if (Buffer?.Reader.Completion.IsCompleted != false)
6363
return this;
6464

6565
if (_timeout == Timeout.Infinite)
@@ -72,7 +72,7 @@ public BatchingChannelReader<T> WithTimeout(long millisecondsTimeout)
7272
() => new Timer(ForceBatch));
7373

7474
if (_batch is null) return this;
75-
75+
7676
// Might be in the middle of a batch so we need to update the timeout.
7777
lock(Buffer)
7878
{
@@ -108,7 +108,7 @@ protected override void OnBeforeFinalFlush()
108108
/// <inheritdoc />
109109
protected override bool TryPipeItems(bool flush)
110110
{
111-
if (Buffer is null || Buffer.Reader.Completion.IsCompleted)
111+
if (Buffer?.Reader.Completion.IsCompleted != false)
112112
return false;
113113

114114
lock (Buffer)
@@ -119,7 +119,7 @@ protected override bool TryPipeItems(bool flush)
119119
var newBatch = false;
120120
List<T>? c = _batch;
121121
ChannelReader<T>? source = Source;
122-
if (source is null || source.Completion.IsCompleted)
122+
if (source?.Completion.IsCompleted != false)
123123
{
124124
// All finished, if necessary, release the last batch to the buffer.
125125
if (c is null) return false;
@@ -128,12 +128,15 @@ protected override bool TryPipeItems(bool flush)
128128

129129
while (source.TryRead(out T? item))
130130
{
131-
if (c is not null) c.Add(item);
132-
else
131+
if (c is null)
133132
{
134133
newBatch = true; // a new batch could start but not be emmited.
135134
_batch = c = new List<T>(_batchSize) { item };
136135
}
136+
else
137+
{
138+
c.Add(item);
139+
}
137140

138141
Debug.Assert(c.Count <= _batchSize);
139142
var full = c.Count == _batchSize;

Open.ChannelExtensions/BufferingChannelReader.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public abstract class BufferingChannelReader<TIn, TOut> : ChannelReader<TOut>
2323
/// </summary>
2424
protected Channel<TOut>? Buffer { get; }
2525

26-
2726
/// <summary>
2827
/// Base constructor for a BufferingChannelReader.
2928
/// </summary>
@@ -100,7 +99,7 @@ public override bool TryRead(out TOut item)
10099
/// <inheritdoc />
101100
public override ValueTask<bool> WaitToReadAsync(CancellationToken cancellationToken = default)
102101
{
103-
if (Buffer is null || Buffer.Reader.Completion.IsCompleted)
102+
if (Buffer?.Reader.Completion.IsCompleted != false)
104103
return new ValueTask<bool>(false);
105104

106105
if (cancellationToken.IsCancellationRequested)
@@ -117,7 +116,7 @@ public override ValueTask<bool> WaitToReadAsync(CancellationToken cancellationTo
117116
protected virtual async ValueTask<bool> WaitToReadAsyncCore(ValueTask<bool> bufferWait, CancellationToken cancellationToken)
118117
{
119118
ChannelReader<TIn>? source = Source;
120-
if (source is null || bufferWait.IsCompleted)
119+
if (source is null || bufferWait.IsCompleted)
121120
return await bufferWait.ConfigureAwait(false);
122121

123122
using var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);

0 commit comments

Comments
 (0)