-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e83a5b
commit 042dfc9
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
tests/MPMCQueue.NET.Tests/FieldReports/Issue2_TryDequeueTrueButGetNull.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters