public void TestConcurrency() { var q = new PunisherQueue <string>(); int n = 0; _ = Task.Run(() => { for (int i = 0; i < 10000; ++i) { q.Enqueue(Path.GetRandomFileName()); ++n; Thread.Yield(); } }); for (int i = 0; i < 10000; ++i) { if (!q.TryDequeue(out _)) { --i; } --n; Thread.Yield(); } if (n == 0) { Assert.Inconclusive(); } Assert.IsTrue(q.Count() == 0); }
public void TestTryDequeue() { var q = new PunisherQueue <string>(); Assert.IsTrue(!q.TryDequeue(out _)); q.Enqueue("a"); q.Enqueue("b"); q.Enqueue("c"); Assert.IsTrue(q.TryDequeue(out string s) && s == "a"); Assert.IsTrue(string.Join("", q) == "bc"); }