From a2e669376ca0536051b16e8f89e5cdd13e4c1899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Tue, 10 Jan 2023 23:17:25 +0100 Subject: [PATCH 1/2] Typos, better docs --- .../Extensions/ReliabilityUITestContextExtensions.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Lombiq.Tests.UI/Extensions/ReliabilityUITestContextExtensions.cs b/Lombiq.Tests.UI/Extensions/ReliabilityUITestContextExtensions.cs index 682dac12f..8377568a3 100644 --- a/Lombiq.Tests.UI/Extensions/ReliabilityUITestContextExtensions.cs +++ b/Lombiq.Tests.UI/Extensions/ReliabilityUITestContextExtensions.cs @@ -74,13 +74,14 @@ public static Task DoWithRetriesOrFailAsync( interval ?? context.Configuration.TimeoutConfiguration.RetryInterval); /// - /// Executes the async process and retries if an element becomes stale ( ). If the operation didn't succeed then throws a . /// /// In situations like a DataTable load it is possible that the page will change during execution of multiple long - /// running operations such as GetAll, causing stale virtual DOM. Such change tends to be near instantaneous and - /// only happens once at a time so this should pass by the 2nd try. + /// running operations such as , + /// causing stale virtual DOM. Such change tends to be near instantaneous and only happens once at a time so this + /// should pass by the 2nd try. /// /// /// The long running operation that may execute during DOM change and should be retried. Should return - /// Executes the process and retries until no element is stale ( ). + /// Executes the process and retries until no element is stale (throws ). /// /// If the operation didn't succeed then throws a . /// From 6f21f15f15dc0ae271b140461d600ca6b2f399d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Tue, 10 Jan 2023 23:54:00 +0100 Subject: [PATCH 2/2] Fixing that stale retries didn't actually retry --- Lombiq.Tests.UI/Helpers/ReliabilityHelper.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Lombiq.Tests.UI/Helpers/ReliabilityHelper.cs b/Lombiq.Tests.UI/Helpers/ReliabilityHelper.cs index bc4bc92a3..255d1f25d 100644 --- a/Lombiq.Tests.UI/Helpers/ReliabilityHelper.cs +++ b/Lombiq.Tests.UI/Helpers/ReliabilityHelper.cs @@ -7,29 +7,33 @@ namespace Lombiq.Tests.UI.Helpers; public static class ReliabilityHelper { - private static readonly Func>, Func>> _retryIfStaleProcess = innerProcess => () => + private static readonly Func>, Func>> _retryIfStaleProcess = innerProcess => async () => { try { - return innerProcess(); + // This needs to use await instead of returning the Task directly, because only this way can we catch the + // exception below. + return await innerProcess(); } catch (StaleElementReferenceException) { // When navigating away this exception will be thrown for all old element references. Not nice to use // exceptions but there doesn't seem to be a better way to do this. - return Task.FromResult(false); + return false; } }; - private static readonly Func>, Func>> _retryIfNotStaleProcess = innerProcess => () => + private static readonly Func>, Func>> _retryIfNotStaleProcess = innerProcess => async () => { try { - return innerProcess(); + // This needs to use await instead of returning the Task directly, because only this way can we catch the + // exception below. + return await innerProcess(); } catch (StaleElementReferenceException) { - return Task.FromResult(true); + return true; } };