Skip to content

Commit 60de54d

Browse files
Merge pull request #455 from browserstack/AFD-1532-null-check-while-updating-progress-bar
Add null check while updating progress bar
2 parents f14755b + 3383f10 commit 60de54d

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

bin/helpers/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ const userMessages = {
110110
"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",
111111
SPEC_LIMIT_SUCCESS_MESSAGE:
112112
"Spec timeout specified as <x> minutes. If any of your specs exceed the specified time limit, it would be forcibly killed by BrowserStack",
113+
NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR:
114+
"Unable to determine zip upload progress due to undefined/null connection request"
113115
};
114116

115117
const validationMessages = {

bin/helpers/zipUpload.js

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const purgeUploadBar = (obj) => {
2121

2222
const uploadSuits = (bsConfig, filePath, opts, obj) => {
2323
return new Promise(function (resolve, reject) {
24+
let uploadProgressBarErrorFlags = {
25+
noConnectionReportSent: false,
26+
unknownErrorReportSent: false
27+
};
2428
obj.startTime = Date.now();
2529

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

98102
obj.zipInterval = setInterval(function () {
99-
let dispatched = r.req.connection._bytesDispatched;
100-
let percent = dispatched * 100.0 / size;
101-
obj.bar1.update(percent, {
102-
speed: ((dispatched / (Date.now() - obj.startTime)) / 125).toFixed(2) //kbits per sec
103-
});
103+
const errorCode = 'update_upload_progress_bar_failed';
104+
try {
105+
if (r && r.req && r.req.connection) {
106+
let dispatched = r.req.connection._bytesDispatched;
107+
let percent = dispatched * 100.0 / size;
108+
obj.bar1.update(percent, {
109+
speed: ((dispatched / (Date.now() - obj.startTime)) / 125).toFixed(2) //kbits per sec
110+
});
111+
} else {
112+
if (!uploadProgressBarErrorFlags.noConnectionReportSent) {
113+
logger.debug(Constants.userMessages.NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR);
114+
utils.sendUsageReport(
115+
bsConfig,
116+
null,
117+
Constants.userMessages.NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR,
118+
Constants.messageTypes.WARNING,
119+
errorCode,
120+
null,
121+
null
122+
);
123+
uploadProgressBarErrorFlags.noConnectionReportSent = true;
124+
}
125+
}
126+
} catch (error) {
127+
if (!uploadProgressBarErrorFlags.unknownErrorReportSent) {
128+
logger.debug('Unable to determine progress.');
129+
logger.debug(error);
130+
utils.sendUsageReport(
131+
bsConfig,
132+
null,
133+
error.stack,
134+
Constants.messageTypes.WARNING,
135+
errorCode,
136+
null,
137+
null
138+
);
139+
uploadProgressBarErrorFlags.unknownErrorReportSent = true;
140+
}
141+
}
104142
}, 150);
105143

106144
});

0 commit comments

Comments
 (0)