Skip to content

Commit

Permalink
dict
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Peck committed Oct 15, 2023
1 parent abe55ab commit 2d5692d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion BitFaster.Caching.UnitTests/Atomic/AtomicFactorySoakTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Linq;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading.Tasks;
using BitFaster.Caching.Atomic;
using BitFaster.Caching.Lru;
using FluentAssertions;
using Xunit;
Expand Down Expand Up @@ -31,5 +33,23 @@ await Threaded.Run(4, (r) =>
cache.Metrics.Value.Evicted.Should().Be(0);

Check failure on line 33 in BitFaster.Caching.UnitTests/Atomic/AtomicFactorySoakTests.cs

View workflow job for this annotation

GitHub Actions / test results (mac net6.0)

BitFaster.Caching.UnitTests.Atomic.AtomicFactorySoakTests ► WhenGetOrAddIsConcurrentValuesCreatedAtomically

Failed test found in: BitFaster.Caching.UnitTests/TestResults/results.trx Error: Expected cache.Metrics.Value.Evicted to be 0L, but found 16L (difference of 16).
Raw output
Expected cache.Metrics.Value.Evicted to be 0L, but found 16L (difference of 16).
   at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
   at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
   at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
   at FluentAssertions.Numeric.NumericAssertions`2.Be(T expected, String because, Object[] becauseArgs)
   at BitFaster.Caching.UnitTests.Atomic.AtomicFactorySoakTests.WhenGetOrAddIsConcurrentValuesCreatedAtomically() in /Users/runner/work/BitFaster.Caching/BitFaster.Caching/BitFaster.Caching.UnitTests/Atomic/AtomicFactorySoakTests.cs:line 33
--- End of stack trace from previous location ---
counters.Sum(x => x).Should().Be(1024);
}

[Fact]
public async Task WhenGetOrAddIsConcurrentValuesCreatedAtomically2()
{
var dictionary = new ConcurrentDictionary<int, AtomicFactory<int, int>>(4, 1024);

var counters = new int[4];

await Threaded.Run(4, (r) =>
{
for (int i = 0; i < 1024; i++)
{
dictionary.GetOrAdd(i, k => { counters[r]++; return k; });
}
});

counters.Sum(x => x).Should().Be(1024);
}
}
}

0 comments on commit 2d5692d

Please sign in to comment.