Skip to content

Commit

Permalink
fixup! add support for retries
Browse files Browse the repository at this point in the history
  • Loading branch information
timmywil committed Mar 27, 2024
1 parent 5289d84 commit 543e26b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
run: npm run build

- name: Test
run: npm run test:unit -- -h -b ${{ matrix.BROWSER }} --jquery ${{ matrix.JQUERY }}
run: npm run test:unit -- -h -b ${{ matrix.BROWSER }} --jquery ${{ matrix.JQUERY }} --retries 3

edge:
runs-on: windows-latest
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
run: npm run build

- name: Test
run: npm run test:unit -- -h -b edge --jquery ${{ matrix.JQUERY }}
run: npm run test:unit -- -h -b edge --jquery ${{ matrix.JQUERY }} --retries 3

safari:
runs-on: macos-latest
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
run: npm run build

- name: Test
run: npm run test:unit -- -b safari --jquery ${{ matrix.JQUERY }}
run: npm run test:unit -- -b safari --jquery ${{ matrix.JQUERY }} --retries 3

legacy-build:
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions tests/runner/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ const argv = yargs( process.argv.slice( 2 ) )
"Leave the browser open for debugging. Cannot be used with --headless.",
conflicts: [ "headless" ]
} )
.option( "retries", {
alias: "r",
type: "number",
description: "Number of times to retry failed tests."
} )
.option( "concurrency", {
alias: "c",
type: "number",
Expand Down
10 changes: 9 additions & 1 deletion tests/runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { generateHash } from "./lib/generateHash.js";
import { getBrowserString } from "./lib/getBrowserString.js";
import { suites as allSuites } from "./suites.js";
import { cleanupAllBrowsers, touchBrowser } from "./selenium/browsers.js";
import { addRun, getNextBrowserTest, runAll } from "./selenium/queue.js";
import { addRun, getNextBrowserTest, retryTest, runAll } from "./selenium/queue.js";

const EXIT_HOOK_WAIT_TIMEOUT = 60 * 1000;

Expand All @@ -21,6 +21,7 @@ export async function run( {
headless,
jquery: jquerys = [],
migrate,
retries = 0,
suite: suites = [],
verbose
} ) {
Expand Down Expand Up @@ -88,6 +89,13 @@ export async function run( {

// Handle failure
if ( failed ) {
const retry = retryTest( reportId, retries );

// Retry if retryTest returns a test
if ( retry ) {
return retry;
}

errorMessages.push( ...Object.values( pendingErrors[ reportId ] ) );
}

Expand Down
20 changes: 20 additions & 0 deletions tests/runner/selenium/queue.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from "chalk";
import { getBrowserString } from "../lib/getBrowserString.js";
import {
checkLastTouches,
Expand Down Expand Up @@ -34,11 +35,30 @@ export function getNextBrowserTest( reportId ) {
}
}

export function retryTest( reportId, maxRetries ) {
if ( !maxRetries ) {
return;
}
const test = queue.find( ( test ) => test.id === reportId );
if ( test ) {
test.retries++;
if ( test.retries <= maxRetries ) {
console.log(
`\nRetrying test ${ reportId } for ${ chalk.yellow( test.options.suite ) }...${
test.retries
}`
);
return test;
}
}
}

export function addRun( url, browser, options ) {
queue.push( {
browser,
fullBrowser: getBrowserString( browser ),
id: options.reportId,
retries: 0,
url,
options,
running: false
Expand Down

0 comments on commit 543e26b

Please sign in to comment.