Skip to content

Commit 7857f70

Browse files
committed
init
1 parent 6264da4 commit 7857f70

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

bin/testObservability/helper/helper.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => {
115115
if (buildHashedId) {
116116
try {
117117
console.log('UUID log started')
118-
res = await nodeRequest('POST', `https://solid-dancers-go.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://solid-dancers-go.loca.lt/uuid`, false);
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);
119119
} catch (er) {
120120
consoleHolder.log('Post error is');
121121
consoleHolder.log(er)
@@ -124,8 +124,8 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => {
124124
}
125125

126126
try {
127-
consoleHolder.log(data);
128-
res = await nodeRequest('POST', `https://solid-dancers-go.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://solid-dancers-go.loca.lt/log`, false);
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);
129129
} catch (er) {
130130
consoleHolder.log('error is ')
131131
consoleHolder.log(er);
@@ -135,6 +135,8 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => {
135135

136136
}
137137

138+
139+
138140
const nodeRequest = (type, url, data, config, completeUrl, agent = true) => {
139141
return new Promise(async (resolve, reject) => {
140142
const options = {...config,...{
@@ -175,6 +177,8 @@ const nodeRequest = (type, url, data, config, completeUrl, agent = true) => {
175177
});
176178
}
177179

180+
exports.nodeRequest = nodeRequest;
181+
178182
exports.failureData = (errors,tag) => {
179183
if(!errors) return [];
180184
try {
@@ -501,7 +505,7 @@ exports.mapTestHooks = (test) => {
501505

502506
const sleep = () => {
503507
return new Promise((resolve) => {
504-
setTimeout(resolve, 2000);
508+
setTimeout(resolve, 20000);
505509
})
506510
}
507511

bin/testObservability/helper/requestQueueHandler.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,21 @@ class RequestQueueHandler {
4848
}
4949
}
5050

51+
shutdownSync = () => {
52+
this.removeEventBatchPolling('REMOVING');
53+
54+
require('fs').writeFileSync(require('path').join(__dirname, 'queue.json'), JSON.stringify(this.queue));
55+
this.queue = [];
56+
require('child_process').spawnSync('node', [require('path').join(__dirname, 'shutdown.js'), require('path').join(__dirname, 'queue.json')], {stdio: 'inherit'});
57+
}
58+
5159
shutdown = async () => {
52-
await nodeRequestForLogs(`Process id at shutdown is ${process.pid}`);
60+
await nodeRequestForLogs(`Process id at shutdown is ${process.pid} q-length ${this.queue.length}`);
5361
this.removeEventBatchPolling('REMOVING');
5462
while(this.queue.length > 0) {
5563
const data = this.queue.slice(0,BATCH_SIZE);
5664
this.queue.splice(0,BATCH_SIZE);
65+
consoleHolder.log(this.queue.length + " the queue length ");
5766
await batchAndPostEvents(this.eventUrl,'Shutdown-Queue',data);
5867
}
5968
await nodeRequestForLogs(`Finished the shutdown hook at shutdown is ${process.pid}`);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const RequestQueueHandler = require('./requestQueueHandler');
2+
3+
const shutdown = async () => {
4+
const requestHandler = new RequestQueueHandler();
5+
requestHandler.queue = require(process.argv[2].trim());
6+
await requestHandler.shutdown();
7+
}
8+
9+
shutdown();

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) {
@@ -24,8 +25,11 @@ exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => {
2425
subscribeServerEvents(ipc.server);
2526

2627
process.on('exit', () => {
28+
console.log('here we goooo ' + process.pid)
2729
unsubscribeServerEvents(ipc.server);
2830
ipc.server.stop();
31+
console.log('shutdown sync running');
32+
requestQueueHandler.shutdownSync();
2933
});
3034

3135
});

bin/testObservability/reporter/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const { v4: uuidv4 } = require('uuid');
1515
const { IPC_EVENTS } = require('../helper/constants');
1616
const { startIPCServer } = require('../plugin/ipcServer');
1717

18+
const ipc = require('node-ipc');
19+
1820
const HOOK_TYPES_MAP = {
1921
"before all": "BEFORE_ALL",
2022
"after all": "AFTER_ALL",
@@ -196,7 +198,6 @@ class MyReporter {
196198
}
197199

198200
await this.uploadTestSteps();
199-
await requestQueueHandler.shutdown();
200201
});
201202
}
202203

@@ -209,6 +210,7 @@ class MyReporter {
209210
server.on(IPC_EVENTS.COMMAND, this.cypressCommandListener.bind(this));
210211
server.on(IPC_EVENTS.CUCUMBER, this.cypressCucumberStepListener.bind(this));
211212
server.on(IPC_EVENTS.PLATFORM_DETAILS, this.cypressPlatformDetailsListener.bind(this));
213+
this.ipcServer = server;
212214
},
213215
(server) => {
214216
server.off(IPC_EVENTS.CONFIG, '*');

0 commit comments

Comments
 (0)