Skip to content

Commit

Permalink
Merge pull request #848 from 07souravkunda/fix_o11y_timeouts
Browse files Browse the repository at this point in the history
Fix o11y timeouts
  • Loading branch information
pranavj1001 authored Jul 26, 2024
2 parents 42a6b2c + be56249 commit 6ac7597
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
13 changes: 13 additions & 0 deletions bin/testObservability/helper/cleanupQueueSync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Sending all the remaining queues for synchronous manner
*/

const RequestQueueHandler = require('./requestQueueHandler');

const shutdown = async () => {
const requestHandler = new RequestQueueHandler();
requestHandler.queue = require(process.argv[2].trim());
await requestHandler.shutdown();
}

shutdown();
2 changes: 2 additions & 0 deletions bin/testObservability/helper/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_QUEUES_FILE = `pending_queues_${process.pid}.json`;
5 changes: 3 additions & 2 deletions bin/testObservability/helper/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -114,7 +114,8 @@ const nodeRequest = (type, url, data, config) => {
url: `${API_URL}/${url}`,
body: data,
json: config.headers['Content-Type'] === 'application/json',
agent: this.httpsKeepAliveAgent
agent: this.httpsKeepAliveAgent,
maxAttempts: 2
}};

if(url === exports.requestQueueHandler.screenshotEventUrl) {
Expand Down
17 changes: 15 additions & 2 deletions bin/testObservability/helper/requestQueueHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder } = require('./constants');
const { debug, batchAndPostEvents } = require('./helper');
const fs = require('fs');
const cp = require('child_process');
const path = require('path');

const { BATCH_SIZE, BATCH_INTERVAL, PENDING_QUEUES_FILE } = require('./constants');
const { batchAndPostEvents } = require('./helper');

class RequestQueueHandler {
constructor() {
Expand Down Expand Up @@ -48,6 +52,15 @@ class RequestQueueHandler {
}
}

shutdownSync = () => {
this.removeEventBatchPolling('REMOVING');

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_QUEUES_FILE)], {stdio: 'inherit'});
fs.unlinkSync(path.join(__dirname, PENDING_QUEUES_FILE));
}

shutdown = async () => {
this.removeEventBatchPolling('REMOVING');
while(this.queue.length > 0) {
Expand Down
4 changes: 4 additions & 0 deletions bin/testObservability/plugin/ipcServer.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -26,6 +27,9 @@ 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();
});

});
Expand Down
1 change: 0 additions & 1 deletion bin/testObservability/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ class MyReporter {
}

await this.uploadTestSteps();
await requestQueueHandler.shutdown();
});
}

Expand Down

0 comments on commit 6ac7597

Please sign in to comment.