Skip to content

Commit eedd758

Browse files
committed
add: debug logs for timeout
1 parent 839e6c7 commit eedd758

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

bin/testObservability/helper/helper.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const { promisify } = require('util');
99
const gitconfig = require('gitconfiglocal');
1010
const { spawn, execSync } = require('child_process');
1111
const glob = require('glob');
12+
const util = require('util');
13+
1214
const { runOptions } = require('../../helpers/runnerArgs')
1315

1416
const pGitconfig = promisify(gitconfig);
@@ -38,6 +40,13 @@ exports.pending_test_uploads = {
3840
count: 0
3941
};
4042

43+
exports.debugOnConsole = (text) => {
44+
if ((process.env.BROWSERSTACK_OBSERVABILITY_DEBUG + '') === "true" ||
45+
(process.env.BROWSERSTACK_OBSERVABILITY_DEBUG + '') === "1") {
46+
consoleHolder.log(`[ OBSERVABILITY ] ${text}`);
47+
}
48+
}
49+
4150
exports.debug = (text, shouldReport = false, throwable = null) => {
4251
if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
4352
logger.info(`[ OBSERVABILITY ] ${text}`);
@@ -475,14 +484,18 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => {
475484
};
476485

477486
try {
487+
const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', ');
488+
exports.debugOnConsole(`[Request Batch Send] for events:uuids ${eventsUuids}`);
478489
const response = await nodeRequest('POST',eventUrl,data,config);
490+
exports.debugOnConsole(`[Request Batch Response] for events:uuids ${eventsUuids}`);
479491
if(response.data.error) {
480492
throw({message: response.data.error});
481493
} else {
482494
exports.debug(`${kind} event successfull!`)
483495
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - data.length);
484496
}
485497
} catch(error) {
498+
exports.debugOnConsole(`[Request Error] Error in sending request ${util.format(error)}`);
486499
if (error.response) {
487500
exports.debug(`EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
488501
} else {
@@ -522,6 +535,7 @@ exports.uploadEventData = async (eventData, run=0) => {
522535

523536
exports.requestQueueHandler.start();
524537
const { shouldProceed, proceedWithData, proceedWithUrl } = exports.requestQueueHandler.add(eventData);
538+
exports.debugOnConsole(`[Request Queue] ${eventData.event_type} with uuid ${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)} is added`)
525539
if(!shouldProceed) {
526540
return;
527541
} else if(proceedWithData) {
@@ -538,7 +552,10 @@ exports.uploadEventData = async (eventData, run=0) => {
538552
};
539553

540554
try {
555+
const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', ');
556+
exports.debugOnConsole(`[Request Send] for events:uuids ${eventsUuids}`);
541557
const response = await nodeRequest('POST',event_api_url,data,config);
558+
exports.debugOnConsole(`[Request Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`)
542559
if(response.data.error) {
543560
throw({message: response.data.error});
544561
} else {
@@ -550,6 +567,7 @@ exports.uploadEventData = async (eventData, run=0) => {
550567
};
551568
}
552569
} catch(error) {
570+
exports.debugOnConsole(`[Request Error] Error in sending request ${util.format(error)}`);
553571
if (error.response) {
554572
exports.debug(`EXCEPTION IN ${event_api_url !== exports.requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
555573
} else {

bin/testObservability/reporter/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ const {
5757
getOSDetailsFromSystem,
5858
findGitConfig,
5959
getFileSeparatorData,
60-
setCrashReportingConfigFromReporter
60+
setCrashReportingConfigFromReporter,
61+
debugOnConsole
6162
} = require('../helper/helper');
6263

6364
const { consoleHolder } = require('../helper/constants');
@@ -123,7 +124,9 @@ class MyReporter {
123124
})
124125

125126
.on(EVENT_TEST_PASS, async (test) => {
127+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_PASS`);
126128
if(this.testObservability == true) {
129+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_PASS for uuid: ${test.testAnalyticsId}`);
127130
if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
128131
if(test.testAnalyticsId) this.runStatusMarkedHash[test.testAnalyticsId] = true;
129132
await this.sendTestRunEvent(test);
@@ -132,7 +135,9 @@ class MyReporter {
132135
})
133136

134137
.on(EVENT_TEST_FAIL, async (test, err) => {
138+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_FAIL`);
135139
if(this.testObservability == true) {
140+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_FAIL for uuid: ${test.testAnalyticsId}`);
136141
if((test.testAnalyticsId && !this.runStatusMarkedHash[test.testAnalyticsId]) || (test.hookAnalyticsId && !this.runStatusMarkedHash[test.hookAnalyticsId])) {
137142
if(test.testAnalyticsId) {
138143
this.runStatusMarkedHash[test.testAnalyticsId] = true;
@@ -146,8 +151,10 @@ class MyReporter {
146151
})
147152

148153
.on(EVENT_TEST_PENDING, async (test) => {
154+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_PENDING`);
149155
if(this.testObservability == true) {
150156
if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4();
157+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_PENDING for uuid: ${test.testAnalyticsId}`);
151158
if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
152159
this.runStatusMarkedHash[test.testAnalyticsId] = true;
153160
await this.sendTestRunEvent(test,undefined,false,"TestRunSkipped");
@@ -156,13 +163,17 @@ class MyReporter {
156163
})
157164

158165
.on(EVENT_TEST_BEGIN, async (test) => {
166+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_BEGIN`);
167+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`);
159168
if (this.runStatusMarkedHash[test.testAnalyticsId]) return;
160169
if(this.testObservability == true) {
161170
await this.testStarted(test);
162171
}
163172
})
164173

165174
.on(EVENT_TEST_END, async (test) => {
175+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_END`);
176+
debugOnConsole(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`);
166177
if (this.runStatusMarkedHash[test.testAnalyticsId]) return;
167178
if(this.testObservability == true) {
168179
if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
@@ -318,6 +329,8 @@ class MyReporter {
318329
}
319330
};
320331

332+
debugOnConsole(`${eventType} for uuid: ${testData.uuid}`);
333+
321334
if(eventType.match(/TestRunFinished/) || eventType.match(/TestRunSkipped/)) {
322335
testData['meta'].steps = JSON.parse(JSON.stringify(this.currentTestCucumberSteps));
323336
this.currentTestCucumberSteps = [];

0 commit comments

Comments
 (0)