Skip to content

Commit bab752b

Browse files
Assert ConfigureAwait and cleanup usings.
1 parent eded126 commit bab752b

File tree

10 files changed

+50
-93
lines changed

10 files changed

+50
-93
lines changed

Open.ChannelExtensions.ComparisonTests/Program.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ static async Task Main()
1717

1818
{
1919
Console.WriteLine("Standard DataFlow operation test...");
20-
var block = new ActionBlock<int>(async i => await Delay(i));
20+
var block = new ActionBlock<int>(async i => await Delay(i).ConfigureAwait(false));
2121
var sw = Stopwatch.StartNew();
2222
foreach (int i in Enumerable.Range(0, repeat))
2323
block.Post(i);
2424
block.Complete();
25-
await block.Completion;
25+
await block.Completion.ConfigureAwait(false);
2626
sw.Stop();
2727
Console.WriteLine(sw.Elapsed);
2828
Console.WriteLine();
2929
}
3030

31-
await BasicTests.ReadAll(testSize);
32-
await BasicTests.ReadAllAsync(testSize);
33-
await BasicTests.BatchThenJoin(testSize, 5001);
34-
await BasicTests.BatchJoin(testSize, 50);
31+
await BasicTests.ReadAll(testSize).ConfigureAwait(false);
32+
await BasicTests.ReadAllAsync(testSize).ConfigureAwait(false);
33+
await BasicTests.BatchThenJoin(testSize, 5001).ConfigureAwait(false);
34+
await BasicTests.BatchJoin(testSize, 50).ConfigureAwait(false);
3535

3636
{
3737
Console.WriteLine("Standard Channel filter test...");
@@ -43,7 +43,7 @@ static async Task Main()
4343
long total = await source
4444
.ToChannelAsync(singleReader: true)
4545
.Filter(i => i % 2 == 0)
46-
.ReadAll(Dummy);
46+
.ReadAll(Dummy).ConfigureAwait(false);
4747
sw.Stop();
4848

4949
Debug.Assert(total == repeat / 2);
@@ -54,11 +54,11 @@ static async Task Main()
5454
{
5555
Console.WriteLine("Concurrent DataFlow operation test...");
5656
var sw = Stopwatch.StartNew();
57-
var block = new ActionBlock<int>(async i => await Delay(i), new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = concurrency });
57+
var block = new ActionBlock<int>(async i => await Delay(i).ConfigureAwait(false), new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = concurrency });
5858
foreach (int i in Enumerable.Range(0, repeat))
5959
block.Post(i);
6060
block.Complete();
61-
await block.Completion;
61+
await block.Completion.ConfigureAwait(false);
6262
sw.Stop();
6363
Console.WriteLine(sw.Elapsed);
6464
Console.WriteLine();
@@ -71,7 +71,7 @@ await Enumerable
7171
.Repeat((Func<int, ValueTask<int>>)Delay, repeat)
7272
.Select((t, i) => t(i))
7373
.ToChannelAsync(singleReader: false, maxConcurrency: concurrency)
74-
.ReadAllConcurrently(4, Dummy);
74+
.ReadAllConcurrently(4, Dummy).ConfigureAwait(false);
7575
sw.Stop();
7676
Console.WriteLine(sw.Elapsed);
7777
Console.WriteLine();
@@ -85,7 +85,7 @@ await Enumerable
8585
.Select((t, i) => t(i))
8686
.ToChannelAsync()
8787
.Pipe(i => i * 2)
88-
.ReadAll(Dummy);
88+
.ReadAll(Dummy).ConfigureAwait(false);
8989
sw.Stop();
9090
Debug.Assert(total == repeat);
9191
Console.WriteLine(sw.Elapsed);
@@ -100,7 +100,7 @@ await Enumerable
100100
.Select((t, i) => t(i))
101101
.ToChannelAsync()
102102
.Transform(i => i * 2L)
103-
.ReadAll(Dummy);
103+
.ReadAll(Dummy).ConfigureAwait(false);
104104
sw.Stop();
105105
Console.WriteLine(sw.Elapsed);
106106
Console.WriteLine();
@@ -134,7 +134,7 @@ static void Dummy(long i)
134134

135135
static async ValueTask<int> Delay(int i)
136136
{
137-
await Task.Delay(100);
137+
await Task.Delay(100).ConfigureAwait(false);
138138
return i;
139139
}
140140
}

