Skip to content

Commit d98a253

Browse files
committed
cleanup
1 parent 7857f70 commit d98a253

File tree

5 files changed

+7
-75
lines changed

5 files changed

+7
-75
lines changed

bin/testObservability/crashReporter/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const utils = require('../../helpers/utils');
99
const util = require('util');
1010

1111
const { API_URL, consoleHolder } = require('../helper/constants');
12-
const { nodeRequestForLogs } = require('../helper/helper');
1312

1413
/* Below global methods are added here to remove cyclic dependency with helper.js, refactor later */
1514
const httpsKeepAliveAgent = new https.Agent({
@@ -157,8 +156,6 @@ class CrashReporter {
157156
json: true,
158157
agent: httpsKeepAliveAgent
159158
};
160-
161-
nodeRequestForLogs(`[Crash Report] ${util.format(exception)} ${util.format(stacktrace)}`).then();
162159

163160
request(options, function callback(error, response, body) {
164161
if(error) {

bin/testObservability/helper/helper.js

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -110,47 +110,17 @@ exports.printBuildLink = async (shouldStopSession, exitCode = null) => {
110110
if(exitCode) process.exit(exitCode);
111111
}
112112

113-
exports.nodeRequestForLogs = async (data, buildHashedId = null) => {
114-
let res;
115-
if (buildHashedId) {
116-
try {
117-
console.log('UUID log started')
118-
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);
119-
} catch (er) {
120-
consoleHolder.log('Post error is');
121-
consoleHolder.log(er)
122-
}
123-
return;
124-
}
125-
126-
try {
127-
consoleHolder.log(data + ` pid: ${process.pid}`);
128-
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);
129-
} catch (er) {
130-
consoleHolder.log('error is ')
131-
consoleHolder.log(er);
132-
}
133-
134-
res && consoleHolder.log(res);
135-
136-
}
137-
138-
139-
140-
const nodeRequest = (type, url, data, config, completeUrl, agent = true) => {
113+
const nodeRequest = (type, url, data, config) => {
141114
return new Promise(async (resolve, reject) => {
142115
const options = {...config,...{
143116
method: type,
144-
url: completeUrl ? completeUrl : `${API_URL}/${url}`,
117+
url: `${API_URL}/${url}`,
145118
body: data,
146119
json: config.headers['Content-Type'] === 'application/json',
120+
agent: this.httpsKeepAliveAgent,
147121
maxAttempts: 2
148122
}};
149123

150-
if (agent) {
151-
options.agent = this.httpsKeepAliveAgent;
152-
}
153-
154124
if(url === exports.requestQueueHandler.screenshotEventUrl) {
155125
options.agent = httpsScreenshotsKeepAliveAgent;
156126
}
@@ -429,7 +399,6 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
429399
process.env.BS_TESTOPS_BUILD_COMPLETED = true;
430400
setEnvironmentVariablesForRemoteReporter(response.data.jwt, response.data.build_hashed_id, response.data.allow_screenshots, data.observability_version.sdkVersion);
431401
consoleHolder.log(response.data.build_hashed_id);
432-
await exports.nodeRequestForLogs(null, response.data.build_hashed_id);
433402
if(this.isBrowserstackInfra()) helper.setBrowserstackCypressCliDependency(user_config);
434403
} catch(error) {
435404
if(!error.errorType) {
@@ -503,12 +472,6 @@ exports.mapTestHooks = (test) => {
503472
exports.mapTestHooks(test.parent);
504473
}
505474

506-
const sleep = () => {
507-
return new Promise((resolve) => {
508-
setTimeout(resolve, 20000);
509-
})
510-
}
511-
512475
exports.batchAndPostEvents = async (eventUrl, kind, data) => {
513476
const config = {
514477
headers: {
@@ -519,20 +482,14 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => {
519482
};
520483

521484
try {
522-
const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', ');
523-
// await sleep();
524-
exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`)
525485
const response = await nodeRequest('POST',eventUrl,data,config);
526-
exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`)
527486
if(response.data.error) {
528487
throw({message: response.data.error});
529488
} else {
530489
exports.debug(`${kind} event successfull!`)
531490
exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - data.length);
532491
}
533492
} catch(error) {
534-
consoleHolder.log(error);
535-
exports.nodeRequestForLogs(`[Request Error] Error in sending request ${util.format(error)}`);
536493
if (error.response) {
537494
exports.debug(`EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error);
538495
} else {
@@ -572,7 +529,6 @@ exports.uploadEventData = async (eventData, run=0) => {
572529

573530
exports.requestQueueHandler.start();
574531
const { shouldProceed, proceedWithData, proceedWithUrl } = exports.requestQueueHandler.add(eventData);
575-
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`)
576532
if(!shouldProceed) {
577533
return;
578534
} else if(proceedWithData) {
@@ -589,11 +545,7 @@ exports.uploadEventData = async (eventData, run=0) => {
589545
};
590546

591547
try {
592-
const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', ');
593-
consoleHolder.log(eventsUuids);
594-
exports.nodeRequestForLogs(`[Request Send] for events:uuids ${eventsUuids}`)
595548
const response = await nodeRequest('POST',event_api_url,data,config);
596-
exports.nodeRequestForLogs(`[Request Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`)
597549
if(response.data.error) {
598550
throw({message: response.data.error});
599551
} else {
@@ -605,8 +557,6 @@ exports.uploadEventData = async (eventData, run=0) => {
605557
};
606558
}
607559
} catch(error) {
608-
consoleHolder.log(error);
609-
exports.nodeRequestForLogs(`[Request Error] Error in sending request ${util.format(error)}`);
610560
if (error.response) {
611561
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);
612562
} else {
@@ -704,7 +654,6 @@ exports.stopBuildUpstream = async () => {
704654
};
705655

706656
try {
707-
await this.nodeRequestForLogs(null, process.env.BS_TESTOPS_BUILD_HASHED_ID);
708657
const response = await nodeRequest('PUT',`api/v1/builds/${process.env.BS_TESTOPS_BUILD_HASHED_ID}/stop`,data,config);
709658
if(response.data && response.data.error) {
710659
throw({message: response.data.error});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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":[]}]

bin/testObservability/helper/requestQueueHandler.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder } = require('./constants');
2-
const { debug, batchAndPostEvents, nodeRequestForLogs } = require('./helper');
2+
const { debug, batchAndPostEvents } = require('./helper');
33

44
class RequestQueueHandler {
55
constructor() {
@@ -57,15 +57,13 @@ class RequestQueueHandler {
5757
}
5858

5959
shutdown = async () => {
60-
await nodeRequestForLogs(`Process id at shutdown is ${process.pid} q-length ${this.queue.length}`);
6160
this.removeEventBatchPolling('REMOVING');
6261
while(this.queue.length > 0) {
6362
const data = this.queue.slice(0,BATCH_SIZE);
6463
this.queue.splice(0,BATCH_SIZE);
6564
consoleHolder.log(this.queue.length + " the queue length ");
6665
await batchAndPostEvents(this.eventUrl,'Shutdown-Queue',data);
6766
}
68-
await nodeRequestForLogs(`Finished the shutdown hook at shutdown is ${process.pid}`);
6967
}
7068

7169
startEventBatchPolling = () => {

bin/testObservability/reporter/index.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const util = require('util');
44
const fs = require('fs');
55
const path = require('path');
6-
const { requireModule, nodeRequestForLogs } = require('../helper/helper');
6+
const { requireModule } = require('../helper/helper');
77
const Base = requireModule('mocha/lib/reporters/base.js'),
88
utils = requireModule('mocha/lib/utils.js');
99
const color = Base.color;
@@ -125,9 +125,7 @@ class MyReporter {
125125
})
126126

127127
.on(EVENT_TEST_PASS, async (test) => {
128-
await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PASS`);
129128
if(this.testObservability == true) {
130-
await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PASS for uuid: ${test.testAnalyticsId}`);
131129
if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
132130
if(test.testAnalyticsId) this.runStatusMarkedHash[test.testAnalyticsId] = true;
133131
await this.sendTestRunEvent(test);
@@ -136,9 +134,7 @@ class MyReporter {
136134
})
137135

138136
.on(EVENT_TEST_FAIL, async (test, err) => {
139-
await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_FAIL`);
140137
if(this.testObservability == true) {
141-
await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_FAIL for uuid: ${test.testAnalyticsId}`);
142138
if((test.testAnalyticsId && !this.runStatusMarkedHash[test.testAnalyticsId]) || (test.hookAnalyticsId && !this.runStatusMarkedHash[test.hookAnalyticsId])) {
143139
if(test.testAnalyticsId) {
144140
this.runStatusMarkedHash[test.testAnalyticsId] = true;
@@ -152,10 +148,8 @@ class MyReporter {
152148
})
153149

154150
.on(EVENT_TEST_PENDING, async (test) => {
155-
await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PENDING`);
156151
if(this.testObservability == true) {
157152
if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4();
158-
await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PENDING for uuid: ${test.testAnalyticsId}`);
159153
if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
160154
this.runStatusMarkedHash[test.testAnalyticsId] = true;
161155
await this.sendTestRunEvent(test,undefined,false,"TestRunSkipped");
@@ -164,17 +158,13 @@ class MyReporter {
164158
})
165159

166160
.on(EVENT_TEST_BEGIN, async (test) => {
167-
await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN`);
168-
await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`);
169161
if (this.runStatusMarkedHash[test.testAnalyticsId]) return;
170162
if(this.testObservability == true) {
171163
await this.testStarted(test);
172164
}
173165
})
174166

175167
.on(EVENT_TEST_END, async (test) => {
176-
await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_END`);
177-
await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`);
178168
if (this.runStatusMarkedHash[test.testAnalyticsId]) return;
179169
if(this.testObservability == true) {
180170
if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
@@ -225,8 +215,7 @@ class MyReporter {
225215
const lastTest = this.current_test;
226216
this.current_test = test;
227217
test.retryOf = null;
228-
test.testAnalyticsId = uuidv4();
229-
await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`);
218+
test.testAnalyticsId = uuidv4()
230219
test.started_at = (new Date()).toISOString();
231220
test.test_started_at = test.started_at;
232221
if(test._currentRetry > 0 && lastTest && lastTest.title == test.title) {
@@ -332,8 +321,6 @@ class MyReporter {
332321
}
333322
};
334323

335-
await nodeRequestForLogs(`${eventType} for uuid: ${testData.uuid}`);
336-
337324
if(eventType.match(/TestRunFinished/) || eventType.match(/TestRunSkipped/)) {
338325
testData['meta'].steps = JSON.parse(JSON.stringify(this.currentTestCucumberSteps));
339326
this.currentTestCucumberSteps = [];

0 commit comments

Comments
 (0)