Skip to content

Commit

Permalink
Merge pull request #135 from LambdaTest/dev
Browse files Browse the repository at this point in the history
2.4.6
  • Loading branch information
japneetlambdatest authored Apr 14, 2022
2 parents 019edeb + fc278ca commit b01d963
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 47 deletions.
24 changes: 18 additions & 6 deletions commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,25 @@ module.exports = function (args) {
.run_batches(lt_config, batches, env)
.then(function (exit_code) {
console.log("stopping tunnel");
tunnelInstance.stop().then(function (done) {
if (
lt_config["run_settings"]["exit-on-failure"]
) {
tunnelInstance
.stop()
.then(function (done) {
if (
lt_config["run_settings"][
"exit-on-failure"
]
) {
process.exit(exit_code);
}
})
.catch(function (error) {
//At times Tunnel instance could not be stopped and
//raised the error but this will stop tunnel automatically
//after some time
//Log error here for debugging
console.log("");
process.exit(exit_code);
}
});
});
})
.catch(function (error) {
console.log(
Expand Down
24 changes: 22 additions & 2 deletions commands/utils/batch/batch_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const request = require("request");
const { del } = require("request");
const { delete_archive } = require("../archive.js");
const poller = require("../poller/poller.js");
const builds = require("../poller/build");

var batchCounter = 0;
var totalBatches = 0;

Expand Down Expand Up @@ -113,7 +115,22 @@ async function run(lt_config, batches, env, i = 0) {
.then(function (session_id) {
delete_archive(project_file);
delete_archive(file_obj["name"]);

//listen to control+c signal and stop tests
process.on("SIGINT", async () => {
try {
console.log(
"Control+c signal received.\nTrying to Terminate the processes"
);
await builds.stop_cypress_session(
lt_config,
session_id,
env
);
resolve(0);
} catch (e) {
console.log("Could not exit process. Try Again!!!");
}
});
if (
lt_config["run_settings"]["sync"] == true ||
lt_config["tunnel_settings"]["tunnel"] == true
Expand All @@ -125,7 +142,10 @@ async function run(lt_config, batches, env, i = 0) {
resolve(exit_code);
})
.catch(function (err) {
console.log();
console.log(
"Some error occured in getting build updates",
err.message
);
});
} else {
resolve(0);
Expand Down
3 changes: 2 additions & 1 deletion commands/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = {
DEFAULT_TEST_PATH: ".",
LAMBDA_CONFIG: "./lambdatest-config.json",
SUPPORTED_CYPRESS_VERSIONS: ["5", "6"],
BUILD_END_STATES: "&status=running,queued,created,initiated,pqueued",
BUILD_END_STATES:
"&status=running,queued,created,initiated,pqueued,error,lambda error,failed",
BUILD_ERROR_STATES: "&status=error,lambda error,failed",
CYPRESS_ENV_FILE_PATH: "cypress.env.json",
ENVS: ["stage", "beta", "prod", "preprod"],
Expand Down
65 changes: 28 additions & 37 deletions commands/utils/poller/build_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,39 @@ function get_build_info(lt_config, session_id, env, update_status, callback) {
update_status(false);
return callback("Unauthorized");
} else if (res.statusCode == "200") {
resp = JSON.parse(body);
if (resp["Meta"]["result_set"]["count"] == 0) {
let statsNew = {
running: 0,
queued: 0,
created: 0,
initiated: 0,
pqueued: 0,
error: 0,
"lambda error": 0,
failed: 0,
};
let build_info = JSON.parse(body);
if (build_info.Meta.result_set.count > 0) {
for (i = 0; i < build_info["data"].length; i++) {
statsNew[build_info["data"][i]["status_ind"]] += 1;
}
}
if (
statsNew["running"] +
statsNew["queued"] +
statsNew["created"] +
statsNew["initiated"] +
statsNew["pqueued"] ==
0
) {
update_status(false);
return callback(null, JSON.parse(body));
}
//Stop the tests if stop on failure is enabled and we get an errored/failed/lambda errored test
if (lt_config.run_settings.stop_on_failure == true) {
let response = await get_error_state(lt_config, session_id, env);
if (response.count > 0) {
if (
statsNew["error"] + statsNew["lambda error"] + statsNew["failed"] >
0
) {
await builds.stop_cypress_session(lt_config, session_id, env);
}
}
Expand All @@ -71,39 +95,6 @@ function get_build_info(lt_config, session_id, env, update_status, callback) {
);
}

function get_error_state(lt_config, session_id, env) {
return new Promise(function (resolve, reject) {
request(
constants[env].SESSION_URL + session_id + constants.BUILD_ERROR_STATES,
{
auth: {
username: lt_config["lambdatest_auth"]["username"],
password: lt_config["lambdatest_auth"]["access_key"],
},
},
(err, res, body) => {
let response = { err: null, res_code: null, count: 0 };
if (err) {
console.log(err);
response.err = err;
response.res_code = 500;
resolve(response);
}
response.res_code = res.statusCode;
if (res.statusCode == "401") {
response.err = "Unauthorized";
resolve(response);
} else if (res.statusCode == "200") {
resp = JSON.parse(body);
response.count = resp["Meta"]["result_set"]["count"];
resolve(response);
} else {
resolve(response);
}
}
);
});
}
module.exports = {
get_build_info: get_build_info,
get_completed_build_info: get_completed_build_info,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lambdatest-cypress-cli",
"version": "2.4.5",
"version": "2.4.6",
"description": "The lambdatest-cypress-cli is LambdaTest's command-line interface (CLI) aimed to help you run your Cypress tests on LambdaTest platform.",
"homepage": "https://github.com/LambdaTest/lambdatest-cypress-cli",
"author": "LambdaTest <[email protected]>",
Expand Down

0 comments on commit b01d963

Please sign in to comment.