Skip to content

Commit 6ac7597

Browse files
authored
Merge pull request #848 from 07souravkunda/fix_o11y_timeouts
Fix o11y timeouts
2 parents 42a6b2c + be56249 commit 6ac7597

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Sending all the remaining queues for synchronous manner
3+
*/
4+
5+
const RequestQueueHandler = require('./requestQueueHandler');
6+
7+
const shutdown = async () => {
8+
const requestHandler = new RequestQueueHandler();
9+
requestHandler.queue = require(process.argv[2].trim());
10+
await requestHandler.shutdown();
11+
}
12+
13+
shutdown();

bin/testObservability/helper/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ exports.OBSERVABILITY_ENV_VARS = [
3232
exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservability/reporter';
3333

3434
exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter');
35+
36+
exports.PENDING_QUEUES_FILE = `pending_queues_${process.pid}.json`;

bin/testObservability/helper/helper.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require('fs');
22
const path = require('path');
33
const http = require('http');
44
const https = require('https');
5-
const request = require('request');
5+
const request = require('requestretry');
66
const { v4: uuidv4 } = require('uuid');
77
const os = require('os');
88
const { promisify } = require('util');
@@ -114,7 +114,8 @@ const nodeRequest = (type, url, data, config) => {
114114
url: `${API_URL}/${url}`,
115115
body: data,
116116
json: config.headers['Content-Type'] === 'application/json',
117-
agent: this.httpsKeepAliveAgent
117+
agent: this.httpsKeepAliveAgent,
118+
maxAttempts: 2
118119
}};
119120

120121
if(url === exports.requestQueueHandler.screenshotEventUrl) {

bin/testObservability/helper/requestQueueHandler.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder } = require('./constants');
2-
const { debug, batchAndPostEvents } = require('./helper');
1+
const fs = require('fs');
2+
const cp = require('child_process');
3+
const path = require('path');
4+
5+
const { BATCH_SIZE, BATCH_INTERVAL, PENDING_QUEUES_FILE } = require('./constants');
6+
const { batchAndPostEvents } = require('./helper');
37

48
class RequestQueueHandler {
59
constructor() {
@@ -48,6 +52,15 @@ class RequestQueueHandler {
4852
}
4953
}
5054

55+
shutdownSync = () => {
56+
this.removeEventBatchPolling('REMOVING');
57+
58+
fs.writeFileSync(path.join(__dirname, PENDING_QUEUES_FILE), JSON.stringify(this.queue));
59+
this.queue = [];
60+
cp.spawnSync('node', [path.join(__dirname, 'cleanupQueueSync.js'), path.join(__dirname, PENDING_QUEUES_FILE)], {stdio: 'inherit'});
61+
fs.unlinkSync(path.join(__dirname, PENDING_QUEUES_FILE));
62+
}
63+
5164
shutdown = async () => {
5265
this.removeEventBatchPolling('REMOVING');
5366
while(this.queue.length > 0) {

bin/testObservability/plugin/ipcServer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const ipc = require('node-ipc');
22
const { consoleHolder } = require('../helper/constants');
3+
const { requestQueueHandler } = require('../helper/helper');
34

45
exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => {
56
if (ipc.server) {
@@ -26,6 +27,9 @@ exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => {
2627
process.on('exit', () => {
2728
unsubscribeServerEvents(ipc.server);
2829
ipc.server.stop();
30+
// Cleaning up all remaining event in request queue handler. Any synchronous operations
31+
// on exit handler will block the process
32+
requestQueueHandler.shutdownSync();
2933
});
3034

3135
});

bin/testObservability/reporter/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ class MyReporter {
186186
}
187187

188188
await this.uploadTestSteps();
189-
await requestQueueHandler.shutdown();
190189
});
191190
}
192191

0 commit comments

Comments
 (0)