Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public Task ActivatedBeforeStartRecievesMessage() =>

await PostTestMessageAsync(window);

await WaitForMessageAsync(() => messages.Contains(TEST_MESSAGE));

tracker.Stop();

Assert.Contains(TEST_MESSAGE, messages);
Expand Down Expand Up @@ -81,6 +83,8 @@ public Task StartBeforeActivatedRecievesMessage() =>

await PostTestMessageAsync(window);

await WaitForMessageAsync(() => messages.Contains(TEST_MESSAGE));

Assert.Contains(TEST_MESSAGE, messages);

void OnWindowMessage(object? sender, WindowMessageEventArgs e)
Expand Down Expand Up @@ -108,6 +112,8 @@ public Task SwitchingWindowsPostsToTheNewWindow() =>

await PostTestMessageAsync(window2);

await WaitForMessageAsync(() => messages.Contains((window2.GetWindowHandle(), TEST_MESSAGE)));

Assert.DoesNotContain((window1.GetWindowHandle(), TEST_MESSAGE), messages);
Assert.Contains((window2.GetWindowHandle(), TEST_MESSAGE), messages);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Maui.Platform;
Expand All @@ -23,5 +24,19 @@ protected async Task PostTestMessageAsync(UI.Xaml.Window window)

await Task.Delay(100);
}

// PostMessage delivers asynchronously: the posted window message is only seen once the
// message pump dispatches it. Poll the condition (yielding to the pump on each iteration)
// up to a generous timeout instead of asserting after a single fixed delay, so a slow pump
// under CI load no longer reads as a failure. A genuine "message never delivered" defect
// still fails the caller's assertion once the timeout elapses.
protected static async Task WaitForMessageAsync(Func<bool> condition, int timeoutMs = 5000, int pollMs = 50)
{
var stopwatch = Stopwatch.StartNew();
while (!condition() && stopwatch.ElapsedMilliseconds < timeoutMs)
{
await Task.Delay(pollMs);
}
}
}
}
Loading