Skip to content

Commit 4c90710

Browse files
committed
fix: poll from v2 endpoint; display duration in the end
1 parent f14755b commit 4c90710

File tree

4 files changed

+96
-6
lines changed

4 files changed

+96
-6
lines changed

bin/helpers/config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ if(config.env !== "production") {
1313
}
1414

1515
config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`;
16+
config.cypress_v2 = `${config.rails_host}/automate/cypress/v2`;
1617
config.buildUrl = `${config.cypress_v1}/builds/`;
18+
config.buildUrlV2 = `${config.cypress_v2}/builds/`;
1719
config.buildStopUrl = `${config.cypress_v1}/builds/stop/`;
1820
config.checkMd5sum = `${config.cypress_v1}/md5sumcheck/`;
1921
config.getInitialDetails = `${config.cypress_v1}/get_initial_details/`;
@@ -24,3 +26,31 @@ config.retries = 5;
2426
config.networkErrorExitCode = 2;
2527

2628
module.exports = config;
29+
30+
31+
// Uncomment below or local testing
32+
33+
// var config = {};
34+
// config.env = "local";
35+
// var hosts = {
36+
// prod: {
37+
// uploadUrl: `https://api-cloud.browserstack.com/automate-frameworks/cypress/upload`,
38+
// rails_host: `https://api.browserstack.com`
39+
// },
40+
// local: {
41+
// uploadUrl: `http://localhost:4000/automate-frameworks/cypress/upload`,
42+
// rails_host: `https://api-local.bsstag.com`
43+
// }
44+
// };
45+
// config.uploadUrl = hosts[config.env].uploadUrl;
46+
// config.rails_host = hosts[config.env].rails_host;
47+
// config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`;
48+
// config.buildUrl = `${config.cypress_v1}/builds/`;
49+
// config.buildStopUrl = `${config.cypress_v1}/builds/stop/`;
50+
// config.usageReportingUrl = `http://127.0.0.1:8000/send_event_cy_internal`;
51+
// config.fileName = "tests.zip";
52+
// config.packageFileName = "bstackPackages.tar.gz";
53+
// config.packageDirName = "tmpBstackPackages";
54+
// config.retries = 5;
55+
// config.networkErrorExitCode = 2;
56+
// module.exports = config

bin/helpers/sync/specsSummary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let printSpecsRunSummary = (data, machines, customErrorsToPrint) => {
3333
});
3434

3535
logger.info(`Total tests: ${summary.total}, passed: ${summary.passed}, failed: ${summary.failed}, skipped: ${summary.skipped}, passed_with_skipped: ${summary.passed_with_skipped}, pending: ${summary.pending}`);
36-
logger.info(`Done in ${data.duration/1000} seconds using ${machines} machines\n`);
36+
// logger.info(`Done in ${data.duration/1000} seconds using ${machines} machines\n`);
3737

