Skip to content

Commit 01e8e76

Browse files
Implemented NET472 tests to ensure parity.
1 parent 7f314be commit 01e8e76

4 files changed

Lines changed: 50 additions & 14 deletions

File tree

Open.ChannelExtensions.Tests/BasicTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.Linq;
6+
using System.Threading;
57
using System.Threading.Channels;
68
using System.Threading.Tasks;
79
using Xunit;
@@ -17,6 +19,7 @@ public static class BasicTests
1719
[InlineData(testSize1)]
1820
[InlineData(testSize2)]
1921
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2012:Use ValueTasks correctly", Justification = "Testing only.")]
22+
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "<Pending>")]
2023
public static async Task DeferredWriteRead(int testSize)
2124
{
2225
IEnumerable<int> range = Enumerable.Range(0, testSize);
@@ -269,6 +272,7 @@ public static async Task BatchJoin(int testSize, int batchSize)
269272
Assert.True(result.SequenceEqual(range));
270273
}
271274

275+
#if NET5_0_OR_GREATER
272276
[Theory]
273277
[InlineData(11)]
274278
[InlineData(51)]
@@ -302,6 +306,7 @@ async IAsyncEnumerable<int> Samples()
302306
}
303307
}
304308
}
309+
#endif
305310

306311
[Theory]
307312
[InlineData(testSize1)]
@@ -326,5 +331,28 @@ public static async Task Filter(int testSize)
326331
Assert.True(result.SequenceEqual(range.Where(i => i % 2 == 1)));
327332
}
328333

334+
[Fact]
335+
public static void PossibleSourceLoadingIssue()
336+
{
337+
int count_ = 0;
338+
339+
var queue = new BlockingCollection<int>();
340+
var processingTask = StartProcessingTask2(queue.GetConsumingEnumerable());
341+
342+
for (var i = 0; i < 100000000; i++)
343+
queue.Add(i);
329344

345+
queue.CompleteAdding();
346+
347+
processingTask.Wait();
348+
349+
Task StartProcessingTask2(IEnumerable<int> source)
350+
=> Channel.CreateUnbounded<int>()
351+
.Source(source, true)
352+
.ReadAll(IncrementCount2)
353+
.AsTask();
354+
355+
void IncrementCount2(int c)
356+
=> Interlocked.Increment(ref count_);
357+
}
330358
}

Open.ChannelExtensions.Tests/BatchTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public static async Task TimeoutTest1()
273273
}
274274

275275

276-
276+
#if NET5_0_OR_GREATER
277277
[Fact]
278278
public static async Task BatchReadBehavior()
279279
{
@@ -347,7 +347,6 @@ async ValueTask Dequeue()
347347
}
348348
}
349349

350-
351350
[Fact]
352351
public static async Task ReadBatchWithTimeoutEnumerableBakedIn()
353352
{
@@ -393,6 +392,7 @@ public static async Task ReadBatchWithTimeoutEnumerableBakedIn()
393392
Assert.Equal(3, i);
394393
await c.Reader.Completion; // Propagate possible failure
395394
}
395+
396396
public static async IAsyncEnumerable<IList<T>> ReadBatchEnumerableAsyncBakedIn<T>(
397397
this ChannelReader<T> channelReader,
398398
int batchSize,
@@ -421,6 +421,6 @@ public static async IAsyncEnumerable<IList<T>> ReadBatchEnumerableAsyncBakedIn<T
421421
if (item?.Count > 0) yield return item;
422422
}
423423
}
424-
424+
#endif
425425
}
426426

Open.ChannelExtensions.Tests/Open.ChannelExtensions.Tests.csproj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
6-
<LangVersion>latest</LangVersion>
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>net472; net5.0;</TargetFrameworks>
6+
<LangVersion>latest</LangVersion>
77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
99

10-
<ItemGroup>
11-
<ProjectReference Include="..\Open.ChannelExtensions\Open.ChannelExtensions.csproj" />
12-
</ItemGroup>
10+
<ItemGroup>
11+
<ProjectReference Include="..\Open.ChannelExtensions\Open.ChannelExtensions.csproj" />
12+
</ItemGroup>
1313

1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
1616
<PackageReference Include="xunit" Version="2.4.1" />
1717
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
18-
<PrivateAssets>all</PrivateAssets>
19-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
</PackageReference>
2121
<PackageReference Include="coverlet.collector" Version="3.0.3">
22-
<PrivateAssets>all</PrivateAssets>
23-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
<PrivateAssets>all</PrivateAssets>
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
</PackageReference>
2525
</ItemGroup>
2626

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Open.ChannelExtensions.Tests;
2+
3+
internal class Program
4+
{
5+
#if NET472
6+
public static void Main(string[] args) {}
7+
#endif
8+
}

0 commit comments

Comments
 (0)