Skip to content

Commit 82d76e1

Browse files
Rethink SkipEmbeddedPpdbWithoutLocalSource and SkipPpdbWithoutLocalSource tests, are flaky on CI (#565)
Rethink SkipEmbeddedPpdbWithoutLocalSource and SkipPpdbWithoutLocalSource tests, are flaky on CI
1 parent e251d23 commit 82d76e1

File tree

9 files changed

+90
-23
lines changed

9 files changed

+90
-23
lines changed

coverlet.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.collector", "src\c
2323
EndProject
2424
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.collector.tests", "test\coverlet.collector.tests\coverlet.collector.tests.csproj", "{5ED4FA81-8F8C-4211-BA88-7573BD63262E}"
2525
EndProject
26-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "coverlet.tests.remoteexecutor", "test\coverlet.tests.remoteexecutor\coverlet.tests.remoteexecutor.csproj", "{3E0F9E47-A1D7-4DF5-841D-A633486E2475}"
26+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.tests.remoteexecutor", "test\coverlet.tests.remoteexecutor\coverlet.tests.remoteexecutor.csproj", "{3E0F9E47-A1D7-4DF5-841D-A633486E2475}"
27+
EndProject
28+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.tests.projectsample.empty", "test\coverlet.tests.projectsample.empty\coverlet.tests.projectsample.empty.csproj", "{085A3AFB-C086-4E98-86F1-1B481446EC5E}"
2729
EndProject
2830
Global
2931
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -67,6 +69,10 @@ Global
6769
{3E0F9E47-A1D7-4DF5-841D-A633486E2475}.Debug|Any CPU.Build.0 = Debug|Any CPU
6870
{3E0F9E47-A1D7-4DF5-841D-A633486E2475}.Release|Any CPU.ActiveCfg = Release|Any CPU
6971
{3E0F9E47-A1D7-4DF5-841D-A633486E2475}.Release|Any CPU.Build.0 = Release|Any CPU
72+
{085A3AFB-C086-4E98-86F1-1B481446EC5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
73+
{085A3AFB-C086-4E98-86F1-1B481446EC5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
74+
{085A3AFB-C086-4E98-86F1-1B481446EC5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
75+
{085A3AFB-C086-4E98-86F1-1B481446EC5E}.Release|Any CPU.Build.0 = Release|Any CPU
7076
EndGlobalSection
7177
GlobalSection(SolutionProperties) = preSolution
7278
HideSolutionNode = FALSE
@@ -81,6 +87,7 @@ Global
8187
{F5B2C45B-274B-43D6-9565-8B50659CFE56} = {E877EBA4-E78B-4F7D-A2D3-1E070FED04CD}
8288
{5ED4FA81-8F8C-4211-BA88-7573BD63262E} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
8389
{3E0F9E47-A1D7-4DF5-841D-A633486E2475} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
90+
{085A3AFB-C086-4E98-86F1-1B481446EC5E} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
8491
EndGlobalSection
8592
GlobalSection(ExtensibilityGlobals) = postSolution
8693
SolutionGuid = {9CA57C02-97B0-4C38-A027-EA61E8741F10}

src/coverlet.core/Helpers/FileSystem.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Coverlet.Core.Helpers
55
{
66
public class FileSystem : IFileSystem
77
{
8-
// We need to partial mock this class on tests
8+
// We need to partial mock this method on tests
99
public virtual bool Exists(string path)
1010
{
1111
return File.Exists(path);
@@ -36,7 +36,8 @@ public void Delete(string path)
3636
File.Delete(path);
3737
}
3838

39-
public Stream NewFileStream(string path, FileMode mode)
39+
// We need to partial mock this method on tests
40+
public virtual Stream NewFileStream(string path, FileMode mode)
4041
{
4142
return new FileStream(path, mode);
4243
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
coverage.*
1+
coverage.*
2+
!75d9f96508d74def860a568f426ea4a4.*

test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public void TestInstrument_ExcludedFilesHelper(string[] excludeFilterHelper, Val
342342
}
343343
}
344344

345-
[Fact(Skip = "Temporary disabled because flaky on CI, we cannot use coverlet.core.dll/pdb as test lib")]
345+
[Fact]
346346
public void SkipEmbeddedPpdbWithoutLocalSource()
347347
{
348348
string xunitDll = Directory.GetFiles(Directory.GetCurrentDirectory(), "xunit.*.dll").First();
@@ -354,32 +354,57 @@ public void SkipEmbeddedPpdbWithoutLocalSource()
354354
loggerMock.Verify(l => l.LogVerbose(It.IsAny<string>()));
355355

356356
// Default case
357-
string coverletCoreDll = Directory.GetFiles(Directory.GetCurrentDirectory(), "coverlet.core.dll").First();
358-
instrumenter = new Instrumenter(coverletCoreDll, "_coverlet_core_instrumented", Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false, loggerMock.Object, _instrumentationHelper, new FileSystem());
359-
Assert.True(_instrumentationHelper.HasPdb(coverletCoreDll, out embedded));
357+
string sample = Directory.GetFiles(Directory.GetCurrentDirectory(), "coverlet.tests.projectsample.empty.dll").First();
358+
instrumenter = new Instrumenter(sample, "_coverlet_tests_projectsample_empty", Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false, loggerMock.Object, _instrumentationHelper, new FileSystem());
359+
Assert.True(_instrumentationHelper.HasPdb(sample, out embedded));
360360
Assert.False(embedded);
361361
Assert.True(instrumenter.CanInstrument());
362362
loggerMock.VerifyNoOtherCalls();
363363
}
364364

365-
[Fact(Skip = "Temporary disabled because flaky on CI, we cannot use coverlet.core.dll/pdb as test lib")]
365+
[Fact]
366366
public void SkipPpdbWithoutLocalSource()
367367
{
368-
Mock<FileSystem> partialMockFileSystem = new Mock<FileSystem>();
369-
partialMockFileSystem.CallBase = true;
370-
partialMockFileSystem.Setup(fs => fs.Exists(It.IsAny<string>())).Returns((string path) =>
371-
{
372-
return Path.GetExtension(path) != ".cs";
373-
});
374-
InstrumentationHelper instrumentationHelper = new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), partialMockFileSystem.Object);
368+
string dllFileName = "75d9f96508d74def860a568f426ea4a4.dll";
369+
string pdbFileName = "75d9f96508d74def860a568f426ea4a4.pdb";
375370

376-
string coverletLib = Directory.GetFiles(Directory.GetCurrentDirectory(), "coverlet.core.dll").First();
377-
var loggerMock = new Mock<ILogger>();
378-
Instrumenter instrumenter = new Instrumenter(coverletLib, "_corelib_instrumented", Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false, loggerMock.Object, instrumentationHelper, partialMockFileSystem.Object);
379-
Assert.True(_instrumentationHelper.HasPdb(coverletLib, out bool embedded));
380-
Assert.False(embedded);
381-
Assert.False(instrumenter.CanInstrument());
382-
loggerMock.Verify(l => l.LogVerbose(It.IsAny<string>()));
371+
// We test only on win because sample dll/pdb were build on it
372+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
373+
{
374+
Mock<FileSystem> partialMockFileSystem = new Mock<FileSystem>();
375+
partialMockFileSystem.CallBase = true;
376+
partialMockFileSystem.Setup(fs => fs.NewFileStream(It.IsAny<string>(), It.IsAny<FileMode>())).Returns((string path, FileMode mode) =>
377+
{
378+
if (Path.GetFileName(path) == pdbFileName)
379+
{
380+
return new FileStream(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), pdbFileName), mode);
381+
}
382+
else
383+
{
384+
return new FileStream(path, mode);
385+
}
386+
});
387+
partialMockFileSystem.Setup(fs => fs.Exists(It.IsAny<string>())).Returns((string path) =>
388+
{
389+
if (Path.GetFileName(path) == pdbFileName)
390+
{
391+
return File.Exists(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), pdbFileName));
392+
}
393+
else
394+
{
395+
return File.Exists(path);
396+
}
397+
});
398+
399+
InstrumentationHelper instrumentationHelper = new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), partialMockFileSystem.Object);
400+
string sample = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), dllFileName).First();
401+
var loggerMock = new Mock<ILogger>();
402+
Instrumenter instrumenter = new Instrumenter(sample, "_75d9f96508d74def860a568f426ea4a4_instrumented", Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false, loggerMock.Object, instrumentationHelper, partialMockFileSystem.Object);
403+
Assert.True(instrumentationHelper.HasPdb(sample, out bool embedded));
404+
Assert.False(embedded);
405+
Assert.False(instrumenter.CanInstrument());
406+
loggerMock.Verify(l => l.LogVerbose(It.IsAny<string>()));
407+
}
383408
}
384409

385410
[Fact]
Binary file not shown.
Binary file not shown.

test/coverlet.core.tests/coverlet.core.tests.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020
<ItemGroup>
2121
<ProjectReference Include="$(RepoRoot)src\coverlet.core\coverlet.core.csproj" />
2222
<ProjectReference Include="$(RepoRoot)test\coverlet.tests.remoteexecutor\coverlet.tests.remoteexecutor.csproj" />
23+
<ProjectReference Include="..\coverlet.tests.projectsample.empty\coverlet.tests.projectsample.empty.csproj" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<Folder Include="TestAssets\" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<None Update="TestAssets\75d9f96508d74def860a568f426ea4a4.dll">
32+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33+
</None>
34+
<None Update="TestAssets\75d9f96508d74def860a568f426ea4a4.pdb">
35+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
36+
</None>
2337
</ItemGroup>
2438

2539
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Coverlet.Tests.ProjectSample.Empty
2+
{
3+
public class Class1
4+
{
5+
public int Method()
6+
{
7+
return 42;
8+
}
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
<IsTestProject>false</IsTestProject>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)