We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 988a07b commit 9d14dc6Copy full SHA for 9d14dc6
WebApiClientTest/Internal/ConcurrentCacheTest.cs
@@ -0,0 +1,34 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Text;
4
+using WebApiClient;
5
+using Xunit;
6
+using System.Threading;
7
+using System.Threading.Tasks;
8
+
9
+namespace WebApiClientTest.Internal
10
+{
11
+ public class ConcurrentCacheTest
12
+ {
13
+ private int count = 0;
14
15
+ [Fact]
16
+ public void GetOrAddGet()
17
18
+ var key = "WebApiClient";
19
+ var cache = new ConcurrentCache<string, int>();
20
21
+ Parallel.For(0, 1000, (i) =>
22
23
+ var value = cache.GetOrAdd(key, k =>
24
25
+ Interlocked.Increment(ref this.count);
26
+ return 1;
27
+ });
28
29
+ Assert.True(value == 1);
30
+ Assert.True(count == 1);
31
32
+ }
33
34
+}
0 commit comments