From 92158e4ab0ee0d1fc5e45fe3c210cf4cc70b02ba Mon Sep 17 00:00:00 2001 From: Karol Zadora-Przylecki Date: Wed, 24 Jan 2018 13:23:57 -0800 Subject: [PATCH] Improve DataFlow test reliability --- .../DataflowTests.cs | 12 +++++++----- test/TestHelpers/TaskUtils.cs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/test/Microsoft.Diagnostics.EventFlow.Core.Tests/DataflowTests.cs b/test/Microsoft.Diagnostics.EventFlow.Core.Tests/DataflowTests.cs index b678971a..aeb8a4a7 100644 --- a/test/Microsoft.Diagnostics.EventFlow.Core.Tests/DataflowTests.cs +++ b/test/Microsoft.Diagnostics.EventFlow.Core.Tests/DataflowTests.cs @@ -442,6 +442,10 @@ private async Task BlockKeepsDeclinedMessages(Func> BlockFacto private async Task BlockKeepsPostponedMessages(Func> BlockFactory) { + // This test requires longer timeout than most of the other tests in this suite, otherwise it occasionally fails on slower machines + // If it fails nevertheless, switch to custom TaskScheduler. + TimeSpan longArrivalTimeout = TimeSpan.FromMilliseconds(MessageArrivalTimeout.TotalMilliseconds * 10.0); + ISourceBlock block = BlockFactory(); ITargetBlock blockT = (ITargetBlock)block; @@ -458,21 +462,19 @@ private async Task BlockKeepsPostponedMessages(Func> BlockFact // Out of capacity Assert.False(blockT.Post(4)); - // However SendAsync() will allow postponing the message, sot the message will be eventually delivered + // However SendAsync() will allow postponing the message, so the message will be eventually delivered blockT.SendAsync(5).Forget(); // Wait till the block offers a message // Assumption: only one message will be offered, the block will not offer more messages if the target postpones - bool messageOffered = await TaskUtils.PollWaitAsync(() => testTarget.MessagesPostponed.Count == 1, MessageArrivalTimeout); + bool messageOffered = await TaskUtils.PollWaitAsync(() => testTarget.MessagesPostponed.Count == 1, longArrivalTimeout); Assert.True(messageOffered); // Assumption: once the block target stops postponing, the block will keep pushing data to target // until it runs out of buffered messages. testTarget.ConsumptionMode = DataflowMessageStatus.Accepted; testTarget.ConsumePostponedMessages(); - // Use 10 times the normal message arrival timeout for extra padding--the test tended to be a bit flakey at this point. - // If this happens again, switch to custom TaskScheduler. - bool gotAllMessages = await TaskUtils.PollWaitAsync(() => testTarget.MessagesConsumed.Count == 4, TimeSpan.FromMilliseconds(MessageArrivalTimeout.TotalMilliseconds * 10)); + bool gotAllMessages = await TaskUtils.PollWaitAsync(() => testTarget.MessagesConsumed.Count == 4, longArrivalTimeout); Assert.True(gotAllMessages, "We should have gotten 4 messages"); Assert.Equal(testTarget.MessagesConsumed.OrderBy((i) => i), new int[] { 1, 2, 3, 5 }); } diff --git a/test/TestHelpers/TaskUtils.cs b/test/TestHelpers/TaskUtils.cs index 34c2ab8e..88f7a930 100644 --- a/test/TestHelpers/TaskUtils.cs +++ b/test/TestHelpers/TaskUtils.cs @@ -10,7 +10,7 @@ namespace Microsoft.Diagnostics.EventFlow.TestHelpers { public static class TaskUtils { - private static readonly TimeSpan JustABit = TimeSpan.FromMilliseconds(20); + private static readonly TimeSpan JustABit = TimeSpan.FromMilliseconds(50); public static async Task PollWaitAsync(Func condition, TimeSpan timeout) {