testaro 53.0.1 → 53.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/netWatch.js +17 -13
- package/package.json +1 -1
- package/procs/doTestAct.js +7 -5
package/netWatch.js
CHANGED
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
|
|
32
32
|
// Module to keep secrets.
|
|
33
33
|
require('dotenv').config();
|
|
34
|
+
// Module to perform file operations.
|
|
35
|
+
const fs = require('fs/promises');
|
|
34
36
|
// Module to validate jobs.
|
|
35
37
|
const {isValidJob} = require('./procs/job');
|
|
36
38
|
// Modules to make requests to servers.
|
|
@@ -63,8 +65,14 @@ const serveObject = (object, response) => {
|
|
|
63
65
|
response.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
64
66
|
response.end(JSON.stringify(object));
|
|
65
67
|
};
|
|
66
|
-
// Removes the query if any, or otherwise the final segment, from a URL.
|
|
68
|
+
// Removes the query, if any, or otherwise the final segment, from a URL.
|
|
67
69
|
const getURLBase = url => url.replace(/[?/][^?/.]+$/, '');
|
|
70
|
+
// Saves a report.
|
|
71
|
+
const rescueReport = async reportJSON => {
|
|
72
|
+
const reportDir = 'data/reports';
|
|
73
|
+
await fs.mkdir(reportDir, { recursive: true });
|
|
74
|
+
await fs.writeFile(reportDir, reportJSON);
|
|
75
|
+
};
|
|
68
76
|
/*
|
|
69
77
|
Requests a network job and, when found, performs and reports it.
|
|
70
78
|
Arguments:
|
|
@@ -128,7 +136,7 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
|
|
|
128
136
|
if (auths[urlIndex]) {
|
|
129
137
|
requestOptions.method = 'POST';
|
|
130
138
|
}
|
|
131
|
-
client.request(jobURL,
|
|
139
|
+
client.request(jobURL, requestOptions, response => {
|
|
132
140
|
const chunks = [];
|
|
133
141
|
response
|
|
134
142
|
// If the response throws an error:
|
|
@@ -197,6 +205,8 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
|
|
|
197
205
|
repResponse
|
|
198
206
|
// If the response to the report threw an error:
|
|
199
207
|
.on('error', async error => {
|
|
208
|
+
// Rescue the report.
|
|
209
|
+
await rescueReport(reportJSON);
|
|
200
210
|
// Report this.
|
|
201
211
|
console.log(`${reportLogStart}error message ${error.message}\n`);
|
|
202
212
|
resolve(true);
|
|
@@ -217,9 +227,9 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
|
|
|
217
227
|
}
|
|
218
228
|
// Otherwise, i.e. if it is not JSON:
|
|
219
229
|
catch(error) {
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
// Report
|
|
230
|
+
// Rescue the report.
|
|
231
|
+
await rescueReport(reportJSON);
|
|
232
|
+
// Report this.
|
|
223
233
|
console.log(
|
|
224
234
|
`ERROR: ${reportLogStart}status ${repResponse.statusCode}, error message ${error.message}, and response ${content.slice(0, 1000)}\n`
|
|
225
235
|
);
|
|
@@ -232,8 +242,8 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
|
|
|
232
242
|
})
|
|
233
243
|
// If the report submission throws an error:
|
|
234
244
|
.on('error', async error => {
|
|
235
|
-
//
|
|
236
|
-
|
|
245
|
+
// Rescue the report.
|
|
246
|
+
await rescueReport(reportJSON);
|
|
237
247
|
// Report this.
|
|
238
248
|
console.log(
|
|
239
249
|
`ERROR ${error.code} in report submission: ${reportLogStart}error message ${error.message}\n`
|
|
@@ -253,8 +263,6 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
|
|
|
253
263
|
}
|
|
254
264
|
// Otherwise, i.e. if it is not JSON:
|
|
255
265
|
catch(error) {
|
|
256
|
-
// Abort the watch.
|
|
257
|
-
abort = true;
|
|
258
266
|
// Report this.
|
|
259
267
|
console.log(`ERROR: Job request got non-JSON response (${error.message})`);
|
|
260
268
|
resolve(true);
|
|
@@ -277,15 +285,11 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
|
|
|
277
285
|
else if (error.message) {
|
|
278
286
|
// Report this.
|
|
279
287
|
console.log(`ERROR: ${logStart}got error message ${error.message.slice(0, 200)}`);
|
|
280
|
-
// Abort the watch.
|
|
281
|
-
abort = true;
|
|
282
288
|
}
|
|
283
289
|
// Otherwise, i.e. if it was any other error with no message:
|
|
284
290
|
else {
|
|
285
291
|
// Report this.
|
|
286
292
|
console.log(`ERROR: ${logStart}got an error with no message`);
|
|
287
|
-
// Abort the watch.
|
|
288
|
-
abort = true;
|
|
289
293
|
}
|
|
290
294
|
resolve(true);
|
|
291
295
|
})
|
package/package.json
CHANGED
package/procs/doTestAct.js
CHANGED
|
@@ -47,9 +47,11 @@ const actIndex = Number.parseInt(process.argv[2]);
|
|
|
47
47
|
// FUNCTIONS
|
|
48
48
|
|
|
49
49
|
const doTestAct = async () => {
|
|
50
|
-
const
|
|
50
|
+
const tempReportDir = `${__dirname}/../temp`;
|
|
51
|
+
const tempReportPath = `${tempReportDir}/report.json`;
|
|
52
|
+
await fs.mkdir(tempReportDir, {recursive: true});
|
|
51
53
|
// Get the saved report.
|
|
52
|
-
const reportJSON = await fs.readFile(
|
|
54
|
+
const reportJSON = await fs.readFile(tempReportPath, 'utf8');
|
|
53
55
|
const report = JSON.parse(reportJSON);
|
|
54
56
|
// Get the act.
|
|
55
57
|
const act = report.acts[actIndex];
|
|
@@ -67,7 +69,7 @@ const doTestAct = async () => {
|
|
|
67
69
|
if (report.jobData && report.jobData.aborted) {
|
|
68
70
|
// Save the revised report.
|
|
69
71
|
const reportJSON = JSON.stringify(report);
|
|
70
|
-
await fs.writeFile(
|
|
72
|
+
await fs.writeFile(tempReportPath, `${reportJSON}\n`);
|
|
71
73
|
// Report this.
|
|
72
74
|
process.send('ERROR: Job aborted');
|
|
73
75
|
}
|
|
@@ -97,7 +99,7 @@ const doTestAct = async () => {
|
|
|
97
99
|
}
|
|
98
100
|
const reportJSON = JSON.stringify(report);
|
|
99
101
|
// Save the revised report.
|
|
100
|
-
await fs.writeFile(
|
|
102
|
+
await fs.writeFile(tempReportPath, reportJSON);
|
|
101
103
|
// Send a completion message.
|
|
102
104
|
process.send('Act completed');
|
|
103
105
|
}
|
|
@@ -106,7 +108,7 @@ const doTestAct = async () => {
|
|
|
106
108
|
catch(error) {
|
|
107
109
|
// Save the revised report.
|
|
108
110
|
const reportJSON = JSON.stringify(report);
|
|
109
|
-
await fs.writeFile(
|
|
111
|
+
await fs.writeFile(tempReportPath, reportJSON);
|
|
110
112
|
// Report the failure.
|
|
111
113
|
const message = error.message.slice(0, 400);
|
|
112
114
|
console.log(`ERROR: Test act ${act.which} failed (${message})`);
|