Skip to content

Commit b01d963

Browse files
Merge pull request #135 from LambdaTest/dev
2.4.6
2 parents 019edeb + fc278ca commit b01d963

File tree

5 files changed

+71
-47
lines changed

5 files changed

+71
-47
lines changed

commands/run.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,25 @@ module.exports = function (args) {
7575
.run_batches(lt_config, batches, env)
7676
.then(function (exit_code) {
7777
console.log("stopping tunnel");
78-
tunnelInstance.stop().then(function (done) {
79-
if (
80-
lt_config["run_settings"]["exit-on-failure"]
81-
) {
78+
tunnelInstance
79+
.stop()
80+
.then(function (done) {
81+
if (
82+
lt_config["run_settings"][
83+
"exit-on-failure"
84+
]
85+
) {
86+
process.exit(exit_code);
87+
}
88+
})
89+
.catch(function (error) {
90+
//At times Tunnel instance could not be stopped and
91+
//raised the error but this will stop tunnel automatically
92+
//after some time
93+
//Log error here for debugging
94+
console.log("");
8295
process.exit(exit_code);
83-
}
84-
});
96+
});
8597
})
8698
.catch(function (error) {
8799
console.log(

commands/utils/batch/batch_runner.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const request = require("request");
1111
const { del } = require("request");
1212
const { delete_archive } = require("../archive.js");
1313
const poller = require("../poller/poller.js");
14+
const builds = require("../poller/build");
15+
1416
var batchCounter = 0;
1517
var totalBatches = 0;
1618

@@ -113,7 +115,22 @@ async function run(lt_config, batches, env, i = 0) {
113115
.then(function (session_id) {
114116
delete_archive(project_file);
115117
delete_archive(file_obj["name"]);
116-
118+
//listen to control+c signal and stop tests
119+
process.on("SIGINT", async () => {
120+
try {
121+
console.log(
122+
"Control+c signal received.\nTrying to Terminate the processes"
123+
);
124+
await builds.stop_cypress_session(
125+
lt_config,
126+
session_id,
127+
env
128+
);
129+
resolve(0);
130+
} catch (e) {
131+
console.log("Could not exit process. Try Again!!!");
132+
}
133+
});
117134
if (
118135
lt_config["run_settings"]["sync"] == true ||
119136
lt_config["tunnel_settings"]["tunnel"] == true
@@ -125,7 +142,10 @@ async function run(lt_config, batches, env, i = 0) {
125142
resolve(exit_code);
126143
})
127144
.catch(function (err) {
128-
console.log();
145+
console.log(
146+
"Some error occured in getting build updates",
147+
err.message
148+
);
129149
});
130150
} else {
131151
resolve(0);

commands/utils/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module.exports = {
99
DEFAULT_TEST_PATH: ".",
1010
LAMBDA_CONFIG: "./lambdatest-config.json",
1111
SUPPORTED_CYPRESS_VERSIONS: ["5", "6"],
12-
BUILD_END_STATES: "&status=running,queued,created,initiated,pqueued",
12+
BUILD_END_STATES:
13+
"&status=running,queued,created,initiated,pqueued,error,lambda error,failed",
1314
BUILD_ERROR_STATES: "&status=error,lambda error,failed",
1415
CYPRESS_ENV_FILE_PATH: "cypress.env.json",
1516
ENVS: ["stage", "beta", "prod", "preprod"],

commands/utils/poller/build_stats.js

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,39 @@ function get_build_info(lt_config, session_id, env, update_status, callback) {
5050
update_status(false);
5151
return callback("Unauthorized");
5252
} else if (res.statusCode == "200") {
53-
resp = JSON.parse(body);
54-
if (resp["Meta"]["result_set"]["count"] == 0) {
53+
let statsNew = {
54+
running: 0,
55+
queued: 0,
56+
created: 0,
57+
initiated: 0,
58+
pqueued: 0,
59+
error: 0,
60+
"lambda error": 0,
61+
failed: 0,
62+
};
63+
let build_info = JSON.parse(body);
64+
if (build_info.Meta.result_set.count > 0) {
65+
for (i = 0; i < build_info["data"].length; i++) {
66+
statsNew[build_info["data"][i]["status_ind"]] += 1;
67+
}
68+
}
69+
if (
70+
statsNew["running"] +
71+
statsNew["queued"] +
72+
statsNew["created"] +
73+
statsNew["initiated"] +
74+
statsNew["pqueued"] ==
75+
0
76+
) {
5577
update_status(false);
5678
return callback(null, JSON.parse(body));
5779
}
5880
//Stop the tests if stop on failure is enabled and we get an errored/failed/lambda errored test
5981
if (lt_config.run_settings.stop_on_failure == true) {
60-
let response = await get_error_state(lt_config, session_id, env);
61-
if (response.count > 0) {
82+
if (
83+
statsNew["error"] + statsNew["lambda error"] + statsNew["failed"] >
84+
0
85+
) {
6286
await builds.stop_cypress_session(lt_config, session_id, env);
6387
}
6488
}
@@ -71,39 +95,6 @@ function get_build_info(lt_config, session_id, env, update_status, callback) {
7195
);
7296
}
7397

74-
function get_error_state(lt_config, session_id, env) {
75-
return new Promise(function (resolve, reject) {
76-
request(
77-
constants[env].SESSION_URL + session_id + constants.BUILD_ERROR_STATES,
78-
{
79-
auth: {
80-
username: lt_config["lambdatest_auth"]["username"],
81-
password: lt_config["lambdatest_auth"]["access_key"],
82-
},
83-
},
84-
(err, res, body) => {
85-
let response = { err: null, res_code: null, count: 0 };
86-
if (err) {
87-
console.log(err);
88-
response.err = err;
89-
response.res_code = 500;
90-
resolve(response);
91-
}
92-
response.res_code = res.statusCode;
93-
if (res.statusCode == "401") {
94-
response.err = "Unauthorized";
95-
resolve(response);
96-
} else if (res.statusCode == "200") {
97-
resp = JSON.parse(body);
98-
response.count = resp["Meta"]["result_set"]["count"];
99-
resolve(response);
100-
} else {
101-
resolve(response);
102-
}
103-
}
104-
);
105-
});
106-
}
10798
module.exports = {
10899
get_build_info: get_build_info,
109100
get_completed_build_info: get_completed_build_info,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lambdatest-cypress-cli",
3-
"version": "2.4.5",
3+
"version": "2.4.6",
44
"description": "The lambdatest-cypress-cli is LambdaTest's command-line interface (CLI) aimed to help you run your Cypress tests on LambdaTest platform.",
55
"homepage": "https://github.com/LambdaTest/lambdatest-cypress-cli",
66
"author": "LambdaTest <[email protected]>",

0 commit comments

Comments
 (0)