Skip to content

Commit c7a3b65

Browse files
Send local_identifier_error when local_identifier not running in stopBinary
1 parent eb75a45 commit c7a3b65

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

bin/helpers/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const userMessages = {
3838
RETRY_LIMIT_EXCEEDED: `Max retries exceeded trying to connect to the host (retries: ${config.retries})`,
3939
CHECK_DASHBOARD_AT: "Please check the build status at: ",
4040
CYPRESS_VERSION_CHANGED: "Your build will run using Cypress <actualVersion> instead of Cypress <preferredVersion>. Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
41-
LOCAL_START_FAILED: "Local Testing setup failed."
41+
LOCAL_START_FAILED: "Local Testing setup failed.",
42+
LOCAL_STOP_FAILED: "Local Binary stop failed."
4243
};
4344

4445
const validationMessages = {

bin/helpers/utils.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,21 @@ exports.setupLocalTesting = (bsConfig, args) => {
441441
};
442442

443443
exports.stopLocalBinary = (bsConfig, bs_local, args) => {
444-
return new Promise((resolve, reject) => {
444+
return new Promise(async (resolve, reject) => {
445+
if(bsConfig['connection_settings'] && bsConfig['connection_settings']['local']){
446+
let localIdentifierRunning = await this.checkLocalIdentifierRunning(bsConfig,bsConfig["connection_settings"]["local_identifier"]);
447+
if(!localIdentifierRunning){
448+
let message = `Local Binary not running.`,
449+
errorCode = 'local_identifier_error';
450+
this.sendUsageReport(
451+
bsConfig,
452+
args,
453+
message,
454+
Constants.messageTypes.ERROR,
455+
errorCode
456+
);
457+
}
458+
}
445459
if (!this.isUndefined(bs_local) && bs_local.isRunning() && bsConfig['connection_settings'] && bsConfig['connection_settings']['local_mode'].toLowerCase() != "always-on") {
446460
let that = this;
447461
bs_local.stop(function (localStopError) {
@@ -457,7 +471,7 @@ exports.stopLocalBinary = (bsConfig, bs_local, args) => {
457471
Constants.messageTypes.ERROR,
458472
errorCode
459473
);
460-
resolve(localStopError);
474+
resolve(Constants.userMessages.LOCAL_STOP_FAILED);
461475
}
462476
});
463477
} else {

test/unit/bin/helpers/utils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,16 @@ describe('utils', () => {
961961
local: true
962962
}
963963
};
964+
let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
965+
checkLocalIdentifierRunningStub.returns(Promise.resolve(false));
966+
let sendUsageReportStub = sandbox
967+
.stub(utils, 'sendUsageReport')
968+
.callsFake(function () {
969+
return 'end';
970+
});
964971
return utils.stopLocalBinary(bsConfig).then((result) => {
965972
expect(result).to.be.eq(undefined);
973+
sinon.assert.calledOnce(sendUsageReportStub);
966974
});
967975
});
968976

@@ -976,6 +984,8 @@ describe('utils', () => {
976984
let bs_local = {
977985
isRunning: isRunningStub,
978986
};
987+
let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
988+
checkLocalIdentifierRunningStub.returns(Promise.resolve(true));
979989
return utils.stopLocalBinary(bsConfig, bs_local).then((result) => {
980990
expect(result).to.be.eq(undefined);
981991
});
@@ -991,6 +1001,8 @@ describe('utils', () => {
9911001
let bs_local = {
9921002
isRunning: isRunningStub,
9931003
}
1004+
let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
1005+
checkLocalIdentifierRunningStub.returns(Promise.resolve(true));
9941006
return utils.stopLocalBinary(bsConfig, bs_local).then((result) => {
9951007
expect(result).to.be.eq(undefined);
9961008
});
@@ -1008,6 +1020,8 @@ describe('utils', () => {
10081020
isRunning: isRunningStub,
10091021
stop: stopStub
10101022
}
1023+
let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
1024+
checkLocalIdentifierRunningStub.returns(Promise.resolve(true));
10111025
return utils.stopLocalBinary(bsConfig, bs_local).then((result) => {
10121026
expect(result).to.be.eq(undefined);
10131027
});
@@ -1022,6 +1036,8 @@ describe('utils', () => {
10221036
let isRunningStub = sandbox.stub().returns(true);
10231037
let error = new Error('Local Stop Error');
10241038
let stopStub = sandbox.stub().yields(error);
1039+
let checkLocalIdentifierRunningStub = sinon.stub(utils, "checkLocalIdentifierRunning");
1040+
checkLocalIdentifierRunningStub.returns(Promise.resolve(true));
10251041
let bs_local = {
10261042
isRunning: isRunningStub,
10271043
stop: stopStub
@@ -1032,7 +1048,7 @@ describe('utils', () => {
10321048
return 'end';
10331049
});
10341050
return utils.stopLocalBinary(bsConfig, bs_local, {}).then((result) => {
1035-
expect(result).to.be.eq(error);
1051+
expect(result).to.be.eq(constant.userMessages.LOCAL_STOP_FAILED);
10361052
sinon.assert.calledOnce(sendUsageReportStub);
10371053
sinon.assert.calledOnce(stopStub);
10381054
});

0 commit comments

Comments
 (0)