diff --git a/bin/commands/runs.js b/bin/commands/runs.js index dc91679e..e8f7d01f 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -211,6 +211,13 @@ module.exports = function run(args, rawArgs) { logger.debug("Completed archiving test suite"); markBlockEnd('zip.archive'); + //setup Local Testing + markBlockStart('localSetup'); + logger.debug("Started setting up BrowserStack Local connection"); + let bs_local = await utils.setupLocalTesting(bsConfig, args, rawArgs, buildReportData); + logger.debug('Completed setting up BrowserStack Local connection'); + markBlockEnd('localSetup'); + let test_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.fileName)); let npm_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.packageFileName)); let node_modules_size = await utils.fetchFolderSize(path.join(process.cwd(), "node_modules")) @@ -233,12 +240,6 @@ module.exports = function run(args, rawArgs) { markBlockEnd('zip'); // Create build - //setup Local Testing - markBlockStart('localSetup'); - logger.debug("Started setting up BrowserStack Local connection"); - let bs_local = await utils.setupLocalTesting(bsConfig, args, rawArgs, buildReportData); - logger.debug('Completed setting up BrowserStack Local connection'); - markBlockEnd('localSetup'); logger.debug("Started build creation"); markBlockStart('createBuild'); return build.createBuild(bsConfig, zip).then(function (data) { @@ -380,9 +381,11 @@ module.exports = function run(args, rawArgs) { utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed', buildReportData, rawArgs); process.exitCode = Constants.ERROR_EXIT_CODE; }); - }).catch(function (err) { + }).catch(async function (err) { // Zip Upload failed | Local Start failed logger.error(err); + // stop the Local instance + await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs, buildReportData); if(err === Constants.userMessages.LOCAL_START_FAILED){ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed', buildReportData, rawArgs); } else { diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 961d220d..482276eb 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -857,7 +857,15 @@ exports.setLocalMode = (bsConfig, args) => { exports.setupLocalTesting = (bsConfig, args, rawArgs, buildReportData) => { return new Promise(async (resolve, reject) => { if( bsConfig['connection_settings'] && bsConfig['connection_settings']['local'] && String(bsConfig['connection_settings']['local']) === "true" ){ - let localBinaryRunning = await this.checkLocalBinaryRunning(bsConfig, bsConfig['connection_settings']['local_identifier']); + let localBinaryRunning; + try { + localBinaryRunning = await this.checkLocalBinaryRunning(bsConfig, bsConfig['connection_settings']['local_identifier']); + } catch(error) { + logger.debug(`Failed to check if a local binary is already running for a user with the error: ${error}`); + localBinaryRunning = { + should_spawn_binary: true + }; + } let localIdentifierRunning; if (localBinaryRunning['should_spawn_binary'] == true) { localIdentifierRunning = false;