Skip to content
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
36 changes: 36 additions & 0 deletions .github/workflows/infer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Infer

on:
push:
paths-ignore: [ '**.md' ]
branches: [ main ]
pull_request:
paths-ignore: [ '**.md' ]
branches: [ main ]

jobs:
infer:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore

- name: Run Infer#
uses: microsoft/infersharpaction@v1.4
id: runinfersharp
with:
binary-path: BitFaster.Caching/bin

- name: Upload SARIF output to GitHub Security Center
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: infer-out/report.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,21 @@ public void WhenNoInnerEventsNoOuterEvents()

cache.Events.HasValue.Should().BeFalse();
}

// Infer identified AddOrUpdate and TryUpdate as resource leaks. This test verifies correct disposal.
[Fact]
public void WhenEntryIsUpdatedOldEntryIsDisposed()
{
var disposable1 = new Disposable();
var disposable2 = new Disposable();

this.cache.AddOrUpdate(1, disposable1);

this.cache.TryUpdate(1, disposable2).Should().BeTrue();
disposable1.IsDisposed.Should().BeTrue();

this.cache.TryUpdate(1, new Disposable()).Should().BeTrue();
disposable2.IsDisposed.Should().BeTrue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,21 @@ public void WhenNoInnerEventsNoOuterEvents()

cache.Events.HasValue.Should().BeFalse();
}

// Infer identified AddOrUpdate and TryUpdate as resource leaks. This test verifies correct disposal.
[Fact]
public void WhenEntryIsUpdatedOldEntryIsDisposed()
{
var disposable1 = new Disposable();
var disposable2 = new Disposable();

this.cache.AddOrUpdate(1, disposable1);

this.cache.TryUpdate(1, disposable2).Should().BeTrue();
disposable1.IsDisposed.Should().BeTrue();

this.cache.TryUpdate(1, new Disposable()).Should().BeTrue();
disposable2.IsDisposed.Should().BeTrue();
}
}
}
10 changes: 10 additions & 0 deletions BitFaster.Caching.UnitTests/ScopedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ namespace BitFaster.Caching.UnitTests
{
public class ScopedTests
{
[Fact]
public void WhenScopeIsCreatedThenScopeDisposedValueIsDisposed()
{
var disposable = new Disposable();
var scope = new Scoped<Disposable>(disposable);

scope.Dispose();
disposable.IsDisposed.Should().BeTrue();
}

[Fact]
public void WhenScopeIsCreatedThenScopeDisposedLifetimeDisposesValue()
{
Expand Down