remote_runner: Promisify
parent
9059a55873
commit
bbb3046a87
|
@ -30,7 +30,7 @@ const log = (msg, pfx = '') => {
|
||||||
|
|
||||||
const finishedRegex = /FINISHED.*[0-9]+ tests passed, ([0-9]+) tests failed/;
|
const finishedRegex = /FINISHED.*[0-9]+ tests passed, ([0-9]+) tests failed/;
|
||||||
|
|
||||||
const sauceTestWorker = async.queue((testSettings, callback) => {
|
const sauceTestWorker = async.queue(async (testSettings) => {
|
||||||
const name = `${testSettings.browserName} ${testSettings.version}, ${testSettings.platform}`;
|
const name = `${testSettings.browserName} ${testSettings.version}, ${testSettings.platform}`;
|
||||||
const pfx = `[${name}] `;
|
const pfx = `[${name}] `;
|
||||||
const fullName = [process.env.GIT_HASH].concat(process.env.SAUCE_NAME || [], name).join(' - ');
|
const fullName = [process.env.GIT_HASH].concat(process.env.SAUCE_NAME || [], name).join(' - ');
|
||||||
|
@ -42,52 +42,33 @@ const sauceTestWorker = async.queue((testSettings, callback) => {
|
||||||
testSettings.extendedDebugging = true;
|
testSettings.extendedDebugging = true;
|
||||||
testSettings.tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER;
|
testSettings.tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER;
|
||||||
const browser = wd.remote(config, 'promiseChain');
|
const browser = wd.remote(config, 'promiseChain');
|
||||||
browser.init(testSettings).get('http://localhost:9001/tests/frontend/', (err) => {
|
await browser.init(testSettings);
|
||||||
if (err != null) return callback(err);
|
const url = `https://saucelabs.com/jobs/${browser.sessionID}`;
|
||||||
const url = `https://saucelabs.com/jobs/${browser.sessionID}`;
|
await browser.get('http://localhost:9001/tests/frontend/');
|
||||||
log(`Remote sauce test started! ${url}`, pfx);
|
log(`Remote sauce test started! ${url}`, pfx);
|
||||||
|
// @TODO this should be configured in testSettings, see
|
||||||
// tear down the test excecution
|
// https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options#TestConfigurationOptions-Timeouts
|
||||||
const stopSauce = (testErr) => {
|
const deadline = Date.now() + 14.5 * 60 * 1000; // Slightly less than overall test timeout.
|
||||||
clearInterval(getStatusInterval);
|
// how many characters of the log have been sent to travis
|
||||||
clearTimeout(timeout);
|
let logIndex = 0;
|
||||||
browser.quit((err) => {
|
while (true) {
|
||||||
if (err) return callback(err);
|
const consoleText = await browser.eval("$('#console').text()") || '';
|
||||||
if (testErr) {
|
consoleText.substring(logIndex).split('\\n').forEach((line) => log(line, pfx));
|
||||||
log(`[red]FAILED[clear] ${testErr}`, pfx);
|
logIndex = consoleText.length;
|
||||||
process.exitCode = 1;
|
const [finished, nFailedStr] = consoleText.match(finishedRegex) || [];
|
||||||
}
|
if (finished) {
|
||||||
log(`Remote sauce test finished! ${url}`, pfx);
|
if (nFailedStr !== '0') process.exitCode = 1;
|
||||||
callback();
|
break;
|
||||||
});
|
}
|
||||||
};
|
if (Date.now() >= deadline) {
|
||||||
|
log('[red]FAILED[clear] allowed test duration exceeded');
|
||||||
/**
|
process.exitCode = 1;
|
||||||
* timeout if a test hangs or the job exceeds 14.5 minutes
|
break;
|
||||||
* It's necessary because if travis kills the saucelabs session due to inactivity,
|
}
|
||||||
* we don't get any output
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||||
* @todo this should be configured in testSettings, see
|
}
|
||||||
* https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options#TestConfigurationOptions-Timeouts
|
log(`Remote sauce test finished! ${url}`, pfx);
|
||||||
*/
|
await browser.quit();
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
stopSauce(new Error('allowed test duration exceeded'));
|
|
||||||
}, 14.5 * 60 * 1000); // Slightly less than overall test timeout.
|
|
||||||
|
|
||||||
// how many characters of the log have been sent to travis
|
|
||||||
let logIndex = 0;
|
|
||||||
const getStatusInterval = setInterval(() => {
|
|
||||||
browser.eval("$('#console').text()", (err, consoleText) => {
|
|
||||||
if (err != null) return stopSauce(err);
|
|
||||||
if (!consoleText) return;
|
|
||||||
consoleText.substring(logIndex).split('\\n').forEach((line) => log(line, pfx));
|
|
||||||
logIndex = consoleText.length;
|
|
||||||
const [finished, nFailedStr] = consoleText.match(finishedRegex) || [];
|
|
||||||
if (finished) {
|
|
||||||
stopSauce(nFailedStr === '0' ? null : new Error(`${nFailedStr} tests failed`));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 5000);
|
|
||||||
});
|
|
||||||
}, 6); // run 6 tests in parrallel
|
}, 6); // run 6 tests in parrallel
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
|
|
Loading…
Reference in New Issue