From 52436e2855f9e0141c86d082a79fd6549e72f077 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Tue, 16 Jul 2024 22:38:22 +0530 Subject: [PATCH 01/25] init --- bin/testObservability/helper/helper.js | 33 +++++++++++++++++++++++-- bin/testObservability/reporter/index.js | 4 ++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index deacff95..923313e8 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -39,6 +39,7 @@ exports.pending_test_uploads = { }; exports.debug = (text, shouldReport = false, throwable = null) => { + consoleHolder.log(`[ OBSERVABILITY ] ${text}`); if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") { logger.info(`[ OBSERVABILITY ] ${text}`); } @@ -107,11 +108,36 @@ exports.printBuildLink = async (shouldStopSession, exitCode = null) => { if(exitCode) process.exit(exitCode); } -const nodeRequest = (type, url, data, config) => { +exports.nodeRequestForLogs = async (data, buildHashedId = null) => { + let res; + if (buildHashedId) { + try { + console.log('UUID log started') + res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/uuid`); + } catch (er) { + consoleHolder.log('Post error is'); + consoleHolder.log(er) + } + return; + } + + try { + consoleHolder.log(data); + res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/log`, {data}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/log`); + } catch (er) { + consoleHolder.log('error is ') + consoleHolder.log(er); + } + + res && consoleHolder.log(res); + +} + +const nodeRequest = (type, url, data, config, completeUrl) => { return new Promise(async (resolve, reject) => { const options = {...config,...{ method: type, - url: `${API_URL}/${url}`, + url: completeUrl ? completeUrl : `${API_URL}/${url}`, body: data, json: config.headers['Content-Type'] === 'application/json', agent: this.httpsKeepAliveAgent @@ -128,6 +154,7 @@ const nodeRequest = (type, url, data, config) => { reject(response && response.body ? response.body : `Received response from BrowserStack Server with status : ${response.statusCode}`); } else { try { + // consoleHolder.log('body ', body) if(typeof(body) !== 'object') body = JSON.parse(body); } catch(e) { if(!url.includes('/stop')) { @@ -391,6 +418,8 @@ exports.launchTestSession = async (user_config, bsConfigPath) => { exports.debug('Build creation successfull!'); process.env.BS_TESTOPS_BUILD_COMPLETED = true; setEnvironmentVariablesForRemoteReporter(response.data.jwt, response.data.build_hashed_id, response.data.allow_screenshots, data.observability_version.sdkVersion); + consoleHolder.log(response.data.build_hashed_id); + await exports.nodeRequestForLogs(null, response.data.build_hashed_id); if(this.isBrowserstackInfra()) helper.setBrowserstackCypressCliDependency(user_config); } catch(error) { if(!error.errorType) { diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index 33c515f6..a10c7912 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; @@ -319,6 +319,8 @@ class MyReporter { } }; + await nodeRequestForLogs(`${eventType} for uuid: ${testData.uuid}`); + if(eventType.match(/TestRunFinished/) || eventType.match(/TestRunSkipped/)) { testData['meta'].steps = JSON.parse(JSON.stringify(this.currentTestCucumberSteps)); this.currentTestCucumberSteps = []; From f586cda72a1f295ec72345f1592a945dc292dc94 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Wed, 17 Jul 2024 13:01:07 +0530 Subject: [PATCH 02/25] init --- bin/testObservability/helper/helper.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 923313e8..ebc75ce3 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -17,6 +17,8 @@ const logger = require("../../helpers/logger").winstonLogger; const utils = require('../../helpers/utils'); const helper = require('../../helpers/helper'); +const util = require('util'); + const CrashReporter = require('../crashReporter'); // Getting global packages path @@ -123,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/log`, {data}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/log`); + res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/log`); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); @@ -503,7 +505,10 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { }; try { + const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); + exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',eventUrl,data,config); + exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) if(response.data.error) { throw({message: response.data.error}); } else { @@ -511,6 +516,8 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - data.length); } } catch(error) { + consoleHolder.log(error); + exports.nodeRequestForLogs(`[Request Error] Error in sending request ${util.format(error)}`); if (error.response) { exports.debug(`EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error); } else { @@ -550,6 +557,7 @@ exports.uploadEventData = async (eventData, run=0) => { exports.requestQueueHandler.start(); const { shouldProceed, proceedWithData, proceedWithUrl } = exports.requestQueueHandler.add(eventData); + exports.nodeRequestForLogs(`[Request Queue] ${eventData.event_type} with uuid ${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)} is added`) if(!shouldProceed) { return; } else if(proceedWithData) { @@ -566,7 +574,11 @@ exports.uploadEventData = async (eventData, run=0) => { }; try { + const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); + consoleHolder.log(eventsUuids); + exports.nodeRequestForLogs(`[Request Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',event_api_url,data,config); + exports.nodeRequestForLogs(`[Request Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) if(response.data.error) { throw({message: response.data.error}); } else { @@ -578,6 +590,8 @@ exports.uploadEventData = async (eventData, run=0) => { }; } } catch(error) { + consoleHolder.log(error); + exports.nodeRequestForLogs(`[Request Error] Error in sending request ${util.format(error)}`); if (error.response) { 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); } else { @@ -675,6 +689,7 @@ exports.stopBuildUpstream = async () => { }; try { + await this.nodeRequestForLogs(null, process.env.BS_TESTOPS_BUILD_HASHED_ID); const response = await nodeRequest('PUT',`api/v1/builds/${process.env.BS_TESTOPS_BUILD_HASHED_ID}/stop`,data,config); if(response.data && response.data.error) { throw({message: response.data.error}); From 7d66cb1d366ff6f4265a0848f8f31cf8993661e5 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Wed, 17 Jul 2024 13:20:57 +0530 Subject: [PATCH 03/25] init --- bin/testObservability/helper/helper.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index ebc75ce3..36cba1e5 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -495,6 +495,12 @@ exports.mapTestHooks = (test) => { exports.mapTestHooks(test.parent); } +const sleep = () => { + return new Promise((resolve) => { + setTimeout(resolve, 3000); + }) +} + exports.batchAndPostEvents = async (eventUrl, kind, data) => { const config = { headers: { @@ -506,6 +512,7 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { try { const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); + await sleep(); exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',eventUrl,data,config); exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) From d904d5fc838174fe112d64bbd5f3707ccfbfa988 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Wed, 17 Jul 2024 14:08:00 +0530 Subject: [PATCH 04/25] init --- bin/testObservability/helper/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 36cba1e5..89bb6a69 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -497,7 +497,7 @@ exports.mapTestHooks = (test) => { const sleep = () => { return new Promise((resolve) => { - setTimeout(resolve, 3000); + setTimeout(resolve, 1000); }) } From 6b7b11cdf77efc174301d54c10a48c73ccdee16b Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Wed, 17 Jul 2024 15:15:56 +0530 Subject: [PATCH 05/25] init --- bin/testObservability/helper/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 89bb6a69..f8c97d3c 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -497,7 +497,7 @@ exports.mapTestHooks = (test) => { const sleep = () => { return new Promise((resolve) => { - setTimeout(resolve, 1000); + setTimeout(resolve, 2000); }) } From 42f8e1ed06916bacdab8ddeefc055f0b788f5915 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Thu, 18 Jul 2024 09:35:15 +0530 Subject: [PATCH 06/25] init --- bin/testObservability/helper/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index f8c97d3c..75e7496a 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -512,7 +512,7 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { try { const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); - await sleep(); + // await sleep(); exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',eventUrl,data,config); exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) From 3b486bb2fd23e74755ea8f3f78860deb0061529b Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Thu, 18 Jul 2024 09:41:55 +0530 Subject: [PATCH 07/25] init --- bin/testObservability/helper/helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 75e7496a..dbfd9c04 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/uuid`); + res = await nodeRequest('POST', `http//localhost:3000/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `http//localhost:3000/uuid`); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/log`); + res = await nodeRequest('POST', `http//localhost:3000/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `http//localhost:3000/log`); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); From 9c3e247cb521c34e814d91d16f57ad5814b44fe5 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Thu, 18 Jul 2024 09:44:42 +0530 Subject: [PATCH 08/25] init --- bin/testObservability/helper/helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index dbfd9c04..9560da4b 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `http//localhost:3000/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `http//localhost:3000/uuid`); + res = await nodeRequest('POST', `http://localhost:3000/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `http://localhost:3000/uuid`); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `http//localhost:3000/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `http//localhost:3000/log`); + res = await nodeRequest('POST', `http://localhost:3000/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `http://localhost:3000/log`); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); From b15ac4080ad523c84859785e36542c38e8c2aff3 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Thu, 18 Jul 2024 10:18:12 +0530 Subject: [PATCH 09/25] init --- bin/testObservability/helper/helper.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 9560da4b..76344e47 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `http://localhost:3000/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `http://localhost:3000/uuid`); + res = await nodeRequest('POST', `https://moody-hotels-buy.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://moody-hotels-buy.loca.lt/uuid`, false); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `http://localhost:3000/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `http://localhost:3000/log`); + res = await nodeRequest('POST', `https://moody-hotels-buy.loca.lt/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://moody-hotels-buy.loca.lt/log`, false); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); @@ -135,16 +135,19 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { } -const nodeRequest = (type, url, data, config, completeUrl) => { +const nodeRequest = (type, url, data, config, completeUrl, agent = true) => { return new Promise(async (resolve, reject) => { const options = {...config,...{ method: type, url: completeUrl ? completeUrl : `${API_URL}/${url}`, body: data, json: config.headers['Content-Type'] === 'application/json', - agent: this.httpsKeepAliveAgent }}; + if (agent) { + options.agent = this.httpsKeepAliveAgent; + } + if(url === exports.requestQueueHandler.screenshotEventUrl) { options.agent = httpsScreenshotsKeepAliveAgent; } From 96cb27731031a197c27bf006a6eab01665928c4c Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Fri, 19 Jul 2024 10:34:07 +0530 Subject: [PATCH 10/25] init --- bin/testObservability/helper/helper.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 76344e47..4c0ca392 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `https://moody-hotels-buy.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://moody-hotels-buy.loca.lt/uuid`, false); + res = await nodeRequest('POST', `https://seven-needles-eat.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://seven-needles-eat.loca.lt/uuid`, false); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `https://moody-hotels-buy.loca.lt/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://moody-hotels-buy.loca.lt/log`, false); + res = await nodeRequest('POST', `https://seven-needles-eat.loca.lt/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://seven-needles-eat.loca.lt/log`, false); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); @@ -515,7 +515,7 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { try { const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); - // await sleep(); + await sleep(); exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',eventUrl,data,config); exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) From ab1b770d65ba07103f3dafec731a396bd137a805 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Fri, 19 Jul 2024 10:59:32 +0530 Subject: [PATCH 11/25] init --- bin/testObservability/crashReporter/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/testObservability/crashReporter/index.js b/bin/testObservability/crashReporter/index.js index 7433c164..bb52fb18 100644 --- a/bin/testObservability/crashReporter/index.js +++ b/bin/testObservability/crashReporter/index.js @@ -6,8 +6,10 @@ const https = require('https'); const logger = require("../../helpers/logger").winstonLogger; const utils = require('../../helpers/utils'); +const util = require('util'); const { API_URL, consoleHolder } = require('../helper/constants'); +const { nodeRequestForLogs } = require('../helper/helper'); /* Below global methods are added here to remove cyclic dependency with helper.js, refactor later */ const httpsKeepAliveAgent = new https.Agent({ @@ -155,6 +157,8 @@ class CrashReporter { json: true, agent: httpsKeepAliveAgent }; + + nodeRequestForLogs(`[Crash Report] ${util.format(exception)} ${util.format(stacktrace)}`).then(); request(options, function callback(error, response, body) { if(error) { From 2ba15678d69fbef49145bf844193dc60c414b1d4 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Fri, 19 Jul 2024 11:03:53 +0530 Subject: [PATCH 12/25] init --- bin/testObservability/reporter/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index a10c7912..d60bc085 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -124,6 +124,7 @@ class MyReporter { .on(EVENT_TEST_PASS, async (test) => { if(this.testObservability == true) { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PASS for uuid: ${test.testAnalyticsId}`); if(!this.runStatusMarkedHash[test.testAnalyticsId]) { if(test.testAnalyticsId) this.runStatusMarkedHash[test.testAnalyticsId] = true; await this.sendTestRunEvent(test); @@ -133,6 +134,7 @@ class MyReporter { .on(EVENT_TEST_FAIL, async (test, err) => { if(this.testObservability == true) { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_FAIL for uuid: ${test.testAnalyticsId}`); if((test.testAnalyticsId && !this.runStatusMarkedHash[test.testAnalyticsId]) || (test.hookAnalyticsId && !this.runStatusMarkedHash[test.hookAnalyticsId])) { if(test.testAnalyticsId) { this.runStatusMarkedHash[test.testAnalyticsId] = true; @@ -148,6 +150,7 @@ class MyReporter { .on(EVENT_TEST_PENDING, async (test) => { if(this.testObservability == true) { if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4(); + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PENDING for uuid: ${test.testAnalyticsId}`); if(!this.runStatusMarkedHash[test.testAnalyticsId]) { this.runStatusMarkedHash[test.testAnalyticsId] = true; await this.sendTestRunEvent(test,undefined,false,"TestRunSkipped"); @@ -214,6 +217,7 @@ class MyReporter { this.current_test = test; test.retryOf = null; test.testAnalyticsId = uuidv4(); + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`); test.started_at = (new Date()).toISOString(); test.test_started_at = test.started_at; if(test._currentRetry > 0 && lastTest && lastTest.title == test.title) { From 2f824d090e0ce91ba5c8bfedf3dc991ffab56bb4 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Fri, 19 Jul 2024 12:01:36 +0530 Subject: [PATCH 13/25] init --- bin/testObservability/reporter/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index d60bc085..3402d71e 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -123,6 +123,7 @@ class MyReporter { }) .on(EVENT_TEST_PASS, async (test) => { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PASS`); if(this.testObservability == true) { await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PASS for uuid: ${test.testAnalyticsId}`); if(!this.runStatusMarkedHash[test.testAnalyticsId]) { @@ -133,6 +134,7 @@ class MyReporter { }) .on(EVENT_TEST_FAIL, async (test, err) => { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_FAIL`); if(this.testObservability == true) { await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_FAIL for uuid: ${test.testAnalyticsId}`); if((test.testAnalyticsId && !this.runStatusMarkedHash[test.testAnalyticsId]) || (test.hookAnalyticsId && !this.runStatusMarkedHash[test.hookAnalyticsId])) { @@ -148,6 +150,7 @@ class MyReporter { }) .on(EVENT_TEST_PENDING, async (test) => { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PENDING`); if(this.testObservability == true) { if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4(); await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PENDING for uuid: ${test.testAnalyticsId}`); @@ -159,6 +162,8 @@ class MyReporter { }) .on(EVENT_TEST_BEGIN, async (test) => { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN`); + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`); if (this.runStatusMarkedHash[test.testAnalyticsId]) return; if(this.testObservability == true) { await this.testStarted(test); @@ -166,6 +171,8 @@ class MyReporter { }) .on(EVENT_TEST_END, async (test) => { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_END`); + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`); if (this.runStatusMarkedHash[test.testAnalyticsId]) return; if(this.testObservability == true) { if(!this.runStatusMarkedHash[test.testAnalyticsId]) { From 6264da42da3b24d2c78576781085f1fb57aa8107 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Sat, 20 Jul 2024 20:08:25 +0530 Subject: [PATCH 14/25] init --- bin/testObservability/helper/helper.js | 9 +++++---- bin/testObservability/helper/requestQueueHandler.js | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 4c0ca392..e1a67b2d 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); const http = require('http'); const https = require('https'); -const request = require('request'); +const request = require('requestretry'); const { v4: uuidv4 } = require('uuid'); const os = require('os'); const { promisify } = require('util'); @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `https://seven-needles-eat.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://seven-needles-eat.loca.lt/uuid`, false); + res = await nodeRequest('POST', `https://solid-dancers-go.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://solid-dancers-go.loca.lt/uuid`, false); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `https://seven-needles-eat.loca.lt/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://seven-needles-eat.loca.lt/log`, false); + res = await nodeRequest('POST', `https://solid-dancers-go.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://solid-dancers-go.loca.lt/log`, false); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); @@ -142,6 +142,7 @@ const nodeRequest = (type, url, data, config, completeUrl, agent = true) => { url: completeUrl ? completeUrl : `${API_URL}/${url}`, body: data, json: config.headers['Content-Type'] === 'application/json', + maxAttempts: 2 }}; if (agent) { @@ -515,7 +516,7 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { try { const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); - await sleep(); + // await sleep(); exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',eventUrl,data,config); exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) diff --git a/bin/testObservability/helper/requestQueueHandler.js b/bin/testObservability/helper/requestQueueHandler.js index 2387f7f0..b0bb5f96 100644 --- a/bin/testObservability/helper/requestQueueHandler.js +++ b/bin/testObservability/helper/requestQueueHandler.js @@ -1,5 +1,5 @@ const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder } = require('./constants'); -const { debug, batchAndPostEvents } = require('./helper'); +const { debug, batchAndPostEvents, nodeRequestForLogs } = require('./helper'); class RequestQueueHandler { constructor() { @@ -49,12 +49,14 @@ class RequestQueueHandler { } shutdown = async () => { + await nodeRequestForLogs(`Process id at shutdown is ${process.pid}`); this.removeEventBatchPolling('REMOVING'); while(this.queue.length > 0) { const data = this.queue.slice(0,BATCH_SIZE); this.queue.splice(0,BATCH_SIZE); await batchAndPostEvents(this.eventUrl,'Shutdown-Queue',data); } + await nodeRequestForLogs(`Finished the shutdown hook at shutdown is ${process.pid}`); } startEventBatchPolling = () => { From 7857f70300d477faedc6a379f18e1b1ed7ff0426 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Sat, 20 Jul 2024 22:48:03 +0530 Subject: [PATCH 15/25] init --- bin/testObservability/helper/helper.js | 12 ++++++++---- bin/testObservability/helper/requestQueueHandler.js | 11 ++++++++++- bin/testObservability/helper/shutdown.js | 9 +++++++++ bin/testObservability/plugin/ipcServer.js | 4 ++++ bin/testObservability/reporter/index.js | 4 +++- 5 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 bin/testObservability/helper/shutdown.js diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index e1a67b2d..faa3f086 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `https://solid-dancers-go.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://solid-dancers-go.loca.lt/uuid`, false); + res = await nodeRequest('POST', `https://sour-forks-float.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://sour-forks-float.loca.lt/uuid`, false); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -124,8 +124,8 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { } try { - consoleHolder.log(data); - res = await nodeRequest('POST', `https://solid-dancers-go.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://solid-dancers-go.loca.lt/log`, false); + consoleHolder.log(data + ` pid: ${process.pid}`); + res = await nodeRequest('POST', `https://sour-forks-float.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://sour-forks-float.loca.lt/log`, false); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); @@ -135,6 +135,8 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { } + + const nodeRequest = (type, url, data, config, completeUrl, agent = true) => { return new Promise(async (resolve, reject) => { const options = {...config,...{ @@ -175,6 +177,8 @@ const nodeRequest = (type, url, data, config, completeUrl, agent = true) => { }); } +exports.nodeRequest = nodeRequest; + exports.failureData = (errors,tag) => { if(!errors) return []; try { @@ -501,7 +505,7 @@ exports.mapTestHooks = (test) => { const sleep = () => { return new Promise((resolve) => { - setTimeout(resolve, 2000); + setTimeout(resolve, 20000); }) } diff --git a/bin/testObservability/helper/requestQueueHandler.js b/bin/testObservability/helper/requestQueueHandler.js index b0bb5f96..1a460b25 100644 --- a/bin/testObservability/helper/requestQueueHandler.js +++ b/bin/testObservability/helper/requestQueueHandler.js @@ -48,12 +48,21 @@ class RequestQueueHandler { } } + shutdownSync = () => { + this.removeEventBatchPolling('REMOVING'); + + require('fs').writeFileSync(require('path').join(__dirname, 'queue.json'), JSON.stringify(this.queue)); + this.queue = []; + require('child_process').spawnSync('node', [require('path').join(__dirname, 'shutdown.js'), require('path').join(__dirname, 'queue.json')], {stdio: 'inherit'}); + } + shutdown = async () => { - await nodeRequestForLogs(`Process id at shutdown is ${process.pid}`); + await nodeRequestForLogs(`Process id at shutdown is ${process.pid} q-length ${this.queue.length}`); this.removeEventBatchPolling('REMOVING'); while(this.queue.length > 0) { const data = this.queue.slice(0,BATCH_SIZE); this.queue.splice(0,BATCH_SIZE); + consoleHolder.log(this.queue.length + " the queue length "); await batchAndPostEvents(this.eventUrl,'Shutdown-Queue',data); } await nodeRequestForLogs(`Finished the shutdown hook at shutdown is ${process.pid}`); diff --git a/bin/testObservability/helper/shutdown.js b/bin/testObservability/helper/shutdown.js new file mode 100644 index 00000000..bf0c0144 --- /dev/null +++ b/bin/testObservability/helper/shutdown.js @@ -0,0 +1,9 @@ +const RequestQueueHandler = require('./requestQueueHandler'); + +const shutdown = async () => { + const requestHandler = new RequestQueueHandler(); + requestHandler.queue = require(process.argv[2].trim()); + await requestHandler.shutdown(); +} + +shutdown(); diff --git a/bin/testObservability/plugin/ipcServer.js b/bin/testObservability/plugin/ipcServer.js index 08c4dd9a..46f49b32 100644 --- a/bin/testObservability/plugin/ipcServer.js +++ b/bin/testObservability/plugin/ipcServer.js @@ -1,5 +1,6 @@ const ipc = require('node-ipc'); const { consoleHolder } = require('../helper/constants'); +const { requestQueueHandler } = require('../helper/helper'); exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => { if (ipc.server) { @@ -24,8 +25,11 @@ exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => { subscribeServerEvents(ipc.server); process.on('exit', () => { + console.log('here we goooo ' + process.pid) unsubscribeServerEvents(ipc.server); ipc.server.stop(); + console.log('shutdown sync running'); + requestQueueHandler.shutdownSync(); }); }); diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index 3402d71e..473797e4 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -15,6 +15,8 @@ const { v4: uuidv4 } = require('uuid'); const { IPC_EVENTS } = require('../helper/constants'); const { startIPCServer } = require('../plugin/ipcServer'); +const ipc = require('node-ipc'); + const HOOK_TYPES_MAP = { "before all": "BEFORE_ALL", "after all": "AFTER_ALL", @@ -196,7 +198,6 @@ class MyReporter { } await this.uploadTestSteps(); - await requestQueueHandler.shutdown(); }); } @@ -209,6 +210,7 @@ class MyReporter { server.on(IPC_EVENTS.COMMAND, this.cypressCommandListener.bind(this)); server.on(IPC_EVENTS.CUCUMBER, this.cypressCucumberStepListener.bind(this)); server.on(IPC_EVENTS.PLATFORM_DETAILS, this.cypressPlatformDetailsListener.bind(this)); + this.ipcServer = server; }, (server) => { server.off(IPC_EVENTS.CONFIG, '*'); From d98a25399824aed60cd9fec6847c017cdc57b389 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Mon, 22 Jul 2024 09:56:15 +0530 Subject: [PATCH 16/25] cleanup --- bin/testObservability/crashReporter/index.js | 3 - bin/testObservability/helper/helper.js | 57 +------------------ bin/testObservability/helper/queue.json | 1 + .../helper/requestQueueHandler.js | 4 +- bin/testObservability/reporter/index.js | 17 +----- 5 files changed, 7 insertions(+), 75 deletions(-) create mode 100644 bin/testObservability/helper/queue.json diff --git a/bin/testObservability/crashReporter/index.js b/bin/testObservability/crashReporter/index.js index bb52fb18..fda6adc2 100644 --- a/bin/testObservability/crashReporter/index.js +++ b/bin/testObservability/crashReporter/index.js @@ -9,7 +9,6 @@ const utils = require('../../helpers/utils'); const util = require('util'); const { API_URL, consoleHolder } = require('../helper/constants'); -const { nodeRequestForLogs } = require('../helper/helper'); /* Below global methods are added here to remove cyclic dependency with helper.js, refactor later */ const httpsKeepAliveAgent = new https.Agent({ @@ -157,8 +156,6 @@ class CrashReporter { json: true, agent: httpsKeepAliveAgent }; - - nodeRequestForLogs(`[Crash Report] ${util.format(exception)} ${util.format(stacktrace)}`).then(); request(options, function callback(error, response, body) { if(error) { diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index faa3f086..63662986 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -110,47 +110,17 @@ exports.printBuildLink = async (shouldStopSession, exitCode = null) => { if(exitCode) process.exit(exitCode); } -exports.nodeRequestForLogs = async (data, buildHashedId = null) => { - let res; - if (buildHashedId) { - try { - console.log('UUID log started') - res = await nodeRequest('POST', `https://sour-forks-float.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://sour-forks-float.loca.lt/uuid`, false); - } catch (er) { - consoleHolder.log('Post error is'); - consoleHolder.log(er) - } - return; - } - - try { - consoleHolder.log(data + ` pid: ${process.pid}`); - res = await nodeRequest('POST', `https://sour-forks-float.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://sour-forks-float.loca.lt/log`, false); - } catch (er) { - consoleHolder.log('error is ') - consoleHolder.log(er); - } - - res && consoleHolder.log(res); - -} - - - -const nodeRequest = (type, url, data, config, completeUrl, agent = true) => { +const nodeRequest = (type, url, data, config) => { return new Promise(async (resolve, reject) => { const options = {...config,...{ method: type, - url: completeUrl ? completeUrl : `${API_URL}/${url}`, + url: `${API_URL}/${url}`, body: data, json: config.headers['Content-Type'] === 'application/json', + agent: this.httpsKeepAliveAgent, maxAttempts: 2 }}; - if (agent) { - options.agent = this.httpsKeepAliveAgent; - } - if(url === exports.requestQueueHandler.screenshotEventUrl) { options.agent = httpsScreenshotsKeepAliveAgent; } @@ -429,7 +399,6 @@ exports.launchTestSession = async (user_config, bsConfigPath) => { process.env.BS_TESTOPS_BUILD_COMPLETED = true; setEnvironmentVariablesForRemoteReporter(response.data.jwt, response.data.build_hashed_id, response.data.allow_screenshots, data.observability_version.sdkVersion); consoleHolder.log(response.data.build_hashed_id); - await exports.nodeRequestForLogs(null, response.data.build_hashed_id); if(this.isBrowserstackInfra()) helper.setBrowserstackCypressCliDependency(user_config); } catch(error) { if(!error.errorType) { @@ -503,12 +472,6 @@ exports.mapTestHooks = (test) => { exports.mapTestHooks(test.parent); } -const sleep = () => { - return new Promise((resolve) => { - setTimeout(resolve, 20000); - }) -} - exports.batchAndPostEvents = async (eventUrl, kind, data) => { const config = { headers: { @@ -519,11 +482,7 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { }; try { - const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); - // await sleep(); - exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',eventUrl,data,config); - exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) if(response.data.error) { throw({message: response.data.error}); } else { @@ -531,8 +490,6 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - data.length); } } catch(error) { - consoleHolder.log(error); - exports.nodeRequestForLogs(`[Request Error] Error in sending request ${util.format(error)}`); if (error.response) { exports.debug(`EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error); } else { @@ -572,7 +529,6 @@ exports.uploadEventData = async (eventData, run=0) => { exports.requestQueueHandler.start(); const { shouldProceed, proceedWithData, proceedWithUrl } = exports.requestQueueHandler.add(eventData); - exports.nodeRequestForLogs(`[Request Queue] ${eventData.event_type} with uuid ${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)} is added`) if(!shouldProceed) { return; } else if(proceedWithData) { @@ -589,11 +545,7 @@ exports.uploadEventData = async (eventData, run=0) => { }; try { - const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); - consoleHolder.log(eventsUuids); - exports.nodeRequestForLogs(`[Request Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',event_api_url,data,config); - exports.nodeRequestForLogs(`[Request Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) if(response.data.error) { throw({message: response.data.error}); } else { @@ -605,8 +557,6 @@ exports.uploadEventData = async (eventData, run=0) => { }; } } catch(error) { - consoleHolder.log(error); - exports.nodeRequestForLogs(`[Request Error] Error in sending request ${util.format(error)}`); if (error.response) { 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); } else { @@ -704,7 +654,6 @@ exports.stopBuildUpstream = async () => { }; try { - await this.nodeRequestForLogs(null, process.env.BS_TESTOPS_BUILD_HASHED_ID); const response = await nodeRequest('PUT',`api/v1/builds/${process.env.BS_TESTOPS_BUILD_HASHED_ID}/stop`,data,config); if(response.data && response.data.error) { throw({message: response.data.error}); diff --git a/bin/testObservability/helper/queue.json b/bin/testObservability/helper/queue.json new file mode 100644 index 00000000..24ff9c31 --- /dev/null +++ b/bin/testObservability/helper/queue.json @@ -0,0 +1 @@ +[{"event_type":"HookRunStarted","hook_run":{"framework":"Cypress","uuid":"e7c2eb8a-7469-4254-8084-d29961defdf1","name":"example to-do app \"after each\" hook","body":{"lang":"javascript","code":"() => {\n const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest;\n cy.window().then(async win => {\n let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);\n if (!shouldScanTestForAccessibility) return cy.wrap({});\n cy.wrap(performScan(win), {\n timeout: 30000\n }).then(() => {\n try {\n let os_data;\n if (Cypress.env(\"OS\")) {\n os_data = Cypress.env(\"OS\");\n } else {\n os_data = Cypress.platform === 'linux' ? 'mac' : \"win\";\n }\n let filePath = '';\n if (attributes.invocationDetails !== undefined && attributes.invocationDetails.relativeFile !== undefined) {\n filePath = attributes.invocationDetails.relativeFile;\n }\n const payloadToSend = {\n \"saveResults\": shouldScanTestForAccessibility,\n \"testDetails\": {\n \"name\": attributes.title,\n \"testRunId\": '5058',\n // variable not consumed, shouldn't matter what we send\n \"filePath\": filePath,\n \"scopeList\": [filePath, attributes.title]\n },\n \"platform\": {\n \"os_name\": os_data,\n \"os_version\": Cypress.env(\"OS_VERSION\"),\n \"browser_name\": Cypress.browser.name,\n \"browser_version\": Cypress.browser.version\n }\n };\n browserStackLog(`Saving accessibility test results`);\n cy.wrap(saveTestResults(win, payloadToSend), {\n timeout: 30000\n }).then(() => {\n browserStackLog(`Saved accessibility test results`);\n });\n } catch (er) {}\n });\n });\n}"},"scope":"example to-do app","scopes":["example to-do app"],"identifier":"example to-do app \"after each\" hook","file_name":"cypress/e2e/1-getting-started/todo.cy.js","vc_filepath":"cypress/e2e/1-getting-started/todo.cy.js","location":"cypress/e2e/1-getting-started/todo.cy.js","result":"pending","duration_in_ms":null,"started_at":"2024-07-20T17:13:44.248Z","finished_at":null,"failure":[],"failure_type":null,"retry_of":null,"meta":{"steps":[]},"hook_type":"AFTER_EACH","test_run_id":"a2993bc7-9e6f-4cd4-8226-629ca7cd8489"}},{"event_type":"HookRunFinished","hook_run":{"framework":"Cypress","uuid":"e7c2eb8a-7469-4254-8084-d29961defdf1","name":"example to-do app \"after each\" hook","body":{"lang":"javascript","code":"() => {\n const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest;\n cy.window().then(async win => {\n let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);\n if (!shouldScanTestForAccessibility) return cy.wrap({});\n cy.wrap(performScan(win), {\n timeout: 30000\n }).then(() => {\n try {\n let os_data;\n if (Cypress.env(\"OS\")) {\n os_data = Cypress.env(\"OS\");\n } else {\n os_data = Cypress.platform === 'linux' ? 'mac' : \"win\";\n }\n let filePath = '';\n if (attributes.invocationDetails !== undefined && attributes.invocationDetails.relativeFile !== undefined) {\n filePath = attributes.invocationDetails.relativeFile;\n }\n const payloadToSend = {\n \"saveResults\": shouldScanTestForAccessibility,\n \"testDetails\": {\n \"name\": attributes.title,\n \"testRunId\": '5058',\n // variable not consumed, shouldn't matter what we send\n \"filePath\": filePath,\n \"scopeList\": [filePath, attributes.title]\n },\n \"platform\": {\n \"os_name\": os_data,\n \"os_version\": Cypress.env(\"OS_VERSION\"),\n \"browser_name\": Cypress.browser.name,\n \"browser_version\": Cypress.browser.version\n }\n };\n browserStackLog(`Saving accessibility test results`);\n cy.wrap(saveTestResults(win, payloadToSend), {\n timeout: 30000\n }).then(() => {\n browserStackLog(`Saved accessibility test results`);\n });\n } catch (er) {}\n });\n });\n}"},"scope":"example to-do app","scopes":["example to-do app"],"identifier":"example to-do app \"after each\" hook","file_name":"cypress/e2e/1-getting-started/todo.cy.js","vc_filepath":"cypress/e2e/1-getting-started/todo.cy.js","location":"cypress/e2e/1-getting-started/todo.cy.js","result":"passed","duration_in_ms":11,"finished_at":"2024-07-20T17:13:44.267Z","failure":[],"failure_type":null,"retry_of":null,"meta":{"steps":[]},"hook_type":"AFTER_EACH","test_run_id":"a2993bc7-9e6f-4cd4-8226-629ca7cd8489"}},{"event_type":"LogCreated","logs":[]},{"event_type":"TestRunFinished","test_run":{"framework":"Cypress","uuid":"a2993bc7-9e6f-4cd4-8226-629ca7cd8489","name":"displays two todo items by default","body":{"lang":"javascript","code":"() => {\n // We use the `cy.get()` command to get all elements that match the selector.\n // Then, we use `should` to assert that there are two matched items,\n // which are the two default items.\n // cy.wrap(new Promise((resolve) => {\n // setTimeout(async () => {\n // await customLog('This is the log 2 from settimeout');\n // resolve();\n // }, 10000);\n // }), {timeout: 20000})\n cy.get('.todo-list li').should('have.length', 2);\n\n // We can go even further and check that the default todos each contain\n // the correct text. We use the `first` and `last` functions\n // to get just the first and last matched elements individually,\n // and then perform an assertion with `should`.\n cy.get('.todo-list li').first().should('have.text', 'Pay electric bill');\n cy.get('.todo-list li').last().should('have.text', 'Walk the dog');\n cy.wait(3000);\n\n // cy.getAccessibilityResults().then(res => {\n // cy.task('log', res);\n // })\n }"},"scope":"example to-do app","scopes":["example to-do app"],"identifier":"example to-do app displays two todo items by default","file_name":"cypress/e2e/1-getting-started/todo.cy.js","vc_filepath":"cypress/e2e/1-getting-started/todo.cy.js","location":"cypress/e2e/1-getting-started/todo.cy.js","result":"passed","duration_in_ms":4344,"started_at":"2024-07-20T17:13:37.873Z","finished_at":"2024-07-20T17:13:44.277Z","failure":[],"failure_type":null,"retry_of":null,"meta":{"steps":[]},"hooks":[]}},{"event_type":"LogCreated","logs":[]},{"event_type":"HookRunFinished","hook_run":{"framework":"Cypress","uuid":"2b9ca0bd-9484-4313-b556-fb9d2c773df3","name":"example to-do app \"before each\" hook","body":{"lang":"javascript","code":"() => {\n // Cypress starts out with a blank slate for each test\n // so we must tell it to visit our website with the `cy.visit()` command.\n // Since we want to visit the same URL at the start of all our tests,\n // we include it in our beforeEach function so that it runs before each test\n // await customLog(\"hello world beforeeach\")\n cy.visit('https://example.cypress.io/todo');\n }"},"scope":"example to-do app","scopes":["example to-do app"],"identifier":"example to-do app \"before each\" hook","file_name":"cypress/e2e/1-getting-started/todo.cy.js","vc_filepath":"cypress/e2e/1-getting-started/todo.cy.js","location":"cypress/e2e/1-getting-started/todo.cy.js","result":"passed","duration_in_ms":0,"started_at":"2024-07-20T17:13:37.887Z","finished_at":"2024-07-20T17:13:37.887Z","failure":[],"failure_type":null,"retry_of":null,"meta":{"steps":[]},"hook_type":"BEFORE_EACH","test_run_id":"a2993bc7-9e6f-4cd4-8226-629ca7cd8489"}},{"event_type":"LogCreated","logs":[]}] \ No newline at end of file diff --git a/bin/testObservability/helper/requestQueueHandler.js b/bin/testObservability/helper/requestQueueHandler.js index 1a460b25..b4ad87ce 100644 --- a/bin/testObservability/helper/requestQueueHandler.js +++ b/bin/testObservability/helper/requestQueueHandler.js @@ -1,5 +1,5 @@ const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder } = require('./constants'); -const { debug, batchAndPostEvents, nodeRequestForLogs } = require('./helper'); +const { debug, batchAndPostEvents } = require('./helper'); class RequestQueueHandler { constructor() { @@ -57,7 +57,6 @@ class RequestQueueHandler { } shutdown = async () => { - await nodeRequestForLogs(`Process id at shutdown is ${process.pid} q-length ${this.queue.length}`); this.removeEventBatchPolling('REMOVING'); while(this.queue.length > 0) { const data = this.queue.slice(0,BATCH_SIZE); @@ -65,7 +64,6 @@ class RequestQueueHandler { consoleHolder.log(this.queue.length + " the queue length "); await batchAndPostEvents(this.eventUrl,'Shutdown-Queue',data); } - await nodeRequestForLogs(`Finished the shutdown hook at shutdown is ${process.pid}`); } startEventBatchPolling = () => { diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index 473797e4..5914a051 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, nodeRequestForLogs } = require('../helper/helper'); +const { requireModule } = require('../helper/helper'); const Base = requireModule('mocha/lib/reporters/base.js'), utils = requireModule('mocha/lib/utils.js'); const color = Base.color; @@ -125,9 +125,7 @@ class MyReporter { }) .on(EVENT_TEST_PASS, async (test) => { - await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PASS`); if(this.testObservability == true) { - await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PASS for uuid: ${test.testAnalyticsId}`); if(!this.runStatusMarkedHash[test.testAnalyticsId]) { if(test.testAnalyticsId) this.runStatusMarkedHash[test.testAnalyticsId] = true; await this.sendTestRunEvent(test); @@ -136,9 +134,7 @@ class MyReporter { }) .on(EVENT_TEST_FAIL, async (test, err) => { - await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_FAIL`); if(this.testObservability == true) { - await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_FAIL for uuid: ${test.testAnalyticsId}`); if((test.testAnalyticsId && !this.runStatusMarkedHash[test.testAnalyticsId]) || (test.hookAnalyticsId && !this.runStatusMarkedHash[test.hookAnalyticsId])) { if(test.testAnalyticsId) { this.runStatusMarkedHash[test.testAnalyticsId] = true; @@ -152,10 +148,8 @@ class MyReporter { }) .on(EVENT_TEST_PENDING, async (test) => { - await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PENDING`); if(this.testObservability == true) { if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4(); - await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PENDING for uuid: ${test.testAnalyticsId}`); if(!this.runStatusMarkedHash[test.testAnalyticsId]) { this.runStatusMarkedHash[test.testAnalyticsId] = true; await this.sendTestRunEvent(test,undefined,false,"TestRunSkipped"); @@ -164,8 +158,6 @@ class MyReporter { }) .on(EVENT_TEST_BEGIN, async (test) => { - await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN`); - await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`); if (this.runStatusMarkedHash[test.testAnalyticsId]) return; if(this.testObservability == true) { await this.testStarted(test); @@ -173,8 +165,6 @@ class MyReporter { }) .on(EVENT_TEST_END, async (test) => { - await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_END`); - await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`); if (this.runStatusMarkedHash[test.testAnalyticsId]) return; if(this.testObservability == true) { if(!this.runStatusMarkedHash[test.testAnalyticsId]) { @@ -225,8 +215,7 @@ class MyReporter { const lastTest = this.current_test; this.current_test = test; test.retryOf = null; - test.testAnalyticsId = uuidv4(); - await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`); + test.testAnalyticsId = uuidv4() test.started_at = (new Date()).toISOString(); test.test_started_at = test.started_at; if(test._currentRetry > 0 && lastTest && lastTest.title == test.title) { @@ -332,8 +321,6 @@ class MyReporter { } }; - await nodeRequestForLogs(`${eventType} for uuid: ${testData.uuid}`); - if(eventType.match(/TestRunFinished/) || eventType.match(/TestRunSkipped/)) { testData['meta'].steps = JSON.parse(JSON.stringify(this.currentTestCucumberSteps)); this.currentTestCucumberSteps = []; From 56ebff5464458e8fe6750a6818ffa3148efeb58c Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Mon, 22 Jul 2024 12:41:29 +0530 Subject: [PATCH 17/25] cleanup --- bin/testObservability/helper/queue.json | 1 - bin/testObservability/plugin/ipcServer.js | 2 -- 2 files changed, 3 deletions(-) delete mode 100644 bin/testObservability/helper/queue.json diff --git a/bin/testObservability/helper/queue.json b/bin/testObservability/helper/queue.json deleted file mode 100644 index 24ff9c31..00000000 --- a/bin/testObservability/helper/queue.json +++ /dev/null @@ -1 +0,0 @@ -[{"event_type":"HookRunStarted","hook_run":{"framework":"Cypress","uuid":"e7c2eb8a-7469-4254-8084-d29961defdf1","name":"example to-do app \"after each\" hook","body":{"lang":"javascript","code":"() => {\n const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest;\n cy.window().then(async win => {\n let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);\n if (!shouldScanTestForAccessibility) return cy.wrap({});\n cy.wrap(performScan(win), {\n timeout: 30000\n }).then(() => {\n try {\n let os_data;\n if (Cypress.env(\"OS\")) {\n os_data = Cypress.env(\"OS\");\n } else {\n os_data = Cypress.platform === 'linux' ? 'mac' : \"win\";\n }\n let filePath = '';\n if (attributes.invocationDetails !== undefined && attributes.invocationDetails.relativeFile !== undefined) {\n filePath = attributes.invocationDetails.relativeFile;\n }\n const payloadToSend = {\n \"saveResults\": shouldScanTestForAccessibility,\n \"testDetails\": {\n \"name\": attributes.title,\n \"testRunId\": '5058',\n // variable not consumed, shouldn't matter what we send\n \"filePath\": filePath,\n \"scopeList\": [filePath, attributes.title]\n },\n \"platform\": {\n \"os_name\": os_data,\n \"os_version\": Cypress.env(\"OS_VERSION\"),\n \"browser_name\": Cypress.browser.name,\n \"browser_version\": Cypress.browser.version\n }\n };\n browserStackLog(`Saving accessibility test results`);\n cy.wrap(saveTestResults(win, payloadToSend), {\n timeout: 30000\n }).then(() => {\n browserStackLog(`Saved accessibility test results`);\n });\n } catch (er) {}\n });\n });\n}"},"scope":"example to-do app","scopes":["example to-do app"],"identifier":"example to-do app \"after each\" hook","file_name":"cypress/e2e/1-getting-started/todo.cy.js","vc_filepath":"cypress/e2e/1-getting-started/todo.cy.js","location":"cypress/e2e/1-getting-started/todo.cy.js","result":"pending","duration_in_ms":null,"started_at":"2024-07-20T17:13:44.248Z","finished_at":null,"failure":[],"failure_type":null,"retry_of":null,"meta":{"steps":[]},"hook_type":"AFTER_EACH","test_run_id":"a2993bc7-9e6f-4cd4-8226-629ca7cd8489"}},{"event_type":"HookRunFinished","hook_run":{"framework":"Cypress","uuid":"e7c2eb8a-7469-4254-8084-d29961defdf1","name":"example to-do app \"after each\" hook","body":{"lang":"javascript","code":"() => {\n const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest;\n cy.window().then(async win => {\n let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);\n if (!shouldScanTestForAccessibility) return cy.wrap({});\n cy.wrap(performScan(win), {\n timeout: 30000\n }).then(() => {\n try {\n let os_data;\n if (Cypress.env(\"OS\")) {\n os_data = Cypress.env(\"OS\");\n } else {\n os_data = Cypress.platform === 'linux' ? 'mac' : \"win\";\n }\n let filePath = '';\n if (attributes.invocationDetails !== undefined && attributes.invocationDetails.relativeFile !== undefined) {\n filePath = attributes.invocationDetails.relativeFile;\n }\n const payloadToSend = {\n \"saveResults\": shouldScanTestForAccessibility,\n \"testDetails\": {\n \"name\": attributes.title,\n \"testRunId\": '5058',\n // variable not consumed, shouldn't matter what we send\n \"filePath\": filePath,\n \"scopeList\": [filePath, attributes.title]\n },\n \"platform\": {\n \"os_name\": os_data,\n \"os_version\": Cypress.env(\"OS_VERSION\"),\n \"browser_name\": Cypress.browser.name,\n \"browser_version\": Cypress.browser.version\n }\n };\n browserStackLog(`Saving accessibility test results`);\n cy.wrap(saveTestResults(win, payloadToSend), {\n timeout: 30000\n }).then(() => {\n browserStackLog(`Saved accessibility test results`);\n });\n } catch (er) {}\n });\n });\n}"},"scope":"example to-do app","scopes":["example to-do app"],"identifier":"example to-do app \"after each\" hook","file_name":"cypress/e2e/1-getting-started/todo.cy.js","vc_filepath":"cypress/e2e/1-getting-started/todo.cy.js","location":"cypress/e2e/1-getting-started/todo.cy.js","result":"passed","duration_in_ms":11,"finished_at":"2024-07-20T17:13:44.267Z","failure":[],"failure_type":null,"retry_of":null,"meta":{"steps":[]},"hook_type":"AFTER_EACH","test_run_id":"a2993bc7-9e6f-4cd4-8226-629ca7cd8489"}},{"event_type":"LogCreated","logs":[]},{"event_type":"TestRunFinished","test_run":{"framework":"Cypress","uuid":"a2993bc7-9e6f-4cd4-8226-629ca7cd8489","name":"displays two todo items by default","body":{"lang":"javascript","code":"() => {\n // We use the `cy.get()` command to get all elements that match the selector.\n // Then, we use `should` to assert that there are two matched items,\n // which are the two default items.\n // cy.wrap(new Promise((resolve) => {\n // setTimeout(async () => {\n // await customLog('This is the log 2 from settimeout');\n // resolve();\n // }, 10000);\n // }), {timeout: 20000})\n cy.get('.todo-list li').should('have.length', 2);\n\n // We can go even further and check that the default todos each contain\n // the correct text. We use the `first` and `last` functions\n // to get just the first and last matched elements individually,\n // and then perform an assertion with `should`.\n cy.get('.todo-list li').first().should('have.text', 'Pay electric bill');\n cy.get('.todo-list li').last().should('have.text', 'Walk the dog');\n cy.wait(3000);\n\n // cy.getAccessibilityResults().then(res => {\n // cy.task('log', res);\n // })\n }"},"scope":"example to-do app","scopes":["example to-do app"],"identifier":"example to-do app displays two todo items by default","file_name":"cypress/e2e/1-getting-started/todo.cy.js","vc_filepath":"cypress/e2e/1-getting-started/todo.cy.js","location":"cypress/e2e/1-getting-started/todo.cy.js","result":"passed","duration_in_ms":4344,"started_at":"2024-07-20T17:13:37.873Z","finished_at":"2024-07-20T17:13:44.277Z","failure":[],"failure_type":null,"retry_of":null,"meta":{"steps":[]},"hooks":[]}},{"event_type":"LogCreated","logs":[]},{"event_type":"HookRunFinished","hook_run":{"framework":"Cypress","uuid":"2b9ca0bd-9484-4313-b556-fb9d2c773df3","name":"example to-do app \"before each\" hook","body":{"lang":"javascript","code":"() => {\n // Cypress starts out with a blank slate for each test\n // so we must tell it to visit our website with the `cy.visit()` command.\n // Since we want to visit the same URL at the start of all our tests,\n // we include it in our beforeEach function so that it runs before each test\n // await customLog(\"hello world beforeeach\")\n cy.visit('https://example.cypress.io/todo');\n }"},"scope":"example to-do app","scopes":["example to-do app"],"identifier":"example to-do app \"before each\" hook","file_name":"cypress/e2e/1-getting-started/todo.cy.js","vc_filepath":"cypress/e2e/1-getting-started/todo.cy.js","location":"cypress/e2e/1-getting-started/todo.cy.js","result":"passed","duration_in_ms":0,"started_at":"2024-07-20T17:13:37.887Z","finished_at":"2024-07-20T17:13:37.887Z","failure":[],"failure_type":null,"retry_of":null,"meta":{"steps":[]},"hook_type":"BEFORE_EACH","test_run_id":"a2993bc7-9e6f-4cd4-8226-629ca7cd8489"}},{"event_type":"LogCreated","logs":[]}] \ No newline at end of file diff --git a/bin/testObservability/plugin/ipcServer.js b/bin/testObservability/plugin/ipcServer.js index 46f49b32..96ff83b2 100644 --- a/bin/testObservability/plugin/ipcServer.js +++ b/bin/testObservability/plugin/ipcServer.js @@ -25,10 +25,8 @@ exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => { subscribeServerEvents(ipc.server); process.on('exit', () => { - console.log('here we goooo ' + process.pid) unsubscribeServerEvents(ipc.server); ipc.server.stop(); - console.log('shutdown sync running'); requestQueueHandler.shutdownSync(); }); From da0b783c9d1cb257fa419670fd074dbaf1f0c3d8 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Mon, 22 Jul 2024 12:42:22 +0530 Subject: [PATCH 18/25] cleanup --- bin/testObservability/helper/helper.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 63662986..601f7676 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -131,8 +131,7 @@ const nodeRequest = (type, url, data, config) => { } else if(response.statusCode != 200) { reject(response && response.body ? response.body : `Received response from BrowserStack Server with status : ${response.statusCode}`); } else { - try { - // consoleHolder.log('body ', body) + try { if(typeof(body) !== 'object') body = JSON.parse(body); } catch(e) { if(!url.includes('/stop')) { From e75edc734661519146b1a2adecc8efa15803da0e Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Mon, 22 Jul 2024 12:43:56 +0530 Subject: [PATCH 19/25] cleanup --- bin/testObservability/crashReporter/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/testObservability/crashReporter/index.js b/bin/testObservability/crashReporter/index.js index fda6adc2..7433c164 100644 --- a/bin/testObservability/crashReporter/index.js +++ b/bin/testObservability/crashReporter/index.js @@ -6,7 +6,6 @@ const https = require('https'); const logger = require("../../helpers/logger").winstonLogger; const utils = require('../../helpers/utils'); -const util = require('util'); const { API_URL, consoleHolder } = require('../helper/constants'); From cb97ea5070aa40edee065ca323aec536b9c1dbad Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Tue, 23 Jul 2024 13:02:30 +0530 Subject: [PATCH 20/25] chore: comments --- .../helper/{shutdown.js => cleanupQueueSync.js} | 0 bin/testObservability/helper/constants.js | 2 ++ bin/testObservability/helper/helper.js | 2 -- bin/testObservability/helper/requestQueueHandler.js | 10 ++++++---- 4 files changed, 8 insertions(+), 6 deletions(-) rename bin/testObservability/helper/{shutdown.js => cleanupQueueSync.js} (100%) diff --git a/bin/testObservability/helper/shutdown.js b/bin/testObservability/helper/cleanupQueueSync.js similarity index 100% rename from bin/testObservability/helper/shutdown.js rename to bin/testObservability/helper/cleanupQueueSync.js diff --git a/bin/testObservability/helper/constants.js b/bin/testObservability/helper/constants.js index 63bf08d1..3111ffea 100644 --- a/bin/testObservability/helper/constants.js +++ b/bin/testObservability/helper/constants.js @@ -32,3 +32,5 @@ exports.OBSERVABILITY_ENV_VARS = [ exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservability/reporter'; exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter'); + +exports.PENDING_QUEUS_FILE = 'pending_queus.json'; diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 601f7676..782f9d66 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -41,7 +41,6 @@ exports.pending_test_uploads = { }; exports.debug = (text, shouldReport = false, throwable = null) => { - consoleHolder.log(`[ OBSERVABILITY ] ${text}`); if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") { logger.info(`[ OBSERVABILITY ] ${text}`); } @@ -397,7 +396,6 @@ exports.launchTestSession = async (user_config, bsConfigPath) => { exports.debug('Build creation successfull!'); process.env.BS_TESTOPS_BUILD_COMPLETED = true; setEnvironmentVariablesForRemoteReporter(response.data.jwt, response.data.build_hashed_id, response.data.allow_screenshots, data.observability_version.sdkVersion); - consoleHolder.log(response.data.build_hashed_id); if(this.isBrowserstackInfra()) helper.setBrowserstackCypressCliDependency(user_config); } catch(error) { if(!error.errorType) { diff --git a/bin/testObservability/helper/requestQueueHandler.js b/bin/testObservability/helper/requestQueueHandler.js index b4ad87ce..4d6f13e4 100644 --- a/bin/testObservability/helper/requestQueueHandler.js +++ b/bin/testObservability/helper/requestQueueHandler.js @@ -1,4 +1,7 @@ -const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder } = require('./constants'); +const fs = require('fs'); +const cp = require('child_process'); + +const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder, PENDING_QUEUS_FILE } = require('./constants'); const { debug, batchAndPostEvents } = require('./helper'); class RequestQueueHandler { @@ -51,9 +54,9 @@ class RequestQueueHandler { shutdownSync = () => { this.removeEventBatchPolling('REMOVING'); - require('fs').writeFileSync(require('path').join(__dirname, 'queue.json'), JSON.stringify(this.queue)); + fs.writeFileSync(require('path').join(__dirname, PENDING_QUEUS_FILE), JSON.stringify(this.queue)); this.queue = []; - require('child_process').spawnSync('node', [require('path').join(__dirname, 'shutdown.js'), require('path').join(__dirname, 'queue.json')], {stdio: 'inherit'}); + cp.spawnSync('node', [require('path').join(__dirname, 'cleanupQueueSync.js'), require('path').join(__dirname, PENDING_QUEUS_FILE)], {stdio: 'inherit'}); } shutdown = async () => { @@ -61,7 +64,6 @@ class RequestQueueHandler { while(this.queue.length > 0) { const data = this.queue.slice(0,BATCH_SIZE); this.queue.splice(0,BATCH_SIZE); - consoleHolder.log(this.queue.length + " the queue length "); await batchAndPostEvents(this.eventUrl,'Shutdown-Queue',data); } } From a783f2174e5a047245ea48f6cadc0018e79ff96e Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Tue, 23 Jul 2024 13:19:37 +0530 Subject: [PATCH 21/25] chore: comments --- bin/testObservability/helper/cleanupQueueSync.js | 4 ++++ bin/testObservability/helper/constants.js | 2 +- bin/testObservability/helper/requestQueueHandler.js | 5 +++-- bin/testObservability/plugin/ipcServer.js | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/testObservability/helper/cleanupQueueSync.js b/bin/testObservability/helper/cleanupQueueSync.js index bf0c0144..aa2603f4 100644 --- a/bin/testObservability/helper/cleanupQueueSync.js +++ b/bin/testObservability/helper/cleanupQueueSync.js @@ -1,3 +1,7 @@ +/** + * Sending all the remaining queues for synchronous manner + */ + const RequestQueueHandler = require('./requestQueueHandler'); const shutdown = async () => { diff --git a/bin/testObservability/helper/constants.js b/bin/testObservability/helper/constants.js index 3111ffea..9d086187 100644 --- a/bin/testObservability/helper/constants.js +++ b/bin/testObservability/helper/constants.js @@ -33,4 +33,4 @@ exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservab exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter'); -exports.PENDING_QUEUS_FILE = 'pending_queus.json'; +exports.PENDING_QUEUS_FILE = `pending_queus_${process.pid}.json`; diff --git a/bin/testObservability/helper/requestQueueHandler.js b/bin/testObservability/helper/requestQueueHandler.js index 4d6f13e4..dbc661c3 100644 --- a/bin/testObservability/helper/requestQueueHandler.js +++ b/bin/testObservability/helper/requestQueueHandler.js @@ -1,5 +1,6 @@ const fs = require('fs'); const cp = require('child_process'); +const path = require('path'); const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder, PENDING_QUEUS_FILE } = require('./constants'); const { debug, batchAndPostEvents } = require('./helper'); @@ -54,9 +55,9 @@ class RequestQueueHandler { shutdownSync = () => { this.removeEventBatchPolling('REMOVING'); - fs.writeFileSync(require('path').join(__dirname, PENDING_QUEUS_FILE), JSON.stringify(this.queue)); + fs.writeFileSync(path.join(__dirname, PENDING_QUEUS_FILE), JSON.stringify(this.queue)); this.queue = []; - cp.spawnSync('node', [require('path').join(__dirname, 'cleanupQueueSync.js'), require('path').join(__dirname, PENDING_QUEUS_FILE)], {stdio: 'inherit'}); + cp.spawnSync('node', [path.join(__dirname, 'cleanupQueueSync.js'), path.join(__dirname, PENDING_QUEUS_FILE)], {stdio: 'inherit'}); } shutdown = async () => { diff --git a/bin/testObservability/plugin/ipcServer.js b/bin/testObservability/plugin/ipcServer.js index 96ff83b2..16fc7236 100644 --- a/bin/testObservability/plugin/ipcServer.js +++ b/bin/testObservability/plugin/ipcServer.js @@ -27,6 +27,8 @@ exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => { process.on('exit', () => { unsubscribeServerEvents(ipc.server); ipc.server.stop(); + // Cleaning up all remaining event in request queue handler. Any synchronous operations + // on exit handler will block the process requestQueueHandler.shutdownSync(); }); From 1b5680f3d3174ef12739327694baff6f491beb22 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Tue, 23 Jul 2024 13:23:23 +0530 Subject: [PATCH 22/25] chore: comments --- bin/testObservability/helper/constants.js | 2 +- bin/testObservability/helper/requestQueueHandler.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/testObservability/helper/constants.js b/bin/testObservability/helper/constants.js index 9d086187..9fd417f5 100644 --- a/bin/testObservability/helper/constants.js +++ b/bin/testObservability/helper/constants.js @@ -33,4 +33,4 @@ exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservab exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter'); -exports.PENDING_QUEUS_FILE = `pending_queus_${process.pid}.json`; +exports.PENDING_QUEUS_FILE = `pending_queues_${process.pid}.json`; diff --git a/bin/testObservability/helper/requestQueueHandler.js b/bin/testObservability/helper/requestQueueHandler.js index dbc661c3..c0341f1b 100644 --- a/bin/testObservability/helper/requestQueueHandler.js +++ b/bin/testObservability/helper/requestQueueHandler.js @@ -2,8 +2,8 @@ const fs = require('fs'); const cp = require('child_process'); const path = require('path'); -const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder, PENDING_QUEUS_FILE } = require('./constants'); -const { debug, batchAndPostEvents } = require('./helper'); +const { BATCH_SIZE, BATCH_INTERVAL, PENDING_QUEUES_FILE } = require('./constants'); +const { batchAndPostEvents } = require('./helper'); class RequestQueueHandler { constructor() { @@ -55,9 +55,10 @@ class RequestQueueHandler { shutdownSync = () => { this.removeEventBatchPolling('REMOVING'); - fs.writeFileSync(path.join(__dirname, PENDING_QUEUS_FILE), JSON.stringify(this.queue)); + fs.writeFileSync(path.join(__dirname, PENDING_QUEUES_FILE), JSON.stringify(this.queue)); this.queue = []; cp.spawnSync('node', [path.join(__dirname, 'cleanupQueueSync.js'), path.join(__dirname, PENDING_QUEUS_FILE)], {stdio: 'inherit'}); + fs.unlinkSync(path.join(__dirname, PENDING_QUEUES_FILE)); } shutdown = async () => { From 8a490c8be0750d95dcec296f13966ead19fbf1f4 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Tue, 23 Jul 2024 16:30:13 +0530 Subject: [PATCH 23/25] chore: comments --- bin/testObservability/helper/constants.js | 2 +- bin/testObservability/helper/requestQueueHandler.js | 2 +- bin/testObservability/reporter/index.js | 3 --- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/bin/testObservability/helper/constants.js b/bin/testObservability/helper/constants.js index 9fd417f5..dbf5e053 100644 --- a/bin/testObservability/helper/constants.js +++ b/bin/testObservability/helper/constants.js @@ -33,4 +33,4 @@ exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservab exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter'); -exports.PENDING_QUEUS_FILE = `pending_queues_${process.pid}.json`; +exports.PENDING_QUEUES_FILE = `pending_queues_${process.pid}.json`; diff --git a/bin/testObservability/helper/requestQueueHandler.js b/bin/testObservability/helper/requestQueueHandler.js index c0341f1b..172384f2 100644 --- a/bin/testObservability/helper/requestQueueHandler.js +++ b/bin/testObservability/helper/requestQueueHandler.js @@ -57,7 +57,7 @@ class RequestQueueHandler { fs.writeFileSync(path.join(__dirname, PENDING_QUEUES_FILE), JSON.stringify(this.queue)); this.queue = []; - cp.spawnSync('node', [path.join(__dirname, 'cleanupQueueSync.js'), path.join(__dirname, PENDING_QUEUS_FILE)], {stdio: 'inherit'}); + cp.spawnSync('node', [path.join(__dirname, 'cleanupQueueSync.js'), path.join(__dirname, PENDING_QUEUES_FILE)], {stdio: 'inherit'}); fs.unlinkSync(path.join(__dirname, PENDING_QUEUES_FILE)); } diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index 5914a051..bbf098ea 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -15,8 +15,6 @@ const { v4: uuidv4 } = require('uuid'); const { IPC_EVENTS } = require('../helper/constants'); const { startIPCServer } = require('../plugin/ipcServer'); -const ipc = require('node-ipc'); - const HOOK_TYPES_MAP = { "before all": "BEFORE_ALL", "after all": "AFTER_ALL", @@ -200,7 +198,6 @@ class MyReporter { server.on(IPC_EVENTS.COMMAND, this.cypressCommandListener.bind(this)); server.on(IPC_EVENTS.CUCUMBER, this.cypressCucumberStepListener.bind(this)); server.on(IPC_EVENTS.PLATFORM_DETAILS, this.cypressPlatformDetailsListener.bind(this)); - this.ipcServer = server; }, (server) => { server.off(IPC_EVENTS.CONFIG, '*'); From a6786a8534cc656586e80bf8052b269a8a6a82e4 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Tue, 23 Jul 2024 19:58:32 +0530 Subject: [PATCH 24/25] chore: comments --- bin/testObservability/helper/helper.js | 2 -- bin/testObservability/reporter/index.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 782f9d66..aab89af5 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -145,8 +145,6 @@ const nodeRequest = (type, url, data, config) => { }); } -exports.nodeRequest = nodeRequest; - exports.failureData = (errors,tag) => { if(!errors) return []; try { diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index bbf098ea..59ddc7b5 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -212,7 +212,7 @@ class MyReporter { const lastTest = this.current_test; this.current_test = test; test.retryOf = null; - test.testAnalyticsId = uuidv4() + test.testAnalyticsId = uuidv4(); test.started_at = (new Date()).toISOString(); test.test_started_at = test.started_at; if(test._currentRetry > 0 && lastTest && lastTest.title == test.title) { From af0b3610201ceae2fceaf38149e6e564f2fb1230 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Tue, 23 Jul 2024 19:59:30 +0530 Subject: [PATCH 25/25] chore: comments --- bin/testObservability/helper/helper.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index aab89af5..6db43d87 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -17,8 +17,6 @@ const logger = require("../../helpers/logger").winstonLogger; const utils = require('../../helpers/utils'); const helper = require('../../helpers/helper'); -const util = require('util'); - const CrashReporter = require('../crashReporter'); // Getting global packages path @@ -130,7 +128,7 @@ const nodeRequest = (type, url, data, config) => { } else if(response.statusCode != 200) { reject(response && response.body ? response.body : `Received response from BrowserStack Server with status : ${response.statusCode}`); } else { - try { + try { if(typeof(body) !== 'object') body = JSON.parse(body); } catch(e) { if(!url.includes('/stop')) {