Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion nightwatch/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -541,6 +546,9 @@ 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
Expand Down
7 changes: 6 additions & 1 deletion src/testObservability.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -521,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) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions src/utils/requestQueueHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ class RequestQueueHandler {
}

start() {
Logger.debug(`start requestQueueHandler called`);
if (!this.started) {
Logger.debug(`Starting requestQueueHandler now`);
this.started = true;
this.startEventBatchPolling();
}
}

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 {
Expand All @@ -31,11 +34,14 @@ 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);
Logger.debug(`Processing batch of events: ${JSON.stringify(data)}, remaining queue: ${JSON.stringify(this.queue)}`);
this.resetEventBatchPolling();
}

Expand Down Expand Up @@ -63,15 +69,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();
}
Expand Down Expand Up @@ -100,7 +109,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 {
Expand Down