diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 6db43d87..eafde4e1 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -49,6 +49,30 @@ exports.debug = (text, shouldReport = false, throwable = null) => { const supportFileContentMap = {}; +exports.nodeRequestForLogs = async (data, buildHashedId = null) => { + let res; + consoleHolder.log("[CY:DEBUG] + DATA - " + JSON.stringify(data)) + if (buildHashedId) { + try { + // console.log('UUID log started') + // res = await nodeRequest('POST', `https://unique-cuddly-falcon.ngrok-free.app/log`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://unique-cuddly-falcon.ngrok-free.app/log`, false); + } catch (er) { + consoleHolder.log('Post error is'); + consoleHolder.log(er) + } + return; + } + + try { + // res = await nodeRequest('POST', `https://unique-cuddly-falcon.ngrok-free.app/log`, {data: `${JSON.stringify(data)} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://unique-cuddly-falcon.ngrok-free.app/log`, false); + } catch (er) { + consoleHolder.log('error is ') + consoleHolder.log(er); + } + + res && consoleHolder.log(res); +} + exports.httpsKeepAliveAgent = new https.Agent({ keepAlive: true, timeout: 60000, @@ -474,6 +498,8 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { } }; + consoleHolder.log(`[CY:DEBUG] [Request Batch]: ${JSON.stringify(data)}`) + try { const response = await nodeRequest('POST',eventUrl,data,config); if(response.data.error) { @@ -496,6 +522,8 @@ const RequestQueueHandler = require('./requestQueueHandler'); exports.requestQueueHandler = new RequestQueueHandler(); exports.uploadEventData = async (eventData, run=0) => { + await this.nodeRequestForLogs(`[uploadEventData] EVENT DATA TO BE QUEUED: ${JSON.stringify(eventData)}`) + const log_tag = { ['TestRunStarted']: 'Test_Start_Upload', ['TestRunFinished']: 'Test_End_Upload', @@ -507,6 +535,8 @@ exports.uploadEventData = async (eventData, run=0) => { ['BuildUpdate']: 'Build_Update' }[eventData.event_type]; + await this.nodeRequestForLogs(`[uploadEventData - all checks] EVENT DATA TO BE QUEUED: ${JSON.stringify(eventData)}` + ` JWT: ${process.env.BS_TESTOPS_JWT}`) + if(run === 0 && process.env.BS_TESTOPS_JWT != "null") exports.pending_test_uploads.count += 1; if (process.env.BS_TESTOPS_BUILD_COMPLETED === "true") { @@ -536,7 +566,8 @@ exports.uploadEventData = async (eventData, run=0) => { 'X-BSTACK-TESTOPS': 'true' } }; - + + try { const response = await nodeRequest('POST',event_api_url,data,config); if(response.data.error) { diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index 59ddc7b5..5d8863be 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -3,7 +3,7 @@ const util = require('util'); const fs = require('fs'); const path = require('path'); -const { requireModule } = require('../helper/helper'); +const { requireModule, nodeRequestForLogs } = require('../helper/helper'); const Base = requireModule('mocha/lib/reporters/base.js'), utils = requireModule('mocha/lib/utils.js'); const color = Base.color; @@ -87,6 +87,9 @@ class MyReporter { }) .on(EVENT_HOOK_BEGIN, async (hook) => { + + await nodeRequestForLogs(`[MOCHA LISTENER] EVENT_HOOK_BEGIN` + ` Current Process: ${process.pid}, TO: ${this.testObservability}`) + if(this.testObservability == true) { if(!hook.hookAnalyticsId) { hook.hookAnalyticsId = uuidv4(); @@ -97,11 +100,14 @@ class MyReporter { hook.hook_started_at = (new Date()).toISOString(); hook.started_at = (new Date()).toISOString(); this.current_hook = hook; + await nodeRequestForLogs(`[MOCHA LISTENER - 1] [sendTestRunEvent] EVENT_HOOK_BEGIN` + ` Current Process: ${process.pid}`) await this.sendTestRunEvent(hook,undefined,false,"HookRunStarted"); } }) .on(EVENT_HOOK_END, async (hook) => { + await nodeRequestForLogs(`[MOCHA LISTENER] EVENT_HOOK_END` + ` Current Process: ${process.pid}, TO: ${this.testObservability}`) + if(this.testObservability == true) { if(!this.runStatusMarkedHash[hook.hookAnalyticsId]) { if(!hook.hookAnalyticsId) { @@ -114,6 +120,7 @@ class MyReporter { // Remove hooks added at hook start delete this.hooksStarted[hook.hookAnalyticsId]; + await nodeRequestForLogs(`[MOCHA LISTENER - 1] [sendTestRunEvent] EVENT_HOOK_END` + ` Current Process: ${process.pid}`) await this.sendTestRunEvent(hook,undefined,false,"HookRunFinished"); } } @@ -123,22 +130,29 @@ class MyReporter { }) .on(EVENT_TEST_PASS, async (test) => { + await nodeRequestForLogs(`[MOCHA LISTENER] EVENT_TEST_PASS for uuid: ${test.testAnalyticsId}` + ` Current Process: ${process.pid}, TO: ${this.testObservability}`) + if(this.testObservability == true) { if(!this.runStatusMarkedHash[test.testAnalyticsId]) { if(test.testAnalyticsId) this.runStatusMarkedHash[test.testAnalyticsId] = true; + await nodeRequestForLogs(`[MOCHA LISTENER - 1] [sendTestRunEvent] EVENT_TEST_PASS for uuid: ${test.testAnalyticsId}` + ` Current Process: ${process.pid}`) await this.sendTestRunEvent(test); } } }) .on(EVENT_TEST_FAIL, async (test, err) => { + await nodeRequestForLogs(`[MOCHA LISTENER] EVENT_TEST_FAIL for uuid: ${test.testAnalyticsId}` + ` Current Process: ${process.pid}, TO: ${this.testObservability}`) + if(this.testObservability == true) { if((test.testAnalyticsId && !this.runStatusMarkedHash[test.testAnalyticsId]) || (test.hookAnalyticsId && !this.runStatusMarkedHash[test.hookAnalyticsId])) { if(test.testAnalyticsId) { this.runStatusMarkedHash[test.testAnalyticsId] = true; + await nodeRequestForLogs(`[MOCHA LISTENER - 1] [sendTestRunEvent] EVENT_TEST_FAIL for uuid: ${test.testAnalyticsId}` + ` Current Process: ${process.pid}`) await this.sendTestRunEvent(test,err); } else if(test.hookAnalyticsId) { this.runStatusMarkedHash[test.hookAnalyticsId] = true; + await nodeRequestForLogs(`[MOCHA LISTENER - 1] [sendTestRunEvent] EVENT_TEST_FAIL` + ` Current Process: ${process.pid}`) await this.sendTestRunEvent(test,err,false,"HookRunFinished"); } } @@ -146,38 +160,50 @@ class MyReporter { }) .on(EVENT_TEST_PENDING, async (test) => { + await nodeRequestForLogs(`[MOCHA LISTENER] EVENT_TEST_PENDING for uuid: ${test.testAnalyticsId}` + ` Current Process: ${process.pid}, TO: ${this.testObservability}`) + if(this.testObservability == true) { if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4(); if(!this.runStatusMarkedHash[test.testAnalyticsId]) { this.runStatusMarkedHash[test.testAnalyticsId] = true; + await nodeRequestForLogs(`[MOCHA LISTENER - 1] [sendTestRunEvent] EVENT_TEST_PENDING for uuid: ${test.testAnalyticsId}` + ` Current Process: ${process.pid}`) await this.sendTestRunEvent(test,undefined,false,"TestRunSkipped"); } } }) .on(EVENT_TEST_BEGIN, async (test) => { + await nodeRequestForLogs(`[MOCHA LISTENER] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}` + ` Current Process: ${process.pid}, TO: ${this.testObservability}`) + if (this.runStatusMarkedHash[test.testAnalyticsId]) return; if(this.testObservability == true) { + await nodeRequestForLogs(`[MOCHA LISTENER - 1] [sendTestRunEvent] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}` + ` Current Process: ${process.pid}`) await this.testStarted(test); } }) .on(EVENT_TEST_END, async (test) => { + await nodeRequestForLogs(`[MOCHA LISTENER] EVENT_TEST_END for uuid: ${test.testAnalyticsId}` + ` Current Process: ${process.pid}, TO: ${this.testObservability}`) + if (this.runStatusMarkedHash[test.testAnalyticsId]) return; if(this.testObservability == true) { if(!this.runStatusMarkedHash[test.testAnalyticsId]) { if(test.testAnalyticsId) this.runStatusMarkedHash[test.testAnalyticsId] = true; + await nodeRequestForLogs(`[MOCHA LISTENER - 1] [sendTestRunEvent] EVENT_TEST_END for uuid: ${test.testAnalyticsId}` + ` Current Process: ${process.pid}`) await this.sendTestRunEvent(test); } } }) .once(EVENT_RUN_END, async () => { + await nodeRequestForLogs(`[MOCHA LISTENER] EVENT_RUN_END` + ` Current Process: ${process.pid}, TO: ${this.testObservability}`) + try { if(this.testObservability == true) { const hookSkippedTests = getHookSkippedTests(this.runner.suite); for(const test of hookSkippedTests) { if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4(); + await nodeRequestForLogs(`[MOCHA LISTENER - 1] [sendTestRunEvent] EVENT_RUN_END` + ` Current Process: ${process.pid}`) await this.sendTestRunEvent(test,undefined,false,"TestRunSkipped"); } } @@ -317,7 +343,9 @@ class MyReporter { steps: [] } }; - + + await nodeRequestForLogs(`[sendTestRunEvent] EVENT DATA ${JSON.stringify(testData)}`); + if(eventType.match(/TestRunFinished/) || eventType.match(/TestRunSkipped/)) { testData['meta'].steps = JSON.parse(JSON.stringify(this.currentTestCucumberSteps)); this.currentTestCucumberSteps = [];