forked from alexfernandez/loadtest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest-generator.js
37 lines (32 loc) · 892 Bytes
/
request-generator.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
'use strict';
/**
* Sample request generator usage.
* Contributed by jjohnsonvng:
* https://github.com/alexfernandez/loadtest/issues/86#issuecomment-211579639
*/
const loadtest = require('../lib/loadtest.js');
const options = {
url: 'http://yourHost',
concurrency: 5,
method: 'POST',
body:'',
requestsPerSecond:5,
maxSeconds:30,
requestGenerator: (params, options, client, callback) => {
const message = '{"hi": "ho"}';
options.headers['Content-Length'] = message.length;
options.headers['Content-Type'] = 'application/json';
options.body = 'YourPostData';
options.path = 'YourURLPath';
const request = client(options, callback);
request.write(message);
return request;
}
};
loadtest.loadTest(options, (error, results) => {
if (error) {
return console.error('Got an error: %s', error);
}
console.log(results);
console.log('Tests run successfully');
});