Skip to content

Commit

Permalink
feat(timeout): command line argument for ACE_TIMEOUT_EXTENSION (-T/--…
Browse files Browse the repository at this point in the history
…timeout)
  • Loading branch information
danielweck committed Dec 17, 2024
1 parent e6f93a8 commit 51e21f8
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 28 deletions.
16 changes: 13 additions & 3 deletions packages/ace-axe-runner-electron/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
const LOG_DEBUG = false;
const ACE_LOG_PREFIX = "[ACE-AXE]";

let cliOption_MILLISECONDS_TIMEOUT_EXTENSION = undefined;

function createAxeRunner(eventEmmitter, CONCURRENT_INSTANCES) {

return {
setTimeout: function (ms) {
try {
cliOption_MILLISECONDS_TIMEOUT_EXTENSION = parseInt(ms, 10);
} catch(_e) {
// ignore
}
},
concurrency: CONCURRENT_INSTANCES,
launch: function () {
if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner will launch ...`);
Expand Down Expand Up @@ -42,7 +51,7 @@ function createAxeRunner(eventEmmitter, CONCURRENT_INSTANCES) {
},
close: function () {
if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner will close ...`);

// // ipcRenderer
// eventEmmitter.send('AXE_RUNNER_CLOSE', {});
// return Promise.resolve();
Expand Down Expand Up @@ -79,7 +88,7 @@ function createAxeRunner(eventEmmitter, CONCURRENT_INSTANCES) {
},
run: function (url, scripts, scriptContents, basedir) {
if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner will run ... ${url}`);

return new Promise((resolve, reject) => {
// ipcRenderer
const callback = (event, arg) => {
Expand Down Expand Up @@ -110,10 +119,11 @@ function createAxeRunner(eventEmmitter, CONCURRENT_INSTANCES) {
scripts,
scriptContents,
basedir,
cliOption_MILLISECONDS_TIMEOUT_EXTENSION,
});
});
}
};
}

module.exports = { createAxeRunner };
module.exports = { createAxeRunner };
7 changes: 5 additions & 2 deletions packages/ace-axe-runner-electron/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const fsOriginal = require('original-fs');
const isDev = process && process.env && (process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true');
const showWindow = false;

let cliOption_MILLISECONDS_TIMEOUT_EXTENSION = undefined;

const LOG_DEBUG_URLS = process.env.LOG_DEBUG_URLS === "1";

const LOG_DEBUG = false;
Expand Down Expand Up @@ -242,8 +244,8 @@ function loadUrl(browserWindow) {
} catch(_e) {
// ignore
}
const MILLISECONDS_TIMEOUT_INITIAL = _MILLISECONDS_TIMEOUT_INITIAL || 10000; // 10s check to load the browser window web contents + execute Axe checkers
const MILLISECONDS_TIMEOUT_EXTENSION = _MILLISECONDS_TIMEOUT_EXTENSION || 480000; // 480s (8mn) extension (window contents usually loads fast, but Axe runtime takes time...)
const MILLISECONDS_TIMEOUT_INITIAL = _MILLISECONDS_TIMEOUT_INITIAL || 5000; // 5s check to load the browser window web contents + execute Axe checkers
const MILLISECONDS_TIMEOUT_EXTENSION = cliOption_MILLISECONDS_TIMEOUT_EXTENSION || _MILLISECONDS_TIMEOUT_EXTENSION || 240000; // 240s (4mn) extension (window contents usually loads fast, but Axe runtime takes time...)

const timeoutFunc = () => {
if (browserWindow.ace__replySent) {
Expand Down Expand Up @@ -572,6 +574,7 @@ function axeRunnerInit(eventEmmitter, CONCURRENT_INSTANCES) {
const uarel = payload.url;
const scripts = payload.scripts;
const scriptContents = payload.scriptContents;
cliOption_MILLISECONDS_TIMEOUT_EXTENSION = payload.cliOption_MILLISECONDS_TIMEOUT_EXTENSION;

if (LOG_DEBUG_URLS) {
console.log("######## URL 1");
Expand Down
17 changes: 13 additions & 4 deletions packages/ace-axe-runner-puppeteer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ try {
} catch(_e) {
// ignore
}
const MILLISECONDS_TIMEOUT_INITIAL = _MILLISECONDS_TIMEOUT_INITIAL || 10000; // 10s check to load the browser window web contents + execute Axe checkers
const MILLISECONDS_TIMEOUT_EXTENSION = _MILLISECONDS_TIMEOUT_EXTENSION || 480000; // 480s (8mn) extension (window contents usually loads fast, but Axe runtime takes time...)
const MILLISECONDS_TIMEOUT_INITIAL = _MILLISECONDS_TIMEOUT_INITIAL || 5000; // 5s check to load the browser window web contents
const MILLISECONDS_TIMEOUT_EXTENSION = _MILLISECONDS_TIMEOUT_EXTENSION || 240000; // 240s (4mn) runtime (window contents usually loads fast, but Axe runtime takes time...)

let cliOption_MILLISECONDS_TIMEOUT_EXTENSION = undefined;

module.exports = {
setTimeout: function (ms) {
try {
cliOption_MILLISECONDS_TIMEOUT_EXTENSION = parseInt(ms, 10);
} catch(_e) {
// ignore
}
},
concurrency: 4,
launch: async function() {
const args = [];
Expand All @@ -41,7 +50,7 @@ module.exports = {
args,
headless: true,
timeout: MILLISECONDS_TIMEOUT_INITIAL, // 30000 default
protocolTimeout: MILLISECONDS_TIMEOUT_EXTENSION, // 180000 default
protocolTimeout: cliOption_MILLISECONDS_TIMEOUT_EXTENSION || MILLISECONDS_TIMEOUT_EXTENSION, // 180000 default
});
return Promise.resolve();
},
Expand Down Expand Up @@ -157,7 +166,7 @@ module.exports = {
} catch (err) {
// ProtocolError: Runtime.callFunctionOn timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed.
if (err && err.toString && err.toString().indexOf("protocolTimeout") >= 0) {
err = new Error(`Timeout :( ${MILLISECONDS_TIMEOUT_EXTENSION}ms`);
err = new Error(`Timeout :( ${cliOption_MILLISECONDS_TIMEOUT_EXTENSION || MILLISECONDS_TIMEOUT_EXTENSION}ms`);
}
try {
await page.close();
Expand Down
7 changes: 7 additions & 0 deletions packages/ace-cli-shared/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const meowHelpMessage = `
-s, --silent do not display any output
-l, --lang <language> language code for localized messages (e.g. "fr"), default is "en"
-T, --timeout <milliseconds> (default is 240000 per document)
Examples
$ ace -o out ~/Documents/book.epub
Expand Down Expand Up @@ -76,6 +78,10 @@ const meowOptions = {
lang: {
alias: 'l',
type: 'string'
},
timeout: {
alias: 'T',
type: 'string'
}
}
};
Expand Down Expand Up @@ -149,6 +155,7 @@ ${overrides.map(file => ` - ${file}`).join('\n')}
silent: cli.flags.silent,
jobId: '',
lang: cli.flags.lang,
timeout: cli.flags.timeout || undefined,
}, axeRunner)
.then(async (jobData) => {
var reportJson = jobData[1];
Expand Down
14 changes: 8 additions & 6 deletions packages/ace-core/src/core/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,29 @@ tmp.setGracefulCleanup();

module.exports = function ace(epubPath, options, axeRunner) {

if (options.timeout) axeRunner.setTimeout(options.timeout);

return new Promise((resolve, reject) => {

function l10nDoneCallback() {

if (options.initLogger) {
logger.initLogger({ verbose: options.verbose, silent: options.silent, fileName: options.fileName });
}

// the jobid option just gets returned in the resolve/reject
// so the calling function can track which job finished
var jobId = 'jobid' in options ? options.jobid : '';
winston.verbose(`Ace ${pkg.version}, Node ${process.version}, ${os.type()} ${os.release()}`);
winston.verbose("Options:", options);

// Check that the EPUB exists
const epubPathResolved = path.resolve(options.cwd, epubPath);
if (!fs.existsSync(epubPathResolved)) {
winston.error(`Couldn’t find EPUB file '${epubPath}'`);
return reject(jobId);
}

// Process options
/* eslint-disable no-param-reassign */
if (typeof options.tmpdir === 'string') {
Expand All @@ -57,11 +59,11 @@ module.exports = function ace(epubPath, options, axeRunner) {
} else {
delete options.outdir;
}

winston.info("Processing " + epubPath);

/* eslint-enable no-param-reassign */

// Unzip the EPUB
const epub = new EPUB(epubPathResolved);
epub.extract()
Expand Down
5 changes: 4 additions & 1 deletion packages/ace-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const meowHelpMessage = `
-s, --silent do not display any output
-l, --lang <language> language code for localized messages (e.g. "fr"), default is "en"
-T, --timeout <milliseconds> (default is 240000 per document)
Examples
$ ace-http -p 3000`;
const meowOptions = {
Expand Down Expand Up @@ -151,6 +153,7 @@ function postJob(req, res, next) {
"outputDir": tmp.dirSync({ unsafeCleanup: true }).name,
"epubPath": req.file.path,
"lang": cli.flags.lang,
"timeout": cli.flags.timeout || undefined,
}
};
newJob(jobdata);
Expand Down Expand Up @@ -189,7 +192,7 @@ function newJob(jobdata) {
joblist.push(jobdata);

// execute the job with Ace
ace(jobdata.internal.epubPath, {'jobid': jobdata.internal.id, 'outdir': jobdata.internal.outputDir, 'lang': jobdata.internal.lang}, axeRunner)
ace(jobdata.internal.epubPath, {'jobid': jobdata.internal.id, 'outdir': jobdata.internal.outputDir, 'lang': jobdata.internal.lang, 'timeout': jobdata.internal.timeout}, axeRunner)
.then((jobData) => {
var jobId = jobData[0];
var idx = joblist.findIndex(job => job.internal.id === jobId);
Expand Down
16 changes: 10 additions & 6 deletions scripts/compareAxeRunners.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ echo "ElectronAxeRunner ..."
#node ./packages/ace-axe-runner-electron/bin/ace.js
#node ./packages/ace/bin/ace-electron.js

# defaults: ACE_TIMEOUT_INITIAL=10000 ACE_TIMEOUT_EXTENSION=480000
# ACE_TIMEOUT_INITIAL=4000 ACE_TIMEOUT_EXTENSION=150000
ACE_PERF=1 node ./packages/ace/bin/ace-electron.js -f -s -o ./CompareAxeRunners/ElectronAxeRunner "$1"
# defaults: ACE_TIMEOUT_INITIAL=5000 ACE_TIMEOUT_EXTENSION=240000
# ACE_TIMEOUT_INITIAL ==> load and Axe
# ACE_TIMEOUT_EXTENSION ==> Axe...
# -T/--timeout 100 means 100 milliseconds over the initial 5 seconds for Axe to do its job
ACE_PERF=1 node ./packages/ace/bin/ace-electron.js -T 100 -l en -f -s -o ./CompareAxeRunners/ElectronAxeRunner "$1"

echo "PuppeteerAxeRunner ..."

# defaults: ACE_TIMEOUT_INITIAL=10000 ACE_TIMEOUT_EXTENSION=480000
# ACE_TIMEOUT_INITIAL=4000 ACE_TIMEOUT_EXTENSION=150000
ACE_PERF=1 node ./packages/ace-cli/bin/ace.js -f -s -o ./CompareAxeRunners/PuppeteerAxeRunner "$1"
# defaults: ACE_TIMEOUT_INITIAL=5000 ACE_TIMEOUT_EXTENSION=240000
# ACE_TIMEOUT_INITIAL ==> load
# ACE_TIMEOUT_EXTENSION ==> Axe...
# -T/--timeout 5100 means 5 seconds and 100 milliseconds for Axe to do its job
ACE_PERF=1 node ./packages/ace-cli/bin/ace.js -T 5100 -l en -f -s -o ./CompareAxeRunners/PuppeteerAxeRunner "$1"

node ./scripts/normalise_report_json.js ./CompareAxeRunners/PuppeteerAxeRunner/report.json
node ./scripts/normalise_report_json.js ./CompareAxeRunners/ElectronAxeRunner/report.json
Expand Down
16 changes: 10 additions & 6 deletions scripts/compareAxeRunners_VERBOSE.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ echo "ElectronAxeRunner ..."
#node ./packages/ace-axe-runner-electron/bin/ace.js
#node ./packages/ace/bin/ace-electron.js

# defaults: ACE_TIMEOUT_INITIAL=10000 ACE_TIMEOUT_EXTENSION=480000
# ACE_TIMEOUT_INITIAL=4000 ACE_TIMEOUT_EXTENSION=150000
ACE_PERF=1 node ./packages/ace/bin/ace-electron.js -l en -f -V -o ./CompareAxeRunners/ElectronAxeRunner "$1"
# defaults: ACE_TIMEOUT_INITIAL=5000 ACE_TIMEOUT_EXTENSION=240000
# ACE_TIMEOUT_INITIAL ==> load and Axe
# ACE_TIMEOUT_EXTENSION ==> Axe...
# -T/--timeout 100 means 100 milliseconds over the initial 5 seconds for Axe to do its job
ACE_PERF=1 node ./packages/ace/bin/ace-electron.js -T 100 -l en -f -V -o ./CompareAxeRunners/ElectronAxeRunner "$1"

echo "PuppeteerAxeRunner ..."

# defaults: ACE_TIMEOUT_INITIAL=10000 ACE_TIMEOUT_EXTENSION=480000
# ACE_TIMEOUT_INITIAL=4000 ACE_TIMEOUT_EXTENSION=150000
ACE_PERF=1 node ./packages/ace-cli/bin/ace.js -l en -f -V -o ./CompareAxeRunners/PuppeteerAxeRunner "$1"
# defaults: ACE_TIMEOUT_INITIAL=5000 ACE_TIMEOUT_EXTENSION=240000
# ACE_TIMEOUT_INITIAL ==> load
# ACE_TIMEOUT_EXTENSION ==> Axe...
# -T/--timeout 5100 means 5 seconds and 100 milliseconds for Axe to do its job
ACE_PERF=1 node ./packages/ace-cli/bin/ace.js -T 5100 -l en -f -V -o ./CompareAxeRunners/PuppeteerAxeRunner "$1"

node ./scripts/normalise_report_json.js ./CompareAxeRunners/PuppeteerAxeRunner/report.json
node ./scripts/normalise_report_json.js ./CompareAxeRunners/ElectronAxeRunner/report.json
Expand Down
4 changes: 4 additions & 0 deletions tests/__tests__/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ exports[`Running the CLI with no input should fail 2`] = `
-s, --silent do not display any output
-l, --lang <language> language code for localized messages (e.g. \"fr\"), default is \"en\"
-T, --timeout <milliseconds> (default is 240000 per document)
Examples
$ ace -o out ~/Documents/book.epub
Expand Down Expand Up @@ -75,6 +77,8 @@ exports[`Running the CLI with the -h option should print help 1`] = `
-s, --silent do not display any output
-l, --lang <language> language code for localized messages (e.g. \"fr\"), default is \"en\"
-T, --timeout <milliseconds> (default is 240000 per document)
Examples
$ ace -o out ~/Documents/book.epub
Expand Down
2 changes: 2 additions & 0 deletions website/content/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Ace by DAISY, an Accessibility Checker for EPUB
-s, --silent do not display any output
-l, --lang <language> language code for localized messages (e.g. "fr"), default is "en"
-T, --timeout <milliseconds> (default is 240000 per document)
Examples
$ ace -o out ~/Documents/book.epub
Expand Down
2 changes: 2 additions & 0 deletions website/content/docs/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Ace by DAISY, an Accessibility Checker for EPUB
-s, --silent do not display any output
-l, --lang <language> language code for localized messages (e.g. "fr"), default is "en"
-T, --timeout <milliseconds> (default is 240000 per document)
Examples
$ ace-http -p 3000
```
Expand Down

0 comments on commit 51e21f8

Please sign in to comment.