What changed, and why it matters
This commit fixes a timing issue in BTCPay Server's automated test suite. It ensures that when a test triggers a browser alert dialog, the test waits for the dialog to actually be accepted before continuing. Previously, the test could proceed before the dialog handler finished, causing unpredictable 'flaky' test failures. There is no change to production code or user-facing security behavior.
No security action required. This is a test reliability improvement. Review and merge as normal.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is in BTCPayServer.Tests/PlaywrightTester.cs’s FillAlertDialog helper. It replaces a fire-and-forget async void dialog handler with a TaskCompletionSource-backed handler that signals completion (or exception) after dialog.AcceptAsync(text) finishes. The caller now awaits tcs.Task after invoking openDialog(), eliminating a race where the dialog acceptance might not complete before subsequent test steps run. This is purely a test-infrastructure reliability fix.
Changed components
BTCPayServer.Tests/PlaywrightTester.csInspect captured patch +16 / −2
diff --git a/BTCPayServer.Tests/PlaywrightTester.cs b/BTCPayServer.Tests/PlaywrightTester.cs
index f82931a..71353bb4 100644
--- a/BTCPayServer.Tests/PlaywrightTester.cs
+++ b/BTCPayServer.Tests/PlaywrightTester.cs
@@ -921,14 +921,28 @@ namespace BTCPayServer.Tests
public async Task FillAlertDialog(string text, Func<Task> openDialog)
{
+ var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
+
// Handle the alert dialog in Playwright
// ReSharper disable once AsyncVoidMethod
- async void Callback(object? sender, IDialog e)
- => await e.AcceptAsync(text);
+ async void Callback(object? sender, IDialog dialog)
+ {
+ try
+ {
+ await dialog.AcceptAsync(text);
+ tcs.TrySetResult();
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ }
+
Page.Dialog += Callback;
try
{
await openDialog();
+ await tcs.Task;
}
finally
{
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.