-
Notifications
You must be signed in to change notification settings - Fork 0
/
canon.js
41 lines (33 loc) · 1.02 KB
/
canon.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
32
33
34
35
36
37
38
39
40
41
"use strict";
const autocannon = require("autocannon");
const instance = autocannon(
{
url: "http://localhost:8063/hola",
connections: 20,
amount: 100,
timeout: 1000
// setupClient: setupClient
},
(err, result) => handleResults(result)
);
// results passed to the callback are the same as those emitted from the done events
instance.on("done", handleResults);
instance.on("tick", () => console.log("ticking"));
instance.on("response", handleResponse);
function setupClient(client) {
client.on("body", console.log); // console.log a response body when its received
}
function handleResponse(client, statusCode, resBytes, responseTime) {
console.log(
`Got response with code ${statusCode} in ${responseTime} milliseconds`
);
console.log(`response: ${resBytes.toString()}`);
//update the body or headers
client.setHeaders({ new: "header" });
client.setBody("new body");
client.setHeadersAndBody({ new: "header" }, "new body");
}
function handleResults(result) {
console.log(result);
// ...
}