Skip to content

Commit

Permalink
log cpu count
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Peck committed Oct 14, 2023
1 parent 150d49f commit 64e36fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
21 changes: 14 additions & 7 deletions BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferTests.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BitFaster.Caching.Buffers;
using FluentAssertions;
using Xunit;

using Xunit.Abstractions;

namespace BitFaster.Caching.UnitTests.Buffers
{
public class MpscBoundedBufferTests
{
private readonly ITestOutputHelper testOutputHelper;
private static readonly TimeSpan Timeout = TimeSpan.FromSeconds(30);
private readonly MpscBoundedBuffer<string> buffer = new MpscBoundedBuffer<string>(10);
private readonly MpscBoundedBuffer<string> buffer = new MpscBoundedBuffer<string>(10);

public MpscBoundedBufferTests(ITestOutputHelper testOutputHelper)
{
this.testOutputHelper = testOutputHelper;
}

[Fact]
public void WhenSizeIsLessThan1CtorThrows()
Expand Down Expand Up @@ -177,6 +180,8 @@ await Threaded.Run(4, () =>
[Fact]
public async Task WhileBufferIsFilledItemsCanBeTaken()
{
this.testOutputHelper.WriteLine($"ProcessorCount={Environment.ProcessorCount}.");

var buffer = new MpscBoundedBuffer<string>(1024);

var fill = Threaded.Run(4, () =>
Expand Down Expand Up @@ -219,13 +224,15 @@ public async Task WhileBufferIsFilledItemsCanBeTaken()
}
});

await fill.TimeoutAfter(Timeout, $"fill timed out, ProcessorCount={Environment.ProcessorCount}.");
await fill.TimeoutAfter(Timeout, $"fill timed out");
await take.TimeoutAfter(Timeout, "take timed out");
}

[Fact]
public async Task WhileBufferIsFilledBufferCanBeDrained()
{
this.testOutputHelper.WriteLine($"ProcessorCount={Environment.ProcessorCount}.");

var buffer = new MpscBoundedBuffer<string>(1024);

var fill = Threaded.Run(4, () =>
Expand Down
3 changes: 1 addition & 2 deletions BitFaster.Caching/Buffers/MpscBoundedBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using BitFaster.Caching.Lfu;

namespace BitFaster.Caching.Buffers
{
Expand Down Expand Up @@ -97,7 +96,7 @@ public BufferStatus TryAdd(T item)

if (Interlocked.CompareExchange(ref this.headAndTail.Tail, tail + 1, tail) == tail)
{
int index = (int)(tail & mask);
int index = tail & mask;
Volatile.Write(ref buffer[index], item);

return BufferStatus.Success;
Expand Down

0 comments on commit 64e36fb

Please sign in to comment.