loadtest 6.4.0 → 7.1.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/lib/websocket.js CHANGED
@@ -7,16 +7,16 @@ let latency;
7
7
  /**
8
8
  * Create a client for a websocket.
9
9
  */
10
- export function create(operation, params) {
11
- return new WebsocketClient(operation, params);
10
+ export function create(loadTest, options) {
11
+ return new WebsocketClient(loadTest, options);
12
12
  }
13
13
 
14
14
  /**
15
15
  * A client that connects to a websocket.
16
16
  */
17
17
  class WebsocketClient extends BaseClient {
18
- constructor(operation, params) {
19
- super(operation, params);
18
+ constructor(loadTest, options) {
19
+ super(loadTest, options);
20
20
  this.connection = null;
21
21
  this.lastCall = null;
22
22
  this.client = null;
@@ -30,7 +30,7 @@ class WebsocketClient extends BaseClient {
30
30
  this.client = new websocket.client();
31
31
  this.client.on('connectFailed', () => {});
32
32
  this.client.on('connect', connection => this.connect(connection));
33
- this.client.connect(this.params.url, []);
33
+ this.client.connect(this.options.url, []);
34
34
  }
35
35
 
36
36
  /**
@@ -55,7 +55,7 @@ class WebsocketClient extends BaseClient {
55
55
  * Make a single request to the server.
56
56
  */
57
57
  makeRequest() {
58
- const id = this.operation.latency.start();
58
+ const id = this.loadTest.latency.start();
59
59
  const requestFinished = this.getRequestFinisher(id);
60
60
 
61
61
  if (this.connection.connected) {
@@ -115,7 +115,7 @@ class WebsocketClient extends BaseClient {
115
115
  if (this.generateMessage) {
116
116
  message = this.generateMessage(id);
117
117
  }
118
- if (typeof this.params.requestGenerator == 'function') {
118
+ if (typeof this.options.requestGenerator == 'function') {
119
119
  // create a 'fake' object which can function like the http client
120
120
  const req = () => {
121
121
  return {
@@ -124,7 +124,7 @@ class WebsocketClient extends BaseClient {
124
124
  }
125
125
  };
126
126
  };
127
- this.params.requestGenerator(this.params, this.options, req, requestFinished);
127
+ this.options.requestGenerator(this.options, this.params, req, requestFinished);
128
128
  } else {
129
129
  this.connection.sendUTF(JSON.stringify(message));
130
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loadtest",
3
- "version": "6.4.0",
3
+ "version": "7.1.0",
4
4
  "type": "module",
5
5
  "description": "Run load tests for your web application. Mostly ab-compatible interface, with an option to force requests per second. Includes an API for automated load testing.",
6
6
  "homepage": "https://github.com/alexfernandez/loadtest",
@@ -23,7 +23,8 @@
23
23
  "websocket": "^1.0.34"
24
24
  },
25
25
  "devDependencies": {
26
- "eslint": "^8.47.0"
26
+ "eslint": "^8.47.0",
27
+ "microprofiler": "^2.0.0"
27
28
  },
28
29
  "keywords": [
29
30
  "testing",
@@ -187,13 +187,34 @@ async function testIndexParam() {
187
187
  await server.close()
188
188
  }
189
189
 
190
+ async function testStatusCallback() {
191
+ let calls = 0
192
+ const server = await startServer(serverOptions)
193
+ const options = {
194
+ url: `http://localhost:${PORT}/`,
195
+ maxRequests: 100,
196
+ concurrency: 10,
197
+ postBody: {
198
+ hi: 'hey',
199
+ },
200
+ quiet: true,
201
+ statusCallback: (error, result) => {
202
+ testing.assertEquals(result.statusCode, 200, 'Should receive status 200')
203
+ calls += 1
204
+ }
205
+ };
206
+ await loadTest(options)
207
+ testing.assertEquals(calls, 100, 'Should have 100 calls')
208
+ await server.close()
209
+ }
210
+
190
211
  /**
191
212
  * Run all tests.
192
213
  */
193
214
  export function test(callback) {
194
215
  testing.run([
195
216
  testIntegration, testIntegrationFile, testDelay, testWSIntegration,
196
- testPromise, testIndexParam,
217
+ testPromise, testIndexParam, testStatusCallback,
197
218
  ], 4000, callback);
198
219
  }
199
220