forked from tombaranowicz/LoadTestingUsingNodeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
child.js
31 lines (26 loc) · 785 Bytes
/
child.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"use strict";
const axios = require("axios");
const argv = require('minimist')(process.argv.slice(2));
(async () => {
axios.interceptors.request.use(function (config) {
config.metadata = { startTime: new Date()}
return config;
}, function (error) {
return Promise.reject(error);
});
axios.interceptors.response.use(function (response) {
response.config.metadata.endTime = new Date()
response.duration = response.config.metadata.endTime - response.config.metadata.startTime
return response;
}, function (error) {
return Promise.reject(error);
});
axios.get(argv.url)
.then((response) => {
process.stdout.write(response.duration.toString());
process.exitCode = 0;
})
.catch((error) => {
process.exitCode = 1;
})
})();