File tree Expand file tree Collapse file tree 4 files changed +78
-0
lines changed
BitFaster.Caching.UnitTests Expand file tree Collapse file tree 4 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Infer
2+
3+ on :
4+ push :
5+ paths-ignore : [ '**.md' ]
6+ branches : [ main ]
7+ pull_request :
8+ paths-ignore : [ '**.md' ]
9+ branches : [ main ]
10+
11+ jobs :
12+ infer :
13+
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - uses : actions/checkout@v3
18+ - name : Setup .NET Core
19+ uses : actions/setup-dotnet@v2
20+ with :
21+ dotnet-version : 6.0.x
22+ - name : Install dependencies
23+ run : dotnet restore
24+ - name : Build
25+ run : dotnet build --configuration Release --no-restore
26+
27+ - name : Run Infer#
28+ uses : microsoft/infersharpaction@v1.4
29+ id : runinfersharp
30+ with :
31+ binary-path : BitFaster.Caching/bin
32+
33+ - name : Upload SARIF output to GitHub Security Center
34+ uses : github/codeql-action/upload-sarif@v2
35+ with :
36+ sarif_file : infer-out/report.sarif
Original file line number Diff line number Diff line change @@ -67,5 +67,21 @@ public void WhenNoInnerEventsNoOuterEvents()
6767
6868 cache . Events . HasValue . Should ( ) . BeFalse ( ) ;
6969 }
70+
71+ // Infer identified AddOrUpdate and TryUpdate as resource leaks. This test verifies correct disposal.
72+ [ Fact ]
73+ public void WhenEntryIsUpdatedOldEntryIsDisposed ( )
74+ {
75+ var disposable1 = new Disposable ( ) ;
76+ var disposable2 = new Disposable ( ) ;
77+
78+ this . cache . AddOrUpdate ( 1 , disposable1 ) ;
79+
80+ this . cache . TryUpdate ( 1 , disposable2 ) . Should ( ) . BeTrue ( ) ;
81+ disposable1 . IsDisposed . Should ( ) . BeTrue ( ) ;
82+
83+ this . cache . TryUpdate ( 1 , new Disposable ( ) ) . Should ( ) . BeTrue ( ) ;
84+ disposable2 . IsDisposed . Should ( ) . BeTrue ( ) ;
85+ }
7086 }
7187}
Original file line number Diff line number Diff line change @@ -67,5 +67,21 @@ public void WhenNoInnerEventsNoOuterEvents()
6767
6868 cache . Events . HasValue . Should ( ) . BeFalse ( ) ;
6969 }
70+
71+ // Infer identified AddOrUpdate and TryUpdate as resource leaks. This test verifies correct disposal.
72+ [ Fact ]
73+ public void WhenEntryIsUpdatedOldEntryIsDisposed ( )
74+ {
75+ var disposable1 = new Disposable ( ) ;
76+ var disposable2 = new Disposable ( ) ;
77+
78+ this . cache . AddOrUpdate ( 1 , disposable1 ) ;
79+
80+ this . cache . TryUpdate ( 1 , disposable2 ) . Should ( ) . BeTrue ( ) ;
81+ disposable1 . IsDisposed . Should ( ) . BeTrue ( ) ;
82+
83+ this . cache . TryUpdate ( 1 , new Disposable ( ) ) . Should ( ) . BeTrue ( ) ;
84+ disposable2 . IsDisposed . Should ( ) . BeTrue ( ) ;
85+ }
7086 }
7187}
Original file line number Diff line number Diff line change @@ -9,6 +9,16 @@ namespace BitFaster.Caching.UnitTests
99{
1010 public class ScopedTests
1111 {
12+ [ Fact ]
13+ public void WhenScopeIsCreatedThenScopeDisposedValueIsDisposed ( )
14+ {
15+ var disposable = new Disposable ( ) ;
16+ var scope = new Scoped < Disposable > ( disposable ) ;
17+
18+ scope . Dispose ( ) ;
19+ disposable . IsDisposed . Should ( ) . BeTrue ( ) ;
20+ }
21+
1222 [ Fact ]
1323 public void WhenScopeIsCreatedThenScopeDisposedLifetimeDisposesValue ( )
1424 {
You can’t perform that action at this time.
0 commit comments