loadtest 8.0.9 → 8.1.1

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/httpClient.js CHANGED
@@ -3,7 +3,7 @@ import * as http from 'http'
3
3
  import * as https from 'https'
4
4
  import * as querystring from 'querystring'
5
5
  import * as websocket from 'websocket'
6
- import {addUserAgent} from './headers.js'
6
+ import { addUserAgent } from './headers.js'
7
7
  import * as agentkeepalive from 'agentkeepalive'
8
8
  import * as HttpsProxyAgent from 'https-proxy-agent'
9
9
 
@@ -68,7 +68,7 @@ export class HttpClient {
68
68
  }
69
69
  if (this.options.cookies) {
70
70
  if (Array.isArray(this.options.cookies)) {
71
- this.params.headers.Cookie = this.options.cookies.join('; ');
71
+ this.params.headers.Cookie = this.options.cookies.join('; ');
72
72
  } else if (typeof this.options.cookies == 'string') {
73
73
  this.params.headers.Cookie = this.options.cookies;
74
74
  } else {
@@ -119,7 +119,7 @@ export class HttpClient {
119
119
  return
120
120
  }
121
121
  const id = this.latency.begin();
122
- const params = {...this.params, headers: {...this.params.headers}}
122
+ const params = { ...this.params, headers: { ...this.params.headers } }
123
123
  this.customizeIndex(params)
124
124
  const request = this.getRequest(id, params)
125
125
  if (this.options.timeout) {
@@ -183,7 +183,7 @@ export class HttpClient {
183
183
  if (this.params.protocol == 'https:') {
184
184
  return https;
185
185
  }
186
- if (this.params.protocol == 'ws:') {
186
+ if (this.params.protocol == 'ws:' || this.params.protocol == 'wss:') {
187
187
  return websocket;
188
188
  }
189
189
  return http;
package/lib/options.js CHANGED
@@ -56,10 +56,10 @@ class Options {
56
56
  if (!options.url) {
57
57
  throw new Error('Missing URL in options')
58
58
  }
59
- if (!options.url.startsWith('http://') && !options.url.startsWith('https://') && !options.url.startsWith('ws://')) {
60
- throw new Error(`Invalid URL ${options.url}, must be http://, https:// or ws://'`)
59
+ if (!options.url.startsWith('http://') && !options.url.startsWith('https://') && !options.url.startsWith('ws://') && !options.url.startsWith('wss://')) {
60
+ throw new Error(`Invalid URL ${options.url}, must be http://, https://, ws://, or wss://'`)
61
61
  }
62
- if (options.url.startsWith('ws:')) {
62
+ if (options.url.startsWith('ws:') || options.url.startsWith('wss:')) {
63
63
  if (options.requestsPerSecond) {
64
64
  throw new Error(`"requestsPerSecond" not supported for WebSockets`);
65
65
  }
package/lib/pool.js CHANGED
@@ -46,8 +46,7 @@ export class Pool {
46
46
  }
47
47
 
48
48
  createClient() {
49
- // TODO: || this.options.url.startsWith('wss:'))
50
- if (this.options.url.startsWith('ws:')) {
49
+ if (this.options.url.startsWith('ws:') || this.options.url.startsWith('wss:')) {
51
50
  return new WebsocketClient(this.loadTest)
52
51
  }
53
52
  if (this.options.tcp) {
@@ -72,8 +71,11 @@ export class Pool {
72
71
  */
73
72
  finishRequest(client, result, error) {
74
73
  if (this.options.statusCallback) {
75
- result.requestIndex = this.requestIndex++
76
- result.instanceIndex = this.loadTest.instanceIndex
74
+ // result can be undefined if an error is thrown for a request
75
+ if (result) {
76
+ result.requestIndex = this.requestIndex++
77
+ result.instanceIndex = this.loadTest.instanceIndex
78
+ }
77
79
  this.options.statusCallback(error, result);
78
80
  }
79
81
  if (this.loadTest.checkStop()) {
package/lib/websocket.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import websocket from 'websocket'
2
- import {BaseClient} from './baseClient.js'
2
+ import { BaseClient } from './baseClient.js'
3
3
 
4
4
  let latency;
5
5
 
@@ -21,10 +21,13 @@ export class WebsocketClient extends BaseClient {
21
21
  * Start the websocket client.
22
22
  */
23
23
  start() {
24
- this.client = new websocket.client();
25
- this.client.on('connectFailed', () => {});
24
+ this.client = new websocket.client({ rejectUnauthorized: false });
25
+ this.client.on('connectFailed', (e) => console.error(`Websocket connection error: ${e.message}`));
26
26
  this.client.on('connect', connection => this.connect(connection));
27
- this.client.connect(this.options.url, []);
27
+ if (this.options.insecure)
28
+ this.client.connect(this.options.url, undefined, undefined, undefined, { "rejectUnauthorized": false });
29
+ else
30
+ this.client.connect(this.options.url);
28
31
  }
29
32
 
30
33
  /**
@@ -84,7 +87,7 @@ export class WebsocketClient extends BaseClient {
84
87
  try {
85
88
  json = JSON.parse(message.utf8Data);
86
89
  }
87
- catch(e) {
90
+ catch (e) {
88
91
  console.error('Invalid JSON: ' + message.utf8Data);
89
92
  return;
90
93
  }
@@ -104,7 +107,7 @@ export class WebsocketClient extends BaseClient {
104
107
  requestFinished(null, json);
105
108
  });
106
109
 
107
- let message={some:"message"};
110
+ let message = { some: "message" };
108
111
 
109
112
  if (this.generateMessage) {
110
113
  message = this.generateMessage(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loadtest",
3
- "version": "8.0.9",
3
+ "version": "8.1.1",
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",