@@ -131,6 +131,52 @@ await Threaded.Run(4, () => {
131131 scheduler . Dispose ( ) ;
132132 await scheduler . Completion ;
133133
134+ RunIntegrityCheck ( lfu ) ;
135+ }
136+
137+ [ Theory ]
138+ [ Repeat ( iterations ) ]
139+ public async Task WhenSoakConcurrentGetAndRemoveCacheEndsInConsistentState ( int iteration )
140+ {
141+ var scheduler = new BackgroundThreadScheduler ( ) ;
142+ var lfu = new ConcurrentLfuBuilder < int , string > ( ) . WithCapacity ( 9 ) . WithScheduler ( scheduler ) . Build ( ) as ConcurrentLfu < int , string > ;
143+
144+ await Threaded . Run ( 4 , ( ) => {
145+ for ( int i = 0 ; i < 100000 ; i ++ )
146+ {
147+ lfu . TryRemove ( i + 1 ) ;
148+ lfu . GetOrAdd ( i + 1 , i => i . ToString ( ) ) ;
149+ }
150+ } ) ;
151+
152+ this . output . WriteLine ( $ "iteration { iteration } keys={ string . Join ( " " , lfu . Keys ) } ") ;
153+
154+ scheduler . Dispose ( ) ;
155+ await scheduler . Completion ;
156+
157+ RunIntegrityCheck ( lfu ) ;
158+ }
159+
160+ [ Theory ]
161+ [ Repeat ( iterations ) ]
162+ public async Task WhenConcurrentGetAndRemoveKvpCacheEndsInConsistentState ( int iteration )
163+ {
164+ var scheduler = new BackgroundThreadScheduler ( ) ;
165+ var lfu = new ConcurrentLfuBuilder < int , string > ( ) . WithCapacity ( 9 ) . WithScheduler ( scheduler ) . Build ( ) as ConcurrentLfu < int , string > ;
166+
167+ await Threaded . Run ( 4 , ( ) => {
168+ for ( int i = 0 ; i < 100000 ; i ++ )
169+ {
170+ lfu . TryRemove ( new KeyValuePair < int , string > ( i + 1 , ( i + 1 ) . ToString ( ) ) ) ;
171+ lfu . GetOrAdd ( i + 1 , i => i . ToString ( ) ) ;
172+ }
173+ } ) ;
174+
175+ this . output . WriteLine ( $ "iteration { iteration } keys={ string . Join ( " " , lfu . Keys ) } ") ;
176+
177+ scheduler . Dispose ( ) ;
178+ await scheduler . Completion ;
179+
134180 RunIntegrityCheck ( lfu ) ;
135181 }
136182
0 commit comments