forked from graemerocher/framework-comparison-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.js
30 lines (26 loc) · 915 Bytes
/
time.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
const spawn = require("child_process").spawn;
const request = require("request");
const pingIntervalMs = 10;
const args = process.argv.slice(2);
if (args.length == 0) {
console.log('The path of java executable jar must be specified !');
}
const proc = spawn("java", ["-jar", args[0]]);
const startTime = new Date().getTime();
const intervalHandle = setInterval(() => {
request("http://localhost:8080/hello/John", (error, response, body) => {
if (!error && response && response.statusCode === 200 && body) {
const time = new Date().getTime() - startTime;
console.log(time + " ms");
clearInterval(intervalHandle);
proc.kill();
process.exit(0);
} else {
// @ts-ignore
if (!error || !error.code === "ECONNREFUSED") {
console.log(error ? error : response.statusCode);
}
}
}
);
}, pingIntervalMs);