Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add log #854

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion bin/testObservability/helper/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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',
Expand All @@ -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") {
Expand Down Expand Up @@ -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) {
Expand Down
32 changes: 30 additions & 2 deletions bin/testObservability/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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");
}
}
Expand All @@ -123,61 +130,80 @@ 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");
}
}
}
})

.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");
}
}
Expand Down Expand Up @@ -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 = [];
Expand Down
Loading