From f8ad83d7c09b86fce9c535e23945cbffa8a6015b Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 5 Dec 2025 20:39:35 +0530 Subject: [PATCH 1/5] added logging --- nightwatch/globals.js | 4 ++++ src/testObservability.js | 2 ++ src/utils/requestQueueHandler.js | 2 ++ 3 files changed, 8 insertions(+) diff --git a/nightwatch/globals.js b/nightwatch/globals.js index 465250a..3720c89 100644 --- a/nightwatch/globals.js +++ b/nightwatch/globals.js @@ -495,6 +495,10 @@ module.exports = { // This will be run after each test suite is finished async afterEach(settings) { + if (testEventPromises.length > 0) { + await Promise.all(testEventPromises); + testEventPromises.length = 0; // Clear the array + } }, beforeChildProcess(settings) { diff --git a/src/testObservability.js b/src/testObservability.js index 11f78ee..94f2462 100644 --- a/src/testObservability.js +++ b/src/testObservability.js @@ -274,7 +274,9 @@ class TestObservability { await helper.uploadPending(); await helper.shutDownRequestHandler(); try { + Logger.debug(`[${new Date().toISOString()}] Making request to stop build ${process.env.BROWSERSTACK_TESTHUB_UUID}`); const response = await makeRequest('PUT', `api/v1/builds/${process.env.BROWSERSTACK_TESTHUB_UUID}/stop`, data, config, API_URL, false); + Logger.debug(`[${new Date().toISOString()}] Received response from stop build: status=${response.status}, hasError=${!!(response.data?.error)}`); if (response.data?.error) { throw {message: response.data.error}; } else { diff --git a/src/utils/requestQueueHandler.js b/src/utils/requestQueueHandler.js index f9ad180..b435fa6 100644 --- a/src/utils/requestQueueHandler.js +++ b/src/utils/requestQueueHandler.js @@ -100,7 +100,9 @@ class RequestQueueHandler { }; try { + Logger.debug(`[${new Date().toISOString()}] Making request to with ${JSON.stringify(data)}`); const response = await makeRequest('POST', eventUrl, data, config); + Logger.debug(`[${new Date().toISOString()}] Received response from status=${response.status}, hasError=${!!(response?.data && response?.data?.error)}`); if (response.data && response.data.error) { throw ({message: response.data.error}); } else { From ca62e013201f5d8fba6ec3c2f39e1a7931cb21fb Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Fri, 5 Dec 2025 22:06:55 +0530 Subject: [PATCH 2/5] changes --- nightwatch/globals.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/nightwatch/globals.js b/nightwatch/globals.js index 3720c89..465250a 100644 --- a/nightwatch/globals.js +++ b/nightwatch/globals.js @@ -495,10 +495,6 @@ module.exports = { // This will be run after each test suite is finished async afterEach(settings) { - if (testEventPromises.length > 0) { - await Promise.all(testEventPromises); - testEventPromises.length = 0; // Clear the array - } }, beforeChildProcess(settings) { From 2c57362ca3277a0484babf913da7f20b7a88f10f Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 8 Dec 2025 10:58:12 +0530 Subject: [PATCH 3/5] added more logging --- nightwatch/globals.js | 9 ++++++++- src/testObservability.js | 5 ++++- src/utils/requestQueueHandler.js | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/nightwatch/globals.js b/nightwatch/globals.js index 465250a..95d23d0 100644 --- a/nightwatch/globals.js +++ b/nightwatch/globals.js @@ -273,13 +273,16 @@ module.exports = { const uuid = process.env.TEST_RUN_UUID || TestMap.getUUID(test); if (TestMap.hasTestFinished(uuid)) { Logger.debug(`Test with UUID ${uuid} already marked as finished, skipping duplicate TestRunFinished event`); - return; } try { + Logger.debug(`Going for accessibility processing: ${uuid}`); await accessibilityAutomation.afterEachExecution(test, uuid); + Logger.debug(`Completed accessibility processing: ${uuid}`); if (testRunner !== 'cucumber'){ + Logger.debug(`Sending TestRunFinished event for UUID from globals: ${uuid}`); testEventPromises.push(testObservability.sendTestRunEvent('TestRunFinished', test, uuid)); + Logger.debug(`Pushed in the testEventPromises for TestRunFinished event: ${uuid}`); TestMap.markTestFinished(uuid); } @@ -473,6 +476,8 @@ module.exports = { await helper.deleteRerunFile(); } try { + Logger.debug('after hook called'); + Logger.debug(`Pending test event promises: ${testEventPromises.length}`); if (testEventPromises.length > 0) { await Promise.all(testEventPromises); testEventPromises.length = 0; // Clear the array @@ -541,6 +546,8 @@ module.exports = { }, async afterChildProcess() { + Logger.debug('afterChildProcess hook called'); + Logger.debug(`Pending test event promises: ${testEventPromises.length}`); if (testEventPromises.length > 0) { await Promise.all(testEventPromises); testEventPromises.length = 0; // Clear the array diff --git a/src/testObservability.js b/src/testObservability.js index 94f2462..35fc5a0 100644 --- a/src/testObservability.js +++ b/src/testObservability.js @@ -523,12 +523,15 @@ class TestObservability { } await this.processTestRunData (eventData, uuid); } - const uploadData = { event_type: eventType, test_run: testData }; + + Logger.debug(`Uploading Test Data for ${eventType}: ${JSON.stringify(testData)}`); await helper.uploadEventData(uploadData); + Logger.debug(`Uploaded Test Data for ${eventType}`); + } async sendHookRunEvent(eventData, testFileReport, eventType, uuid, hookType, sectionName, hooks) { diff --git a/src/utils/requestQueueHandler.js b/src/utils/requestQueueHandler.js index b435fa6..9017f50 100644 --- a/src/utils/requestQueueHandler.js +++ b/src/utils/requestQueueHandler.js @@ -21,6 +21,7 @@ class RequestQueueHandler { } add (event) { + Logger.debug(`Adding event to queue: ${JSON.stringify(event)}`); if (this.BATCH_EVENT_TYPES.includes(event.event_type)) { if (event.logs && event.logs[0] && event.logs[0].kind === 'TEST_SCREENSHOT') { return { @@ -36,6 +37,7 @@ class RequestQueueHandler { if (shouldProceed) { data = this.queue.slice(0, BATCH_SIZE); this.queue.splice(0, BATCH_SIZE); + Logger.debug(`Processing batch of events: ${JSON.stringify(data)}, remaining queue: ${JSON.stringify(this.queue)}`); this.resetEventBatchPolling(); } @@ -63,15 +65,18 @@ class RequestQueueHandler { startEventBatchPolling () { this.pollEventBatchInterval = setInterval(async () => { + Logger.debug(`Polling event batch queue, current queue length: ${this.queue.length}`); if (this.queue.length > 0) { const data = this.queue.slice(0, BATCH_SIZE); this.queue.splice(0, BATCH_SIZE); + Logger.debug(`Sending event batch queue`); await this.batchAndPostEvents(this.eventUrl, 'Interval-Queue', data); } }, BATCH_INTERVAL); } resetEventBatchPolling () { + Logger.debug(`Resetting event batch polling`); this.removeEventBatchPolling('RESETTING'); this.startEventBatchPolling(); } From a033a0a70c7fcc9fb9e73acdf382ad87cb2c5d82 Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 8 Dec 2025 17:35:28 +0530 Subject: [PATCH 4/5] log changes --- src/utils/requestQueueHandler.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/requestQueueHandler.js b/src/utils/requestQueueHandler.js index 9017f50..03889dd 100644 --- a/src/utils/requestQueueHandler.js +++ b/src/utils/requestQueueHandler.js @@ -32,8 +32,10 @@ class RequestQueueHandler { } this.queue.push(event); + Logger.debug(`Current queue: ${JSON.stringify(this.queue)}`); let data = null; const shouldProceed = this.shouldProceed(); + Logger.debug(`Should proceed with batch: ${shouldProceed}`); if (shouldProceed) { data = this.queue.slice(0, BATCH_SIZE); this.queue.splice(0, BATCH_SIZE); From 2b9826bb571d63cc5acf74cd0b8bc7b31d15bd2b Mon Sep 17 00:00:00 2001 From: Bhargavi-BS Date: Mon, 8 Dec 2025 18:11:47 +0530 Subject: [PATCH 5/5] log changes --- nightwatch/globals.js | 1 + src/utils/helper.js | 2 +- src/utils/requestQueueHandler.js | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/nightwatch/globals.js b/nightwatch/globals.js index 95d23d0..b360c1b 100644 --- a/nightwatch/globals.js +++ b/nightwatch/globals.js @@ -548,6 +548,7 @@ module.exports = { async afterChildProcess() { Logger.debug('afterChildProcess hook called'); Logger.debug(`Pending test event promises: ${testEventPromises.length}`); + await helper.shutDownRequestHandler(); if (testEventPromises.length > 0) { await Promise.all(testEventPromises); testEventPromises.length = 0; // Clear the array diff --git a/src/utils/helper.js b/src/utils/helper.js index ba103d6..a1ac419 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -555,7 +555,7 @@ exports.uploadEventData = async (eventData) => { } let data = eventData; let event_api_url = 'api/v1/event'; - + Logger.debug(`Starting requestQueueHandler before uploading event data for {${eventData.event_type}}`); requestQueueHandler.start(); const { shouldProceed, diff --git a/src/utils/requestQueueHandler.js b/src/utils/requestQueueHandler.js index 03889dd..4c05c88 100644 --- a/src/utils/requestQueueHandler.js +++ b/src/utils/requestQueueHandler.js @@ -14,7 +14,9 @@ class RequestQueueHandler { } start() { + Logger.debug(`start requestQueueHandler called`); if (!this.started) { + Logger.debug(`Starting requestQueueHandler now`); this.started = true; this.startEventBatchPolling(); }