3838
if (customErrorsToPrint && customErrorsToPrint.length > 0) {
3939
for (const error of customErrorsToPrint) {

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (!isNaN(terminalWidth)) lineSeparator = "\n" + "-".repeat(terminalWidth);
2424

2525
let getOptions = (auth, build_id) => {
2626
return {
27-
url: `${config.buildUrl}${build_id}`,
27+
url: `${config.buildUrlV2}${build_id}`,
2828
auth: {
2929
user: auth.username,
3030
password: auth.access_key
@@ -144,18 +144,31 @@ let whileProcess = (whilstCallback) => {
144144

145145
whileTries = config.retries; // reset to default after every successful request
146146

147+
console.log(`---> response code: ${response.statusCode} body is: ${JSON.stringify(body)}`)
147148
switch (response.statusCode) {
148149
case 202: // get data here and print it
149150
n = 2
150-
showSpecsStatus(body);
151+
// try {
152+
// parsed_body = JSON.parse(JSON.stringify(body));
153+
// showSpecsStatus(parsed_body['data']);
154+
// } catch (error) {
155+
// console.log(`---> Got error: ${JSON.stringify(error)}`)
156+
// }
157+
showSpecsStatus(body, 202);
151158
return setTimeout(whilstCallback, timeout * n, null);
152159
case 204: // No data available, wait for some time and ask again
153160
n = 1
154161
return setTimeout(whilstCallback, timeout * n, null);
155162
case 200: // Build is completed.
156163
whileLoop = false;
157164
endTime = Date.now();
158-
showSpecsStatus(body);
165+
// try {
166+
// parsed_body = JSON.parse(body);
167+
// showSpecsStatus(JSON.stringify(parsed_body['data']));
168+
// } catch (error) {
169+
// console.log(`---> Got error: ${JSON.stringify(error)}`)
170+
// }
171+
showSpecsStatus(body, 200);
159172
return specSummary.exitCode == Constants.BUILD_FAILED_EXIT_CODE ?
160173
whilstCallback({ status: 204, message: "No specs ran in the build"} ) : whilstCallback(null, body);
161174
default:
@@ -169,9 +182,9 @@ let getStackTraceUrl = () => {
169182
return specSummary.buildError
170183
}
171184

172-
let showSpecsStatus = (data) => {
185+
let showSpecsStatus = (data, statusCode) => {
173186
let specData = JSON.parse(data);
174-
specData.forEach(specDetails => {
187+
specData["specDetails"].forEach(specDetails => {
175188
if (specDetails.type === Constants.CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY) {
176189
addCustomErrorToPrint(specDetails);
177190
} else {
@@ -190,6 +203,14 @@ let showSpecsStatus = (data) => {
190203
}
191204
}
192205
});
206+
if ( statusCode != 200 ) return;
207+
// Below block is for printing build details, return if non 200 status code
208+
if ("buildDetails" in specData) {
209+
const buildDetails = specData["buildDetails"];
210+
logger.info(`Done in ${buildDetails["duration"]} seconds with ${buildDetails["parallels"]} parallels.\n`);
211+
} else {
212+
logger.debug(`Build details not sent`)
213+
}
193214
}
194215

195216
let printInitialLog = () => {

bin/helpers/syncRunner.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
'use strict';
2+
const logger = require("./logger").syncCliLogger;
3+
const request = require('request');
24
const syncSpecsLogs = require('./sync/syncSpecsLogs'),
35
specDetails = require('./sync/failedSpecsDetails'),
6+
config = require("../helpers/config"),
7+
utils = require('./utils'),
48
specsSummary = require('./sync/specsSummary');
59

610
exports.pollBuildStatus = (bsConfig, buildDetails, rawArgs, buildReportData) => {
@@ -12,6 +16,41 @@ exports.pollBuildStatus = (bsConfig, buildDetails, rawArgs, buildReportData) =>
1216
}
1317
return specDetails.failedSpecsDetails(data);
1418
}).then((data) => {
19+
// logger.info(`--> data: ${JSON.stringify(data)}\n--> buildDetails: ${JSON.stringify(buildDetails)}\n-->${JSON.stringify(rawArgs)}`)
20+
// const buildId = buildDetails.build_id;
21+
// let options = {
22+
// url: config.buildUrl + buildId,
23+
// auth: {
24+
// user: bsConfig.auth.username,
25+
// password: bsConfig.auth.access_key,
26+
// },
27+
// headers: {
28+
// 'User-Agent': utils.getUserAgent(),
29+
// },
30+
// };
31+
// logger.info(`--> options: ${JSON.stringify(options)}`)
32+
// request.get(options, function (err, resp, body) {
33+
// logger.info(`\n\n--> build details body: ${JSON.stringify(body)}`)
34+
// let message = null;
35+
// let messageType = null;
36+
// let errorCode = null;
37+
// if (err) {
38+
// message = Constants.userMessages.BUILD_INFO_FAILED;
39+
// messageType = Constants.messageTypes.ERROR;
40+
// errorCode = 'api_failed_build_info';
41+
42+
// logger.info(message);
43+
// logger.error(utils.formatRequest(err, resp, body));
44+
// } else {
45+
// let build = null;
46+
// try {
47+
// build = JSON.parse(body);
48+
// } catch (error) {
49+
// build = null;
50+
// }
51+
// logger.info(`\n\n--> build details: ${JSON.stringify(build)}`)
52+
// }
53+
// });
1554
return specsSummary.printSpecsRunSummary(data, buildDetails.machines, customErrorsToPrint);
1655
}).then((successExitCode) => {
1756
resolve(successExitCode); // exit code 0

0 commit comments

Comments
 (0)