Skip to content

Commit e15e653

Browse files
Fix pdb file locking during instrumentation (#656)
Fix pdb file locking during instrumentation
1 parent 45d8d4e commit e15e653

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

Documentation/Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
-Fix ConfigureAwait state machine generated branches [#634](https://github.com/tonerdo/coverlet/pull/634)
2020
-Fix coverage overwritten if the project has multiple target frameworks [#636](https://github.com/tonerdo/coverlet/issues/177)
2121
-Fix cobertura Jenkins reporter + source link support [#614](https://github.com/tonerdo/coverlet/pull/614) by https://github.com/daveMueller
22+
-Fix pdb file locking during instrumentation [#656](https://github.com/tonerdo/coverlet/pull/656)
23+
2224

2325
### Improvements
2426

src/coverlet.core/Helpers/FileSystem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public string ReadAllText(string path)
2121
return File.ReadAllText(path);
2222
}
2323

24-
public Stream OpenRead(string path)
24+
// We need to partial mock this method on tests
25+
public virtual Stream OpenRead(string path)
2526
{
2627
return File.OpenRead(path);
2728
}

src/coverlet.core/Helpers/InstrumentationHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public bool PortablePdbHasLocalSource(string module, out string firstNotFoundDoc
144144
if (entry.Type == DebugDirectoryEntryType.CodeView)
145145
{
146146
var codeViewData = peReader.ReadCodeViewDebugDirectoryData(entry);
147-
using Stream pdbStream = _fileSystem.NewFileStream(codeViewData.Path, FileMode.Open);
147+
using Stream pdbStream = _fileSystem.OpenRead(codeViewData.Path);
148148
using MetadataReaderProvider metadataReaderProvider = MetadataReaderProvider.FromPortablePdbStream(pdbStream);
149149
MetadataReader metadataReader = null;
150150
try

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,15 @@ public void SkipPpdbWithoutLocalSource()
374374
{
375375
Mock<FileSystem> partialMockFileSystem = new Mock<FileSystem>();
376376
partialMockFileSystem.CallBase = true;
377-
partialMockFileSystem.Setup(fs => fs.NewFileStream(It.IsAny<string>(), It.IsAny<FileMode>())).Returns((string path, FileMode mode) =>
377+
partialMockFileSystem.Setup(fs => fs.OpenRead(It.IsAny<string>())).Returns((string path) =>
378378
{
379379
if (Path.GetFileName(path) == pdbFileName)
380380
{
381-
return new FileStream(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), pdbFileName), mode);
381+
return File.OpenRead(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), pdbFileName));
382382
}
383383
else
384384
{
385-
return new FileStream(path, mode);
385+
return File.OpenRead(path);
386386
}
387387
});
388388
partialMockFileSystem.Setup(fs => fs.Exists(It.IsAny<string>())).Returns((string path) =>

0 commit comments

Comments
 (0)