Skip to content

Commit

Permalink
Merge pull request #3908 from Ginger-Automation/BugFix/BlockingBuffer…
Browse files Browse the repository at this point in the history
…QueueTestFix

Fixed BlockingBufferQueue Unit Tests
  • Loading branch information
Maheshkale447 authored Sep 16, 2024
2 parents bdfcd86 + cbf5112 commit b219dc9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Ginger/GingerCoreNETUnitTest/Telemetry/BlockingBufferQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task Dequeue_QueueSizeLessThanBufferSizeSingleConsumer_ConsumerBloc
BlockingBufferQueue<int> queue = new(bufferSize: 2);

Task dequeueTask = Task.Run(queue.Dequeue);
await Task.Delay(TimeSpan.FromMilliseconds(50));
await TaskTryWaitAsync(dequeueTask, TimeSpan.FromSeconds(1));

Assert.IsFalse(dequeueTask.IsCompleted);
}
Expand All @@ -55,7 +55,8 @@ public async Task Dequeue_QueueSizeLessThanBufferSizeMultipleConsumer_AllConsume

Task dequeueTask1 = Task.Run(queue.Dequeue);
Task dequeueTask2 = Task.Run(queue.Dequeue);
await Task.Delay(TimeSpan.FromMilliseconds(50));
await TaskTryWaitAsync(dequeueTask1, TimeSpan.FromSeconds(1));
await TaskTryWaitAsync(dequeueTask2, TimeSpan.FromSeconds(1));

Assert.IsFalse(dequeueTask1.IsCompleted);
Assert.IsFalse(dequeueTask2.IsCompleted);
Expand All @@ -69,11 +70,20 @@ public async Task Dequeue_QueueSizeGreaterThanBufferSizeSingleConsumer_ConsumerN
Task dequeueTask = Task.Run(queue.Dequeue);
queue.Enqueue(new Random().Next());
queue.Enqueue(new Random().Next());
await Task.Delay(TimeSpan.FromMilliseconds(50));
await TaskTryWaitAsync(dequeueTask, TimeSpan.FromSeconds(1));

Assert.IsTrue(dequeueTask.IsCompleted);
}

private static async Task TaskTryWaitAsync(Task taskToWait, TimeSpan timeout)
{
try
{
await taskToWait.WaitAsync(timeout);
}
catch {}
}

#region Flaky Tests Group 1
/*Below tests are flaky because in case of some resource shortage, the task might not reach the expected status in the given time.
*It doesn't mean that the task was blocked by the queue, but instead it just didn't reach the status in time.
Expand Down

0 comments on commit b219dc9

Please sign in to comment.