loadtest 5.1.2 → 6.0.0
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/.eslintrc +1 -1
- package/README.md +80 -45
- package/bin/loadtest.js +26 -154
- package/bin/testserver.js +5 -12
- package/index.js +6 -12
- package/lib/baseClient.js +5 -22
- package/lib/config.js +9 -24
- package/lib/headers.js +3 -64
- package/lib/hrtimer.js +2 -55
- package/lib/httpClient.js +19 -64
- package/lib/latency.js +25 -147
- package/lib/loadtest.js +19 -150
- package/lib/options.js +156 -0
- package/lib/testserver.js +15 -65
- package/lib/websocket.js +8 -54
- package/package.json +8 -8
- package/sample/post-file.js +13 -0
- package/sample/request-generator.js +2 -4
- package/test/all.js +33 -0
- package/test/body-generator.js +41 -0
- package/test/headers.js +51 -0
- package/test/hrtimer.js +39 -0
- package/test/httpClient.js +22 -0
- package/{lib → test}/integration.js +13 -35
- package/test/latency.js +81 -0
- package/test/loadtest.js +87 -0
- package/{lib → test}/request-generator.js +9 -21
- package/test/testserver.js +24 -0
- package/test/websocket.js +23 -0
- package/test.js +0 -36
- /package/{test → sample}/.loadtestrc +0 -0
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Sample request generator usage.
|
|
5
3
|
* Contributed by jjohnsonvng:
|
|
6
4
|
* https://github.com/alexfernandez/loadtest/issues/86#issuecomment-211579639
|
|
7
5
|
*/
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
import {loadTest} from '../index.js'
|
|
10
8
|
|
|
11
9
|
const options = {
|
|
12
10
|
url: 'http://yourHost',
|
|
@@ -27,7 +25,7 @@ const options = {
|
|
|
27
25
|
}
|
|
28
26
|
};
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
loadTest(options, (error, results) => {
|
|
31
29
|
if (error) {
|
|
32
30
|
return console.error('Got an error: %s', error);
|
|
33
31
|
}
|
package/test/all.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run package tests.
|
|
3
|
+
* (C) 2013 Alex Fernández.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import testing from 'testing'
|
|
7
|
+
import {test as testHrtimer} from './hrtimer.js'
|
|
8
|
+
import {test as testHeaders} from './headers.js'
|
|
9
|
+
import {test as testLatency} from './latency.js'
|
|
10
|
+
import {test as testHttpClient} from './httpClient.js'
|
|
11
|
+
import {test as testServer} from './testserver.js'
|
|
12
|
+
import {test as testRequestGenerator} from './request-generator.js'
|
|
13
|
+
import {test as testBodyGenerator} from './body-generator.js'
|
|
14
|
+
import {test as testLoadtest} from './loadtest.js'
|
|
15
|
+
import {test as testWebsocket} from './websocket.js'
|
|
16
|
+
import {test as integrationTest} from './integration.js'
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Run all module tests.
|
|
21
|
+
*/
|
|
22
|
+
function test() {
|
|
23
|
+
const tests = [
|
|
24
|
+
testHrtimer, testHeaders, testLatency, testHttpClient,
|
|
25
|
+
testServer, integrationTest, testLoadtest, testWebsocket,
|
|
26
|
+
testRequestGenerator, testBodyGenerator,
|
|
27
|
+
];
|
|
28
|
+
testing.run(tests, 4200);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
test()
|
|
32
|
+
|
|
33
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import testing from 'testing'
|
|
2
|
+
import {loadTest} from '../lib/loadtest.js'
|
|
3
|
+
import {startServer} from '../lib/testserver.js'
|
|
4
|
+
|
|
5
|
+
const PORT = 10453;
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function testBodyGenerator(callback) {
|
|
9
|
+
const server = startServer({port: PORT}, error => {
|
|
10
|
+
if (error) {
|
|
11
|
+
return callback('Could not start test server');
|
|
12
|
+
}
|
|
13
|
+
const options = {
|
|
14
|
+
url: 'http://localhost:' + PORT,
|
|
15
|
+
requestsPerSecond: 100,
|
|
16
|
+
maxRequests: 100,
|
|
17
|
+
concurrency: 10,
|
|
18
|
+
postFile: 'sample/post-file.js',
|
|
19
|
+
}
|
|
20
|
+
loadTest(options, (error, result) => {
|
|
21
|
+
if (error) {
|
|
22
|
+
console.error(error)
|
|
23
|
+
return callback(`Could not run load test with postFile: ${error.message}`);
|
|
24
|
+
}
|
|
25
|
+
server.close(error => {
|
|
26
|
+
if (error) {
|
|
27
|
+
return callback('Could not close test server');
|
|
28
|
+
}
|
|
29
|
+
return callback(null, 'bodyGenerator succeeded: ' + JSON.stringify(result));
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Run all tests.
|
|
37
|
+
*/
|
|
38
|
+
export function test(callback) {
|
|
39
|
+
testing.run([testBodyGenerator], 4000, callback);
|
|
40
|
+
}
|
|
41
|
+
|
package/test/headers.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import testing from 'testing'
|
|
2
|
+
import {addHeaders, addUserAgent} from '../lib/headers.js'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function testAddHeaders(callback) {
|
|
6
|
+
const tests = [ {
|
|
7
|
+
raw: 'k:v',
|
|
8
|
+
headers: { 'k': 'v' }
|
|
9
|
+
}, {
|
|
10
|
+
raw: ['k:v', 'k:v2'],
|
|
11
|
+
headers: { 'k': 'v2' }
|
|
12
|
+
}, {
|
|
13
|
+
raw: ['k:v', 'k2:v2'],
|
|
14
|
+
headers: { 'k': 'v', 'k2': 'v2' }
|
|
15
|
+
}, {
|
|
16
|
+
raw: 'K:v',
|
|
17
|
+
headers: { 'k': 'v' }
|
|
18
|
+
}, {
|
|
19
|
+
raw: 'k:v:w',
|
|
20
|
+
headers: { 'k': 'v:w' }
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
tests.forEach(function(test) {
|
|
24
|
+
const headers = {};
|
|
25
|
+
addHeaders(test.raw, headers);
|
|
26
|
+
testing.assertEquals(headers, test.headers, 'Wrong headers', callback);
|
|
27
|
+
});
|
|
28
|
+
testing.success(callback);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function testAddUserAgent(callback) {
|
|
32
|
+
const headers = {'k': 'v', 'q': 'r' };
|
|
33
|
+
addUserAgent(headers);
|
|
34
|
+
testing.assertEquals(Object.keys(headers).length, 3, 'Did not add user agent', callback);
|
|
35
|
+
const userAgent = headers['user-agent'];
|
|
36
|
+
testing.assert(userAgent.includes('bot'), 'Invalid user agent', callback);
|
|
37
|
+
addUserAgent(headers);
|
|
38
|
+
testing.assertEquals(Object.keys(headers).length, 3, 'Should not add user agent', callback);
|
|
39
|
+
testing.success(callback);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Run all tests.
|
|
44
|
+
*/
|
|
45
|
+
export function test(callback) {
|
|
46
|
+
testing.run([
|
|
47
|
+
testAddHeaders,
|
|
48
|
+
testAddUserAgent,
|
|
49
|
+
], callback);
|
|
50
|
+
}
|
|
51
|
+
|
package/test/hrtimer.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Measure latency for a load test.
|
|
3
|
+
* (C) 2013 Alex Fernández.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import testing from 'testing';
|
|
8
|
+
import {HighResolutionTimer} from '../lib/hrtimer.js'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Test a high resolution timer.
|
|
13
|
+
*/
|
|
14
|
+
function testTimerStop(callback) {
|
|
15
|
+
const timer = new HighResolutionTimer(10, callback);
|
|
16
|
+
setImmediate(() => timer.stop())
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function testTimerRun(callback) {
|
|
20
|
+
let run = 0
|
|
21
|
+
const timer = new HighResolutionTimer(100, () => run++)
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
testing.equals(run, 3, callback)
|
|
24
|
+
timer.stop()
|
|
25
|
+
testing.success(callback)
|
|
26
|
+
}, 250)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Run package tests.
|
|
31
|
+
*/
|
|
32
|
+
export function test(callback) {
|
|
33
|
+
const tests = [
|
|
34
|
+
testTimerStop,
|
|
35
|
+
testTimerRun,
|
|
36
|
+
];
|
|
37
|
+
testing.run(tests, callback);
|
|
38
|
+
}
|
|
39
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import testing from 'testing'
|
|
2
|
+
import {create} from '../lib/httpClient.js'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function testHttpClient(callback) {
|
|
6
|
+
const options = {
|
|
7
|
+
url: 'http://localhost:7357/',
|
|
8
|
+
maxSeconds: 0.1,
|
|
9
|
+
concurrency: 1,
|
|
10
|
+
};
|
|
11
|
+
create({}, options);
|
|
12
|
+
testing.success(callback);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Run all tests.
|
|
18
|
+
*/
|
|
19
|
+
export function test(callback) {
|
|
20
|
+
testing.run([testHttpClient], callback)
|
|
21
|
+
}
|
|
22
|
+
|
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import * as testing from 'testing'
|
|
2
|
+
import {execFile} from 'child_process'
|
|
3
|
+
import {join} from 'path'
|
|
4
|
+
import {loadTest, startServer} from '../index.js'
|
|
2
5
|
|
|
3
|
-
/**
|
|
4
|
-
* API usage examples
|
|
5
|
-
* (C) 2013 Alex Fernández.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// requires
|
|
10
|
-
const loadtest = require('./loadtest.js');
|
|
11
|
-
const testserver = require('./testserver.js');
|
|
12
|
-
const testing = require('testing');
|
|
13
|
-
const Log = require('log');
|
|
14
|
-
const { execFile } = require('child_process');
|
|
15
|
-
const { join } = require('path');
|
|
16
|
-
|
|
17
|
-
// globals
|
|
18
|
-
const log = new Log('info');
|
|
19
|
-
|
|
20
|
-
// constants
|
|
21
6
|
const PORT = 10408;
|
|
22
7
|
|
|
23
8
|
|
|
@@ -25,7 +10,7 @@ const PORT = 10408;
|
|
|
25
10
|
* Run an integration test.
|
|
26
11
|
*/
|
|
27
12
|
function testIntegration(callback) {
|
|
28
|
-
const server =
|
|
13
|
+
const server = startServer({ port: PORT }, error => {
|
|
29
14
|
if (error) {
|
|
30
15
|
return callback(error);
|
|
31
16
|
}
|
|
@@ -38,7 +23,7 @@ function testIntegration(callback) {
|
|
|
38
23
|
hi: 'there',
|
|
39
24
|
},
|
|
40
25
|
};
|
|
41
|
-
|
|
26
|
+
loadTest(options, (error, result) => {
|
|
42
27
|
if (error) {
|
|
43
28
|
return callback(error);
|
|
44
29
|
}
|
|
@@ -57,13 +42,12 @@ function testIntegration(callback) {
|
|
|
57
42
|
* Run an integration test using configuration file.
|
|
58
43
|
*/
|
|
59
44
|
function testIntegrationFile(callback) {
|
|
60
|
-
const server =
|
|
45
|
+
const server = startServer({ port: PORT }, error => {
|
|
61
46
|
if (error) {
|
|
62
47
|
return callback(error);
|
|
63
48
|
}
|
|
64
49
|
execFile('node',
|
|
65
|
-
[join(
|
|
66
|
-
{ cwd: join(__dirname, '..', 'test') },
|
|
50
|
+
[join('./', 'bin', 'loadtest.js'), `http://localhost:${PORT}/`, '-n', '100'],
|
|
67
51
|
(error, stdout) => {
|
|
68
52
|
if (error) {
|
|
69
53
|
return callback(error);
|
|
@@ -84,7 +68,7 @@ function testIntegrationFile(callback) {
|
|
|
84
68
|
* Run an integration test.
|
|
85
69
|
*/
|
|
86
70
|
function testWSIntegration(callback) {
|
|
87
|
-
const server =
|
|
71
|
+
const server = startServer({ port: PORT }, error => {
|
|
88
72
|
if (error) {
|
|
89
73
|
return callback(error);
|
|
90
74
|
}
|
|
@@ -102,7 +86,7 @@ function testWSIntegration(callback) {
|
|
|
102
86
|
hi: 'there',
|
|
103
87
|
},
|
|
104
88
|
};
|
|
105
|
-
|
|
89
|
+
loadTest(options, (error, result) => {
|
|
106
90
|
if (error) {
|
|
107
91
|
return callback(error);
|
|
108
92
|
}
|
|
@@ -125,7 +109,7 @@ function testDelay(callback) {
|
|
|
125
109
|
port: PORT + 1,
|
|
126
110
|
delay: delay,
|
|
127
111
|
};
|
|
128
|
-
const server =
|
|
112
|
+
const server = startServer(options, error => {
|
|
129
113
|
if (error) {
|
|
130
114
|
return callback(error);
|
|
131
115
|
}
|
|
@@ -133,7 +117,7 @@ function testDelay(callback) {
|
|
|
133
117
|
url: 'http://localhost:' + (PORT + 1),
|
|
134
118
|
maxRequests: 10,
|
|
135
119
|
};
|
|
136
|
-
|
|
120
|
+
loadTest(options, (error, result) => {
|
|
137
121
|
if (error) {
|
|
138
122
|
return callback(error);
|
|
139
123
|
}
|
|
@@ -152,13 +136,7 @@ function testDelay(callback) {
|
|
|
152
136
|
/**
|
|
153
137
|
* Run all tests.
|
|
154
138
|
*/
|
|
155
|
-
|
|
156
|
-
log.debug('Running all tests');
|
|
139
|
+
export function test(callback) {
|
|
157
140
|
testing.run([testIntegration, testIntegrationFile, testDelay, testWSIntegration], 4000, callback);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
// start load test if invoked directly
|
|
161
|
-
if (__filename == process.argv[1]) {
|
|
162
|
-
exports.test(testing.show);
|
|
163
141
|
}
|
|
164
142
|
|
package/test/latency.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import testing from 'testing'
|
|
2
|
+
import {Latency} from '../lib/latency.js'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Test latency ids.
|
|
7
|
+
*/
|
|
8
|
+
function testLatencyIds(callback) {
|
|
9
|
+
const latency = new Latency({});
|
|
10
|
+
const firstId = latency.start();
|
|
11
|
+
testing.assert(firstId, 'Invalid first latency id %s', firstId, callback);
|
|
12
|
+
const secondId = latency.start();
|
|
13
|
+
testing.assert(secondId, 'Invalid second latency id', callback);
|
|
14
|
+
testing.assert(firstId != secondId, 'Repeated latency ids', callback);
|
|
15
|
+
testing.success(callback);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Test latency measurements.
|
|
20
|
+
*/
|
|
21
|
+
function testLatencyRequests(callback) {
|
|
22
|
+
const options = {
|
|
23
|
+
maxRequests: 10,
|
|
24
|
+
};
|
|
25
|
+
const errorCode = '500';
|
|
26
|
+
const latency = new Latency(options, (error, result) => {
|
|
27
|
+
testing.check(error, 'Could not compute latency', callback);
|
|
28
|
+
testing.assertEquals(result.totalRequests, 10, 'Invalid total requests', callback);
|
|
29
|
+
testing.assertEquals(result.totalErrors, 1, 'Invalid total errors', callback);
|
|
30
|
+
testing.assert(errorCode in result.errorCodes, 'Error code not found', callback);
|
|
31
|
+
testing.assertEquals(result.errorCodes[errorCode], 1, 'Should have one ' + errorCode, callback);
|
|
32
|
+
testing.success(callback);
|
|
33
|
+
});
|
|
34
|
+
let id;
|
|
35
|
+
for (let i = 0; i < 9; i++) {
|
|
36
|
+
id = latency.start();
|
|
37
|
+
latency.end(id);
|
|
38
|
+
}
|
|
39
|
+
id = latency.start();
|
|
40
|
+
latency.end(id, errorCode);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check that percentiles are correct.
|
|
45
|
+
*/
|
|
46
|
+
function testLatencyPercentiles(callback) {
|
|
47
|
+
const options = {
|
|
48
|
+
maxRequests: 10
|
|
49
|
+
};
|
|
50
|
+
const latency = new Latency(options, error => {
|
|
51
|
+
testing.check(error, 'Error while testing latency percentiles', callback);
|
|
52
|
+
const percentiles = latency.getResults().percentiles;
|
|
53
|
+
|
|
54
|
+
Object.keys(percentiles).forEach(percentile => {
|
|
55
|
+
testing.assert(percentiles[percentile] !== false, 'Empty percentile for %s', percentile, callback);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
testing.success(percentiles, callback);
|
|
59
|
+
});
|
|
60
|
+
for (let ms = 1; ms <= 10; ms++) {
|
|
61
|
+
(function() {
|
|
62
|
+
const id = latency.start();
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
latency.end(id);
|
|
65
|
+
}, ms);
|
|
66
|
+
})();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Run package tests.
|
|
72
|
+
*/
|
|
73
|
+
export function test(callback) {
|
|
74
|
+
const tests = [
|
|
75
|
+
testLatencyIds,
|
|
76
|
+
testLatencyRequests,
|
|
77
|
+
testLatencyPercentiles,
|
|
78
|
+
];
|
|
79
|
+
testing.run(tests, callback);
|
|
80
|
+
}
|
|
81
|
+
|
package/test/loadtest.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import testing from 'testing'
|
|
2
|
+
import {loadTest} from '../lib/loadtest.js'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A load test with max seconds.
|
|
7
|
+
*/
|
|
8
|
+
function testMaxSeconds(callback) {
|
|
9
|
+
const options = {
|
|
10
|
+
url: 'http://localhost:7357/',
|
|
11
|
+
maxSeconds: 0.1,
|
|
12
|
+
concurrency: 1,
|
|
13
|
+
};
|
|
14
|
+
loadTest(options, callback);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A load test with max seconds.
|
|
20
|
+
*/
|
|
21
|
+
function testWSEcho(callback) {
|
|
22
|
+
const options = {
|
|
23
|
+
url: 'ws://localhost:7357/',
|
|
24
|
+
maxSeconds: 0.1,
|
|
25
|
+
concurrency: 1,
|
|
26
|
+
};
|
|
27
|
+
loadTest(options, callback);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function testIndexParam(callback) {
|
|
31
|
+
const options = {
|
|
32
|
+
url: 'http://localhost:7357/replace',
|
|
33
|
+
concurrency:1,
|
|
34
|
+
maxSeconds: 0.1,
|
|
35
|
+
indexParam: "replace"
|
|
36
|
+
};
|
|
37
|
+
loadTest(options, callback);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function testIndexParamWithBody(callback) {
|
|
41
|
+
const options = {
|
|
42
|
+
url: 'http://localhost:7357/replace',
|
|
43
|
+
concurrency:1,
|
|
44
|
+
maxSeconds: 0.1,
|
|
45
|
+
indexParam: "replace",
|
|
46
|
+
body: '{"id": "replace"}'
|
|
47
|
+
};
|
|
48
|
+
loadTest(options, callback);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function testIndexParamWithCallback(callback) {
|
|
52
|
+
const options = {
|
|
53
|
+
url: 'http://localhost:7357/replace',
|
|
54
|
+
concurrency:1,
|
|
55
|
+
maxSeconds: 0.1,
|
|
56
|
+
indexParam: "replace",
|
|
57
|
+
indexParamCallback: function() {
|
|
58
|
+
//https://gist.github.com/6174/6062387
|
|
59
|
+
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
loadTest(options, callback);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function testIndexParamWithCallbackAndBody(callback) {
|
|
66
|
+
const options = {
|
|
67
|
+
url: 'http://localhost:7357/replace',
|
|
68
|
+
concurrency:1,
|
|
69
|
+
maxSeconds: 0.1,
|
|
70
|
+
body: '{"id": "replace"}',
|
|
71
|
+
indexParam: "replace",
|
|
72
|
+
indexParamCallback: function() {
|
|
73
|
+
//https://gist.github.com/6174/6062387
|
|
74
|
+
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
loadTest(options, callback);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Run all tests.
|
|
83
|
+
*/
|
|
84
|
+
export function test(callback) {
|
|
85
|
+
testing.run([testMaxSeconds, testWSEcho, testIndexParam, testIndexParamWithBody, testIndexParamWithCallback, testIndexParamWithCallbackAndBody], callback);
|
|
86
|
+
}
|
|
87
|
+
|
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import testing from 'testing'
|
|
2
|
+
import {loadTest} from '../lib/loadtest.js'
|
|
3
|
+
import {startServer} from '../lib/testserver.js'
|
|
2
4
|
|
|
3
|
-
const loadtest = require('./loadtest.js');
|
|
4
|
-
const testserver = require('./testserver.js');
|
|
5
|
-
const testing = require('testing');
|
|
6
|
-
const Log = require('log');
|
|
7
|
-
|
|
8
|
-
// globals
|
|
9
|
-
const log = new Log('info');
|
|
10
|
-
|
|
11
|
-
// constants
|
|
12
5
|
const PORT = 10453;
|
|
13
6
|
|
|
14
7
|
|
|
15
8
|
function testRequestGenerator(callback) {
|
|
16
|
-
const server =
|
|
9
|
+
const server = startServer({port: PORT}, error => {
|
|
17
10
|
if (error) {
|
|
18
11
|
return callback('Could not start test server');
|
|
19
12
|
}
|
|
20
13
|
const options = {
|
|
21
14
|
url: 'http://localhost:' + PORT,
|
|
22
15
|
method: 'POST',
|
|
23
|
-
requestsPerSecond:
|
|
16
|
+
requestsPerSecond: 100,
|
|
24
17
|
maxRequests: 100,
|
|
25
18
|
concurrency: 10,
|
|
26
19
|
requestGenerator: (params, options, client, callback) => {
|
|
@@ -32,9 +25,10 @@ function testRequestGenerator(callback) {
|
|
|
32
25
|
return request;
|
|
33
26
|
},
|
|
34
27
|
};
|
|
35
|
-
|
|
28
|
+
loadTest(options, (error, result) => {
|
|
36
29
|
if (error) {
|
|
37
|
-
|
|
30
|
+
console.error(error)
|
|
31
|
+
return callback(`Could not run load test with requestGenerator: ${error.message}`);
|
|
38
32
|
}
|
|
39
33
|
server.close(error => {
|
|
40
34
|
if (error) {
|
|
@@ -49,13 +43,7 @@ function testRequestGenerator(callback) {
|
|
|
49
43
|
/**
|
|
50
44
|
* Run all tests.
|
|
51
45
|
*/
|
|
52
|
-
|
|
53
|
-
log.debug('Running all tests');
|
|
46
|
+
export function test(callback) {
|
|
54
47
|
testing.run([testRequestGenerator], 4000, callback);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// start load test if invoked directly
|
|
58
|
-
if (__filename == process.argv[1]) {
|
|
59
|
-
exports.test(testing.show);
|
|
60
48
|
}
|
|
61
49
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import testing from 'testing'
|
|
2
|
+
import {startServer} from '../lib/testserver.js'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function testStartServer(callback) {
|
|
6
|
+
const options = {
|
|
7
|
+
port: 10530,
|
|
8
|
+
};
|
|
9
|
+
const server = startServer(options, error => {
|
|
10
|
+
testing.check(error, 'Could not start server', callback);
|
|
11
|
+
server.close(error => {
|
|
12
|
+
testing.check(error, 'Could not stop server', callback);
|
|
13
|
+
testing.success(callback);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Run the tests.
|
|
20
|
+
*/
|
|
21
|
+
export function test(callback) {
|
|
22
|
+
testing.run([testStartServer], 5000, callback);
|
|
23
|
+
}
|
|
24
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import testing from 'testing'
|
|
2
|
+
import {create} from '../lib/websocket.js'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function testWebsocketClient(callback) {
|
|
6
|
+
const options = {
|
|
7
|
+
url: 'ws://localhost:7357/',
|
|
8
|
+
maxSeconds: 0.1,
|
|
9
|
+
concurrency: 1,
|
|
10
|
+
};
|
|
11
|
+
create({}, options);
|
|
12
|
+
testing.success(callback);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Run tests, currently nothing.
|
|
17
|
+
*/
|
|
18
|
+
export function test(callback) {
|
|
19
|
+
testing.run([
|
|
20
|
+
testWebsocketClient,
|
|
21
|
+
], callback);
|
|
22
|
+
}
|
|
23
|
+
|
package/test.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Run package tests.
|
|
5
|
-
* (C) 2013 Alex Fernández.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// requires
|
|
9
|
-
const testing = require('testing');
|
|
10
|
-
const Log = require('log');
|
|
11
|
-
|
|
12
|
-
// globals
|
|
13
|
-
const log = new Log('info');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Run all module tests.
|
|
18
|
-
*/
|
|
19
|
-
exports.test = function(callback)
|
|
20
|
-
{
|
|
21
|
-
log.debug('Running tests');
|
|
22
|
-
const tests = {};
|
|
23
|
-
const libs = ['hrtimer', 'latency', 'integration', 'loadtest', 'headers', 'testserver', 'websocket', 'httpClient'];
|
|
24
|
-
libs.forEach(function(lib)
|
|
25
|
-
{
|
|
26
|
-
tests[lib] = require('./lib/' + lib + '.js').test;
|
|
27
|
-
});
|
|
28
|
-
testing.run(tests, 4200, callback);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// run tests if invoked directly
|
|
32
|
-
if (__filename == process.argv[1])
|
|
33
|
-
{
|
|
34
|
-
exports.test();
|
|
35
|
-
}
|
|
36
|
-
|
|
File without changes
|