From 364b2496d6486071cf4721d2e3dc1f28d7b6c5c7 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Wed, 11 Jun 2025 23:50:10 -0700 Subject: [PATCH] Chore: CI: Retry opening the go-to-anything dialog on failure (#12481) --- .eslintignore | 1 + .gitignore | 1 + .../integration-tests/models/GoToAnything.ts | 9 ++++++--- .../util/evaluateWithRetry.ts | 15 ++++---------- .../integration-tests/util/retryOnFailure.ts | 20 +++++++++++++++++++ 5 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 packages/app-desktop/integration-tests/util/retryOnFailure.ts diff --git a/.eslintignore b/.eslintignore index efd9baf8d6..76474c5e43 100644 --- a/.eslintignore +++ b/.eslintignore @@ -542,6 +542,7 @@ packages/app-desktop/integration-tests/util/evaluateWithRetry.js packages/app-desktop/integration-tests/util/extendedExpect.js packages/app-desktop/integration-tests/util/getImageSourceSize.js packages/app-desktop/integration-tests/util/getMainWindow.js +packages/app-desktop/integration-tests/util/retryOnFailure.js packages/app-desktop/integration-tests/util/setDarkMode.js packages/app-desktop/integration-tests/util/setFilePickerResponse.js packages/app-desktop/integration-tests/util/setMessageBoxResponse.js diff --git a/.gitignore b/.gitignore index 859857ff57..ba48bc04a6 100644 --- a/.gitignore +++ b/.gitignore @@ -517,6 +517,7 @@ packages/app-desktop/integration-tests/util/evaluateWithRetry.js packages/app-desktop/integration-tests/util/extendedExpect.js packages/app-desktop/integration-tests/util/getImageSourceSize.js packages/app-desktop/integration-tests/util/getMainWindow.js +packages/app-desktop/integration-tests/util/retryOnFailure.js packages/app-desktop/integration-tests/util/setDarkMode.js packages/app-desktop/integration-tests/util/setFilePickerResponse.js packages/app-desktop/integration-tests/util/setMessageBoxResponse.js diff --git a/packages/app-desktop/integration-tests/models/GoToAnything.ts b/packages/app-desktop/integration-tests/models/GoToAnything.ts index 8ee384093d..91c4cd58d7 100644 --- a/packages/app-desktop/integration-tests/models/GoToAnything.ts +++ b/packages/app-desktop/integration-tests/models/GoToAnything.ts @@ -3,6 +3,7 @@ import { ElectronApplication, expect, Locator, Page } from '@playwright/test'; import MainScreen from './MainScreen'; import activateMainMenuItem from '../util/activateMainMenuItem'; import { msleep } from '@joplin/utils/time'; +import retryOnFailure from '../util/retryOnFailure'; export default class GoToAnything { public readonly containerLocator: Locator; @@ -19,9 +20,11 @@ export default class GoToAnything { public async open(electronApp: ElectronApplication) { await this.mainScreen.waitFor(); - await activateMainMenuItem(electronApp, 'Goto Anything...'); - - return this.waitFor(); + const openFromMenu = async () => { + await activateMainMenuItem(electronApp, 'Goto Anything...'); + await this.waitFor(); + }; + await retryOnFailure(openFromMenu, { maxRetries: 3 }); } public async openLinkToNote(electronApp: ElectronApplication) { diff --git a/packages/app-desktop/integration-tests/util/evaluateWithRetry.ts b/packages/app-desktop/integration-tests/util/evaluateWithRetry.ts index eb72bc9106..8edc0bd72a 100644 --- a/packages/app-desktop/integration-tests/util/evaluateWithRetry.ts +++ b/packages/app-desktop/integration-tests/util/evaluateWithRetry.ts @@ -2,23 +2,16 @@ import { ElectronApplication } from '@playwright/test'; import type { PageFunctionOn } from 'playwright-core/types/structs'; import type * as ElectronType from 'electron'; +import retryOnFailure from './retryOnFailure'; const evaluateWithRetry = async ( app: ElectronApplication, pageFunction: PageFunctionOn, arg: Arg, ) => { - let lastError; - const maxRetries = 3; - for (let retryIndex = 0; retryIndex < maxRetries; retryIndex ++) { - try { - return await app.evaluate(pageFunction, arg); - } catch (error) { - console.error('app.evaluate failed:', error, `Retrying... ${retryIndex}/${maxRetries}`); - lastError = error; - } - } - throw lastError; + await retryOnFailure(async () => { + return await app.evaluate(pageFunction, arg); + }, { maxRetries: 3 }); }; export default evaluateWithRetry; diff --git a/packages/app-desktop/integration-tests/util/retryOnFailure.ts b/packages/app-desktop/integration-tests/util/retryOnFailure.ts new file mode 100644 index 0000000000..59d90d5f3f --- /dev/null +++ b/packages/app-desktop/integration-tests/util/retryOnFailure.ts @@ -0,0 +1,20 @@ + +interface Options { + maxRetries: number; +} + +const retryOnFailure = async (callback: ()=> Promise, { maxRetries }: Options): Promise => { + let lastError: Error|null = null; + for (let i = 0; i < maxRetries; i++) { + try { + return await callback(); + } catch (error) { + console.error('retry failed:', error, `Retrying... ${i + 1}/${maxRetries}`); + lastError = error; + } + } + + throw lastError; +}; + +export default retryOnFailure;