Skip to content

Commit

Permalink
Add a repro from issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrnikitin committed Jan 23, 2018
1 parent 1e83a5b commit 042dfc9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Threading.Tasks;
using Xunit;

namespace MPMCQueue.NET.Tests.FieldReports
{
public class Issue2_TryDequeueTrueButGetNull
{
static MPMCQueue queue { get; } = new MPMCQueue(2);
static void Enqueue()
{
while (true) { queue.TryEnqueue(1); }
}

static void Dequeue()
{
while (true)
{
if (queue.TryDequeue(out object t) && t == null)
{
throw new Exception("Dequeue null");
}
}
}

[Fact]
public void Test()
{
var t1 = Task.Run(() => Enqueue());
var t2 = Task.Run(() => Dequeue());
t2.Wait(TimeSpan.FromSeconds(10));
}
}
}
1 change: 1 addition & 0 deletions tests/MPMCQueue.NET.Tests/MPMCQueue.NET.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MultiThreadedTests.cs" />
<Compile Include="RandomTests.cs" />
<Compile Include="FieldReports\Issue2_TryDequeueTrueButGetNull.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down

0 comments on commit 042dfc9

Please sign in to comment.