Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unstable tests and switch to dotcover #636

Merged
merged 2 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 51 additions & 19 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
LIB_PROJ: src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
steps:
- uses: actions/checkout@v2

with:
fetch-depth: 0

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
Expand All @@ -39,46 +41,76 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu, windows, macos]
# Windows testing is combined with code coverage
os: [ubuntu, macos]
target: [netcoreapp3.1]
include:
- os: windows
target: net46
steps:
- uses: actions/checkout@v2

with:
fetch-depth: 0

- name: Setup .NET Core
if: matrix.target == 'netcoreapp3.1'
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'

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

- name: Restore test dependencies
run: dotnet restore

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

- name: Run tests (Release)
# Only upload code coverage for windows in an attempt to fix the broken code coverage
if: ${{ matrix.os == 'windows' }}
run: dotnet test -c release -f ${{ matrix.target }} --no-restore --collect="XPlat Code Coverage"

- name: Run tests with coverage (Release)
# Only upload code coverage for windows in an attempt to fix the broken code coverage
if: ${{ matrix.os != 'windows' }}
run: dotnet test -c release -f ${{ matrix.target }} --no-restore


CodeCov:
name: Code Coverage
runs-on: windows-latest
env:
DOTCOVER_VER: 2021.1.2
DOTCOVER_PKG: jetbrains.dotcover.commandlinetools
COVER_SNAPSHOT: SharpZipLib.dcvr
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'

# NOTE: This is the temporary fix for https://github.com/actions/virtual-environments/issues/1090
- name: Cleanup before restore
run: dotnet clean ICSharpCode.SharpZipLib.sln && dotnet nuget locals all --clear

- name: Install codecov
run: nuget install -o tools -version ${{env.DOTCOVER_VER}} ${{env.DOTCOVER_PKG}}

- name: Add dotcover to path
run: echo "$(pwd)\tools\${{env.DOTCOVER_PKG}}.${{env.DOTCOVER_VER}}\tools" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- name: Run tests with code coverage
run: dotcover dotnet --output=${{env.COVER_SNAPSHOT}} --filters=-:ICSharpCode.SharpZipLib.Tests -- test -c release

- name: Create code coverage report
run: dotcover report --source=${{env.COVER_SNAPSHOT}} --reporttype=detailedxml --output=dotcover-report.xml

- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
files: dotcover-report.xml

- name: Upload coverage snapshot artifact
uses: actions/upload-artifact@v2
with:
name: Code coverage snapshot
path: ${{env.COVER_SNAPSHOT}}

Pack:
needs: [Build, Test]
needs: [Build, Test, CodeCov]
runs-on: windows-latest
env:
PKG_SUFFIX: ''
Expand Down
5 changes: 4 additions & 1 deletion test/ICSharpCode.SharpZipLib.Tests/BZip2/Bzip2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace ICSharpCode.SharpZipLib.Tests.BZip2
[TestFixture]
public class BZip2Suite
{
// Use the same random seed to guarantee all the code paths are followed
const int RandomSeed = 4;

/// <summary>
/// Basic compress/decompress test BZip2
/// </summary>
Expand All @@ -23,7 +26,7 @@ public void BasicRoundTrip()
var outStream = new BZip2OutputStream(ms);

byte[] buf = new byte[10000];
var rnd = new Random();
var rnd = new Random(RandomSeed);
rnd.NextBytes(buf);

outStream.Write(buf, 0, buf.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace ICSharpCode.SharpZipLib.Tests.Base
[TestFixture]
public class InflaterDeflaterTestSuite
{
// Use the same random seed to guarantee all the code paths are followed
const int RandomSeed = 5;

private void Inflate(MemoryStream ms, byte[] original, int level, bool zlib)
{
byte[] buf2 = new byte[original.Length];
Expand Down Expand Up @@ -60,7 +63,7 @@ private MemoryStream Deflate(byte[] data, int level, bool zlib)
private static byte[] GetRandomTestData(int size)
{
byte[] buffer = new byte[size];
var rnd = new Random();
var rnd = new Random(RandomSeed);
rnd.NextBytes(buffer);

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

private void DeflateAndInflate(byte[] buffer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="nunit" Version="3.13.1" />
<PackageReference Include="nunit.console" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="OpenCover" Version="4.6.519" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.4.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
Expand Down