Open.ChannelExtensions.Tests/AssumptionTests.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading;
6-
using System.Threading.Channels;
7-
using System.Threading.Tasks;
8-
using Xunit;
9-
10-
namespace Open.ChannelExtensions.Tests;
1+
namespace Open.ChannelExtensions.Tests;
112

123
public static class AssumptionTests
134
{

Open.ChannelExtensions.Tests/BasicTests.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
using System;
2-
using System.Collections.Concurrent;
3-
using System.Collections.Generic;
4-
using System.Diagnostics;
5-
using System.Linq;
6-
using System.Threading;
7-
using System.Threading.Channels;
8-
using System.Threading.Tasks;
9-
using Xunit;
10-
111
namespace Open.ChannelExtensions.Tests;
122

133
public static class BasicTests
@@ -18,8 +8,8 @@ public static class BasicTests
188
[Theory]
199
[InlineData(testSize1)]
2010
[InlineData(testSize2)]
21-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2012:Use ValueTasks correctly", Justification = "Testing only.")]
22-
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "<Pending>")]
11+
[SuppressMessage("Reliability", "CA2012:Use ValueTasks correctly", Justification = "Testing only.")]
12+
[SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "<Pending>")]
2313
public static async Task DeferredWriteRead(int testSize)
2414
{
2515
IEnumerable<int> range = Enumerable.Range(0, testSize);
@@ -113,7 +103,7 @@ public static async Task ReadAllConcurrentlyAsEnumerablesAsync()
113103
int total = 0;
114104
var read = channel.Reader.ReadAllConcurrentlyAsEnumerablesAsync(3, async e =>
115105
{
116-
foreach(var i in e)
106+
foreach (var i in e)
117107
{
118108
await Task.Delay(1);
119109
Interlocked.Increment(ref total);
@@ -142,7 +132,7 @@ public static async Task ReadAllConcurrentlyAsEnumerables()
142132
{
143133
foreach (var i in e)
144134
{
145-
for(var n = 0; n < 2000000; n++)
135+
for (var n = 0; n < 2000000; n++)
146136
{
147137
// loop delay
148138
}

Open.ChannelExtensions.Tests/BatchTests.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Linq;
5-
using System.Runtime.CompilerServices;
6-
using System.Threading;
7-
using System.Threading.Channels;
8-
using System.Threading.Tasks;
9-
using Xunit;
1+
using System.Runtime.CompilerServices;
102

113
namespace Open.ChannelExtensions.Tests;
124

@@ -232,7 +224,7 @@ public static async Task TimeoutTest1()
232224
var reader = c.Reader.Batch(10).WithTimeout(500);
233225
_ = Task.Run(async () =>
234226
{
235-
for(var i = 0;i<15;i++)
227+
for (var i = 0; i < 15; i++)
236228
{
237229
c.Writer.TryWrite(i);
238230
}
@@ -267,7 +259,7 @@ public static async Task TimeoutTest1()
267259
}));
268260
}
269261

270-
#if NET5_0_OR_GREATER
262+
#if NET5_0_OR_GREATER
271263
[Fact]
272264
public static async Task BatchReadBehavior()
273265
{
@@ -276,7 +268,7 @@ public static async Task BatchReadBehavior()
276268

277269
var queue = new Queue<int>(Enumerable.Range(0, 100));
278270
int e;
279-
while(queue.TryDequeue(out e) && c.Writer.TryWrite(e))
271+
while (queue.TryDequeue(out e) && c.Writer.TryWrite(e))
280272
await Task.Yield();
281273

282274
Assert.True(69 <= queue.Count);
@@ -345,7 +337,8 @@ async ValueTask Dequeue()
345337
public static async Task ReadBatchWithTimeoutEnumerableBakedIn()
346338
{
347339
var c = Channel.CreateUnbounded<int>(new UnboundedChannelOptions { SingleReader = false, SingleWriter = false });
348-
_ = Task.Run(async () => {
340+
_ = Task.Run(async () =>
341+
{
349342
//await Task.Delay(1000);
350343
c.Writer.TryWrite(1);
351344
c.Writer.TryWrite(2);

Open.ChannelExtensions.Tests/CancellationTests.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Linq;
3-
using System.Threading;
4-
using System.Threading.Tasks;
5-
using Xunit;
6-
7-
namespace Open.ChannelExtensions.Tests;
1+
namespace Open.ChannelExtensions.Tests;
82

93
public static class CancellationTests
104
{

Open.ChannelExtensions.Tests/ExceptionTests.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
using System;
2-
using System.Linq;
3-
using System.Threading;
4-
using System.Threading.Channels;
5-
using System.Threading.Tasks;
6-
using Xunit;
7-
8-
namespace Open.ChannelExtensions.Tests;
1+
namespace Open.ChannelExtensions.Tests;
92

103
public static class ExceptionTests
114
{
12-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1194:Implement exception constructors.")]
5+
[SuppressMessage("Roslynator", "RCS1194:Implement exception constructors.")]
136
class TestException : Exception { }
147

158
[Fact]
@@ -57,7 +50,7 @@ await range
5750

5851
return i.ToString();
5952
})
60-
.ReadAll(_ => {});
53+
.ReadAll(_ => { });
6154
}
6255
catch (Exception ex)
6356
{
@@ -103,7 +96,7 @@ await range
10396
}
10497

10598
[Fact]
106-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2012:Use ValueTasks correctly", Justification = "Needs to happen synchronously")]
99+
[SuppressMessage("Reliability", "CA2012:Use ValueTasks correctly", Justification = "Needs to happen synchronously")]
107100
public static void ChannelClosed()
108101
{
109102
var channel = Channel.CreateBounded<int>(new BoundedChannelOptions(1000)
@@ -127,7 +120,7 @@ public static async Task WriteAllThrowIfClosed()
127120
var reader = channel.Source(Enumerable.Range(0, 10_000));
128121
await reader.ReadAll(_ => { });
129122

130-
await Assert.ThrowsAsync<ChannelClosedException>(async ()=>
123+
await Assert.ThrowsAsync<ChannelClosedException>(async () =>
131124
{
132125
channel.Source(Enumerable.Range(0, 10_000), out var completion);
133126
await completion;

Open.ChannelExtensions.Tests/PipelineExceptionTests.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Threading.Tasks;
4-
using System.Threading.Channels;
5-
using Xunit;
6-
7-
namespace Open.ChannelExtensions.Tests;
1+
namespace Open.ChannelExtensions.Tests;
82
public static class PipelineExceptionTests
93
{
104
const int BatchSize = 20;
@@ -32,7 +26,7 @@ public static async Task Regular(int elementToThrow)
3226
.PipeAsync(1, evt => new ValueTask<int>(evt))
3327
.ReadAll(_ => { });
3428

35-
if(elementToThrow == Elements)
29+
if (elementToThrow == Elements)
3630
channel.Writer.Complete(new Exception());
3731
else
3832
channel.Writer.Complete();
@@ -63,7 +57,7 @@ public static async Task Batched(int elementToThrow)
6357
.PipeAsync(1, evt => new ValueTask<List<int>>(evt))
6458
.ReadAll(_ => { });
6559

66-
if(elementToThrow == Elements)
60+
if (elementToThrow == Elements)
6761
channel.Writer.Complete(new Exception());
6862
else
6963
channel.Writer.Complete();

Open.ChannelExtensions.Tests/SourceTests.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Linq;
3-
using System.Threading;
4-
using System.Threading.Tasks;
5-
using Xunit;
6-
7-
namespace Open.ChannelExtensions.Tests;
1+
namespace Open.ChannelExtensions.Tests;
82
public static class SourceTests
93
{
104
[Fact]
@@ -22,7 +16,7 @@ public static async Task ToChannelCancelledAfterwriteStarts()
2216
{ }
2317

2418
await reader.ReadAll(_ => { });
25-
await Assert.ThrowsAsync<TaskCanceledException>(()=>reader.Completion);
19+
await Assert.ThrowsAsync<TaskCanceledException>(() => reader.Completion);
2620
}
2721

2822
[Fact]

Open.ChannelExtensions.Tests/SpecialTests.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Concurrent;
3-
using System.Collections.Generic;
4-
using System.Threading;
5-
using System.Threading.Channels;
6-
using System.Threading.Tasks;
7-
using Xunit;
1+
using System.Collections.Concurrent;
82

93
namespace Open.ChannelExtensions.Tests;
104

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
global using System;
2+
global using System.Collections.Generic;
3+
global using System.Diagnostics;
4+
global using System.Diagnostics.CodeAnalysis;
5+
global using System.Linq;
6+
global using System.Threading;
7+
global using System.Threading.Channels;
8+
global using System.Threading.Tasks;
9+
global using Xunit;
10+
11+
[assembly: SuppressMessage(
12+
"ConfigureAwait",
13+
"ConfigureAwaitEnforcer:ConfigureAwaitEnforcer",
14+
Justification = "Should not be used in test projects.")]

0 commit comments

Comments
 (0)