Skip to content

Commit 8c0a169

Browse files
authored
PR #636: Fix unstable tests and switch to dotcover
* test: use static random seed in tests this prevents the code coverage from varying depending on how well the random data compresses * ci: use dotcover for code coverage
1 parent 8e4d144 commit 8c0a169

File tree

4 files changed

+60
-27
lines changed

4 files changed

+60
-27
lines changed

.github/workflows/build-test.yml

+51-19
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ jobs:
2222
LIB_PROJ: src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
2323
steps:
2424
- uses: actions/checkout@v2
25-
25+
with:
26+
fetch-depth: 0
27+
2628
- name: Setup .NET Core
2729
uses: actions/setup-dotnet@v1
2830
with:
@@ -39,46 +41,76 @@ jobs:
3941
strategy:
4042
fail-fast: false
4143
matrix:
42-
os: [ubuntu, windows, macos]
44+
# Windows testing is combined with code coverage
45+
os: [ubuntu, macos]
4346
target: [netcoreapp3.1]
44-
include:
45-
- os: windows
46-
target: net46
4747
steps:
4848
- uses: actions/checkout@v2
49-
49+
with:
50+
fetch-depth: 0
51+
5052
- name: Setup .NET Core
5153
if: matrix.target == 'netcoreapp3.1'
5254
uses: actions/setup-dotnet@v1
5355
with:
5456
dotnet-version: '3.1.x'
5557

56-
# NOTE: This is the temporary fix for https://github.com/actions/virtual-environments/issues/1090
57-
- name: Cleanup before restore
58-
if: ${{ matrix.os == 'windows' }}
59-
run: dotnet clean ICSharpCode.SharpZipLib.sln && dotnet nuget locals all --clear
60-
6158
- name: Restore test dependencies
6259
run: dotnet restore
6360

6461
- name: Run tests (Debug)
6562
run: dotnet test -c debug -f ${{ matrix.target }} --no-restore
6663

6764
- name: Run tests (Release)
68-
# Only upload code coverage for windows in an attempt to fix the broken code coverage
69-
if: ${{ matrix.os == 'windows' }}
70-
run: dotnet test -c release -f ${{ matrix.target }} --no-restore --collect="XPlat Code Coverage"
71-
72-
- name: Run tests with coverage (Release)
73-
# Only upload code coverage for windows in an attempt to fix the broken code coverage
74-
if: ${{ matrix.os != 'windows' }}
7565
run: dotnet test -c release -f ${{ matrix.target }} --no-restore
7666

67+
68+
CodeCov:
69+
name: Code Coverage
70+
runs-on: windows-latest
71+
env:
72+
DOTCOVER_VER: 2021.1.2
73+
DOTCOVER_PKG: jetbrains.dotcover.commandlinetools
74+
COVER_SNAPSHOT: SharpZipLib.dcvr
75+
steps:
76+
- uses: actions/checkout@v2
77+
with:
78+
fetch-depth: 0
79+
80+
- name: Setup .NET
81+
uses: actions/setup-dotnet@v1
82+
with:
83+
dotnet-version: '3.1.x'
84+
85+
# NOTE: This is the temporary fix for https://github.com/actions/virtual-environments/issues/1090
86+
- name: Cleanup before restore
87+
run: dotnet clean ICSharpCode.SharpZipLib.sln && dotnet nuget locals all --clear
88+
89+
- name: Install codecov
90+
run: nuget install -o tools -version ${{env.DOTCOVER_VER}} ${{env.DOTCOVER_PKG}}
91+
92+
- name: Add dotcover to path
93+
run: echo "$(pwd)\tools\${{env.DOTCOVER_PKG}}.${{env.DOTCOVER_VER}}\tools" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
94+
95+
- name: Run tests with code coverage
96+
run: dotcover dotnet --output=${{env.COVER_SNAPSHOT}} --filters=-:ICSharpCode.SharpZipLib.Tests -- test -c release
97+
98+
- name: Create code coverage report
99+
run: dotcover report --source=${{env.COVER_SNAPSHOT}} --reporttype=detailedxml --output=dotcover-report.xml
100+
77101
- name: Upload coverage to Codecov
78102
uses: codecov/[email protected]
103+
with:
104+
files: dotcover-report.xml
105+
106+
- name: Upload coverage snapshot artifact
107+
uses: actions/upload-artifact@v2
108+
with:
109+
name: Code coverage snapshot
110+
path: ${{env.COVER_SNAPSHOT}}
79111

80112
Pack:
81-
needs: [Build, Test]
113+
needs: [Build, Test, CodeCov]
82114
runs-on: windows-latest
83115
env:
84116
PKG_SUFFIX: ''

test/ICSharpCode.SharpZipLib.Tests/BZip2/Bzip2Tests.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ namespace ICSharpCode.SharpZipLib.Tests.BZip2
1212
[TestFixture]
1313
public class BZip2Suite
1414
{
15+
// Use the same random seed to guarantee all the code paths are followed
16+
const int RandomSeed = 4;
17+
1518
/// <summary>
1619
/// Basic compress/decompress test BZip2
1720
/// </summary>
@@ -23,7 +26,7 @@ public void BasicRoundTrip()
2326
var outStream = new BZip2OutputStream(ms);
2427

2528
byte[] buf = new byte[10000];
26-
var rnd = new Random();
29+
var rnd = new Random(RandomSeed);
2730
rnd.NextBytes(buf);
2831

2932
outStream.Write(buf, 0, buf.Length);

test/ICSharpCode.SharpZipLib.Tests/Base/InflaterDeflaterTests.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ namespace ICSharpCode.SharpZipLib.Tests.Base
1616
[TestFixture]
1717
public class InflaterDeflaterTestSuite
1818
{
19+
// Use the same random seed to guarantee all the code paths are followed
20+
const int RandomSeed = 5;
21+
1922
private void Inflate(MemoryStream ms, byte[] original, int level, bool zlib)
2023
{
2124
byte[] buf2 = new byte[original.Length];
@@ -60,7 +63,7 @@ private MemoryStream Deflate(byte[] data, int level, bool zlib)
6063
private static byte[] GetRandomTestData(int size)
6164
{
6265
byte[] buffer = new byte[size];
63-
var rnd = new Random();
66+
var rnd = new Random(RandomSeed);
6467
rnd.NextBytes(buffer);
6568

6669
return buffer;
@@ -184,7 +187,7 @@ public async Task InflateDeflateZlibAsync([Range(0, 9)] int level)
184187
private int runLevel;
185188
private bool runZlib;
186189
private long runCount;
187-
private readonly Random runRandom = new Random(5);
190+
private readonly Random runRandom = new Random(RandomSeed);
188191

189192
private void DeflateAndInflate(byte[] buffer)
190193
{

test/ICSharpCode.SharpZipLib.Tests/ICSharpCode.SharpZipLib.Tests.csproj

-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="coverlet.collector" Version="3.0.3">
12-
<PrivateAssets>all</PrivateAssets>
13-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14-
</PackageReference>
1511
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
1612
<PackageReference Include="nunit" Version="3.13.1" />
1713
<PackageReference Include="nunit.console" Version="3.12.0" />
1814
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
19-
<PackageReference Include="OpenCover" Version="4.6.519" />
2015
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.4.0" />
2116
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
2217
</ItemGroup>

0 commit comments

Comments
 (0)