File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed
BitFaster.Caching.UnitTests Expand file tree Collapse file tree 3 files changed +42
-0
lines changed 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