Skip to content

Commit 13af79a

Browse files
committed
update: stability improvements
1 parent 174fb9c commit 13af79a

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

bin/commands/runs.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ module.exports = function run(args, rawArgs) {
111111
/*
112112
Send build start to Observability
113113
*/
114-
if(isTestObservabilitySession) await launchTestSession(bsConfig, bsConfigPath);
114+
if(isTestObservabilitySession) {
115+
await launchTestSession(bsConfig, bsConfigPath);
116+
utils.setO11yProcessHooks(null, bsConfig, args, null, buildReportData);
117+
}
115118

116119
// accept the system env list from bsconf and set it
117120
utils.setSystemEnvs(bsConfig);
@@ -264,6 +267,9 @@ module.exports = function run(args, rawArgs) {
264267
markBlockEnd('createBuild');
265268
markBlockEnd('total');
266269
utils.setProcessHooks(data.build_id, bsConfig, bs_local, args, buildReportData);
270+
if(isTestObservabilitySession) {
271+
utils.setO11yProcessHooks(data.build_id, bsConfig, bs_local, args, buildReportData);
272+
}
267273
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
268274
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`;
269275
buildReportData = { 'build_id': data.build_id, 'parallels': userSpecifiedParallels, ...buildReportData }

bin/helpers/utils.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,8 +1451,24 @@ exports.setProcessHooks = (buildId, bsConfig, bsLocal, args, buildReportData) =>
14511451
process.on('SIGTERM', processExitHandler.bind(this, bindData));
14521452
process.on('SIGBREAK', processExitHandler.bind(this, bindData));
14531453
process.on('uncaughtException', processExitHandler.bind(this, bindData));
1454+
process.on('beforeExit', processO11yExitHandler.bind(this, bindData));
14541455
}
14551456

1457+
exports.setO11yProcessHooks = (() => {
1458+
let bindData = {};
1459+
let handlerAdded = false;
1460+
return (buildId, bsConfig, bsLocal, args, buildReportData) => {
1461+
bindData.buildId = buildId;
1462+
bindData.bsConfig = bsConfig;
1463+
bindData.bsLocal = bsLocal;
1464+
bindData.args = args;
1465+
bindData.buildReportData = buildReportData;
1466+
if (handlerAdded) return;
1467+
handlerAdded = true;
1468+
process.on('beforeExit', processO11yExitHandler.bind(this, bindData));
1469+
}
1470+
})()
1471+
14561472
async function processExitHandler(exitData){
14571473
logger.warn(Constants.userMessages.PROCESS_KILL_MESSAGE);
14581474
await this.stopBrowserStackBuild(exitData.bsConfig, exitData.args, exitData.buildId, null, exitData.buildReportData);
@@ -1461,6 +1477,14 @@ async function processExitHandler(exitData){
14611477
process.exit(0);
14621478
}
14631479

1480+
async function processO11yExitHandler(exitData){
1481+
if (!exitData.buildId && args.async) {
1482+
await printBuildLink(false);
1483+
} else {
1484+
await printBuildLink(true);
1485+
}
1486+
}
1487+
14641488
exports.fetchZipSize = (fileName) => {
14651489
try {
14661490
let stats = fs.statSync(fileName)

bin/testObservability/helper/helper.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ const supportFileCleanup = () => {
6464
});
6565
}
6666

67+
exports.buildStopped = false;
68+
6769
exports.printBuildLink = async (shouldStopSession, exitCode = null) => {
68-
if(!this.isTestObservabilitySession()) return;
70+
if(!this.isTestObservabilitySession() || exports.buildStopped) return;
71+
exports.buildStopped = true;
6972
try {
7073
if(shouldStopSession) {
7174
supportFileCleanup();
@@ -472,6 +475,10 @@ const RequestQueueHandler = require('./requestQueueHandler');
472475
exports.requestQueueHandler = new RequestQueueHandler();
473476

474477
exports.uploadEventData = async (eventData, run=0) => {
478+
exports.debug("I aminside upload event data")
479+
exports.debug(JSON.stringify(eventData))
480+
consoleHolder.log("I aminside upload event data")
481+
consoleHolder.log(JSON.stringify(eventData))
475482
const log_tag = {
476483
['TestRunStarted']: 'Test_Start_Upload',
477484
['TestRunFinished']: 'Test_End_Upload',

bin/testObservability/reporter/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class MyReporter {
9393
delete this.runStatusMarkedHash[hook.hookAnalyticsId];
9494
hook.hookAnalyticsId = uuidv4();
9595
}
96+
console.log("At hook begin ", hook.hookAnalyticsId + hook.fullTitle())
9697
hook.hook_started_at = (new Date()).toISOString();
9798
hook.started_at = (new Date()).toISOString();
9899
this.current_hook = hook;
@@ -101,7 +102,9 @@ class MyReporter {
101102
})
102103

103104
.on(EVENT_HOOK_END, async (hook) => {
105+
console.log("At hook end ", this.current_hook.hookAnalyticsId, hook.fullTitle())
104106
if(this.testObservability == true) {
107+
// console.log("At hook end bool", this.runStatusMarkedHash[hook.hookAnalyticsId])
105108
if(!this.runStatusMarkedHash[hook.hookAnalyticsId]) {
106109
if(!hook.hookAnalyticsId) {
107110
/* Hook objects don't maintain uuids in Cypress-Mocha */
@@ -110,6 +113,7 @@ class MyReporter {
110113
} else {
111114
this.runStatusMarkedHash[hook.hookAnalyticsId] = true;
112115
}
116+
console.log("Sending hook finished ", hook.hookAnalyticsId);
113117
await this.sendTestRunEvent(hook,undefined,false,"HookRunFinished");
114118
}
115119
}
@@ -143,21 +147,27 @@ class MyReporter {
143147

144148
.on(EVENT_TEST_PENDING, async (test) => {
145149
if(this.testObservability == true) {
150+
test.isSkipped = true;
146151
if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4();
147152
if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
148153
this.runStatusMarkedHash[test.testAnalyticsId] = true;
154+
consoleHolder.log("Inside event for event_test_pending " + test.state);
149155
await this.sendTestRunEvent(test,undefined,false,"TestRunSkipped");
150156
}
151157
}
152158
})
153159

154160
.on(EVENT_TEST_BEGIN, async (test) => {
161+
consoleHolder.log("Inside event for event_test_begin " + test.state + " " + test.isSkipped);
162+
if (test.isSkipped) return;
155163
if(this.testObservability == true) {
156164
await this.testStarted(test);
157165
}
158166
})
159167

160168
.on(EVENT_TEST_END, async (test) => {
169+
consoleHolder.log("Inside event for event_test_end " + test.state + " " + test.isSkipped);
170+
if (test.isSkipped) return;
161171
if(this.testObservability == true) {
162172
if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
163173
if(test.testAnalyticsId) this.runStatusMarkedHash[test.testAnalyticsId] = true;
@@ -253,6 +263,8 @@ class MyReporter {
253263
}
254264

255265
sendTestRunEvent = async (test, err = undefined, customFinished=false, eventType = "TestRunFinished") => {
266+
debug("Sending test run event for " + eventType);
267+
consoleHolder.log("Sending test run event for " + eventType)
256268
try {
257269
if(test.body && test.body.match(/browserstack internal helper hook/)) return;
258270
let failureArgs = [];

0 commit comments

Comments
 (0)