Skip to content

Add null check while updating progress bar #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ const userMessages = {
"Value for the 'spec_timeout' key not in the 1-120 range. Going ahead with 30 mins as the default spec timeout. Read more about how to specify the option in https://browserstack.com/docs/automate/cypress/spec-timeout",
SPEC_LIMIT_SUCCESS_MESSAGE:
"Spec timeout specified as <x> minutes. If any of your specs exceed the specified time limit, it would be forcibly killed by BrowserStack",
NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR:
"Unable to determine zip upload progress due to undefined/null connection request"
};

const validationMessages = {
Expand Down
48 changes: 43 additions & 5 deletions bin/helpers/zipUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const purgeUploadBar = (obj) => {

const uploadSuits = (bsConfig, filePath, opts, obj) => {
return new Promise(function (resolve, reject) {
let uploadProgressBarErrorFlags = {
noConnectionReportSent: false,
unknownErrorReportSent: false
};
obj.startTime = Date.now();

if (opts.urlPresent) {
Expand Down Expand Up @@ -96,11 +100,45 @@ const uploadSuits = (bsConfig, filePath, opts, obj) => {
});

obj.zipInterval = setInterval(function () {
let dispatched = r.req.connection._bytesDispatched;
let percent = dispatched * 100.0 / size;
obj.bar1.update(percent, {
speed: ((dispatched / (Date.now() - obj.startTime)) / 125).toFixed(2) //kbits per sec
});
const errorCode = 'update_upload_progress_bar_failed';
try {
if (r && r.req && r.req.connection) {
let dispatched = r.req.connection._bytesDispatched;
let percent = dispatched * 100.0 / size;
obj.bar1.update(percent, {
speed: ((dispatched / (Date.now() - obj.startTime)) / 125).toFixed(2) //kbits per sec
});
} else {
if (!uploadProgressBarErrorFlags.noConnectionReportSent) {
logger.debug(Constants.userMessages.NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR);
utils.sendUsageReport(
bsConfig,
null,
Constants.userMessages.NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR,
Constants.messageTypes.WARNING,
errorCode,
null,
null
);
uploadProgressBarErrorFlags.noConnectionReportSent = true;
}
}
} catch (error) {
if (!uploadProgressBarErrorFlags.unknownErrorReportSent) {
logger.debug('Unable to determine progress.');
logger.debug(error);
utils.sendUsageReport(
bsConfig,
null,
error.stack,
Constants.messageTypes.WARNING,
errorCode,
null,
null
);
uploadProgressBarErrorFlags.unknownErrorReportSent = true;
}
}
}, 150);

});
Expand Down