@artilleryio/int-core 2.2.0-fef0907 → 2.2.1-12670e3

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.
@@ -713,7 +713,17 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
713
713
  .catch((gotErr) => {
714
714
  // TODO: Handle the error properly with run hooks
715
715
  debug(gotErr);
716
- return callback(gotErr, context);
716
+ runOnErrorHooks(
717
+ onErrorHandlers,
718
+ config.processor,
719
+ gotErr,
720
+ requestParams,
721
+ context,
722
+ ee,
723
+ function (asyncErr) {
724
+ return callback(gotErr, context);
725
+ }
726
+ );
717
727
  });
718
728
  }
719
729
  ); // eachSeries
@@ -61,19 +61,41 @@ function isAcknowledgeRequired(spec) {
61
61
  return spec.emit && spec.acknowledge;
62
62
  }
63
63
 
64
- function processResponse(ee, data, response, context, callback) {
65
- function isValid(data, response) {
66
- if (!Array.isArray(response.data)) {
67
- //`json` key is added at some point to the response.data object, to use with `captureOrMatch` function
68
- //we should omit it when comparing the response to the data
69
- const responseDataWithoutJson = _.isObject(response.data)
70
- ? _.omit(response.data, 'json')
71
- : response.data;
72
- return deepEqual(data[0], responseDataWithoutJson);
64
+ function isValid(data, response) {
65
+ if (_.isArray(response.data)) {
66
+ //we check if it's an array first (as arrays are objects), and if it's an array, do a deep equality check between both arrays
67
+ return deepEqual(data, response.data);
68
+ }
69
+
70
+ if (_.isObject(response.data)) {
71
+ //`json` key is added at some point to the response.data object, to use with `captureOrMatch` function
72
+ //we should omit it when comparing the response to the data
73
+ const expectedResponse = _.omit(response.data, 'json');
74
+ const actualResponse = data[data.length - 1]; // if response.data is not an array, we compare it to the last element of the actual response
75
+
76
+ return deepEqual(actualResponse, expectedResponse);
77
+ }
78
+
79
+ if (_.isString(response.data)) {
80
+ const expectedResponse = response.data;
81
+ let actualResponse = data[data.length - 1]; // if response.data is not an array, we compare it to the last element of the actual response
82
+
83
+ // unless the user wants to test against the entire response
84
+ if (response.concat) {
85
+ actualResponse = data.join('');
73
86
  }
74
87
 
75
- return deepEqual(data, response.data);
88
+ debug(
89
+ `checking if string ${expectedResponse} is a partial match for string ${actualResponse}`
90
+ );
91
+ return actualResponse.includes(expectedResponse); //we accept a partial match if it's a string
76
92
  }
93
+
94
+ debug(`unexpected data type for response.data: ${typeof response.data}`);
95
+ return false;
96
+ }
97
+
98
+ function processResponse(ee, data, response, context, callback) {
77
99
  // Do we have supplied data to validate?
78
100
  if (response.data && !isValid(data, response)) {
79
101
  debug('data is not valid:');
@@ -237,7 +259,7 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
237
259
  socketio.emit(...outgoing);
238
260
  }
239
261
  markEndTime(ee, context, startedAt);
240
- return callback(null, context);
262
+ return callback(err, context);
241
263
  }
242
264
  }; // endCallback
243
265
 
@@ -247,6 +269,7 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
247
269
  requestSpec.response.channel || requestSpec.response.on,
248
270
  context
249
271
  ),
272
+ concat: template(requestSpec.response.concat, context),
250
273
  data: template(
251
274
  requestSpec.response.data || requestSpec.response.args,
252
275
  context
@@ -257,18 +280,23 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
257
280
 
258
281
  // Listen for the socket.io response on the specified channel
259
282
  let done = false;
283
+ let responseData = [];
260
284
 
261
285
  socketio.on(response.channel, function receive(...args) {
262
- done = true;
263
- processResponse(ee, args, response, context, function (err) {
264
- if (!err) {
265
- markEndTime(ee, context, startedAt);
266
- }
267
- // Stop listening on the response channel
268
- socketio.off(response.channel);
286
+ responseData.push(...args);
287
+ if (isValid(responseData, response)) {
288
+ done = true;
269
289
 
270
- return endCallback(err, context, false);
271
- });
290
+ processResponse(ee, responseData, response, context, function (err) {
291
+ if (!err) {
292
+ markEndTime(ee, context, startedAt);
293
+ }
294
+ // Stop listening on the response channel
295
+ socketio.off(response.channel);
296
+
297
+ return endCallback(err, context, false);
298
+ });
299
+ }
272
300
  });
273
301
 
274
302
  // Send the data on the specified socket.io channel
@@ -278,6 +306,27 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
278
306
 
279
307
  setTimeout(function responseTimeout() {
280
308
  if (!done) {
309
+ if (responseData.length) {
310
+ processResponse(
311
+ ee,
312
+ responseData,
313
+ response,
314
+ context,
315
+ function (err) {
316
+ if (!err) {
317
+ markEndTime(ee, context, startedAt);
318
+ }
319
+ // Stop listening on the response channel
320
+ socketio.off(response.channel);
321
+
322
+ // called
323
+ return endCallback(err, context, false);
324
+ }
325
+ );
326
+
327
+ return;
328
+ }
329
+
281
330
  const err = 'response timeout';
282
331
  ee.emit('error', err);
283
332
  return callback(err, context);
@@ -339,6 +388,10 @@ SocketIoEngine.prototype.loadContextSocket = function (namespace, context, cb) {
339
388
  socket.once('connect_error', function (err) {
340
389
  cb(err, null);
341
390
  });
391
+
392
+ socket.once('error', function (err) {
393
+ cb(err, socket);
394
+ });
342
395
  } else {
343
396
  return cb(null, context.sockets[namespace]);
344
397
  }
package/lib/runner.js CHANGED
@@ -327,8 +327,13 @@ function runScenario(script, metrics, runState, contextVars, options) {
327
327
  if (options.scenarioName) {
328
328
  let foundIndex;
329
329
  const foundScenario = script.scenarios.filter((scenario, index) => {
330
- foundIndex = index;
331
- return new RegExp(options.scenarioName).test(scenario.name);
330
+ const hasScenario = new RegExp(options.scenarioName).test(scenario.name);
331
+
332
+ if (hasScenario) {
333
+ foundIndex = index;
334
+ }
335
+
336
+ return hasScenario;
332
337
  });
333
338
 
334
339
  if (foundScenario?.length === 0) {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@artilleryio/int-core",
3
- "version": "2.2.0-fef0907",
3
+ "version": "2.2.1-12670e3",
4
4
  "main": "./index.js",
5
5
  "license": "MPL-2.0",
6
6
  "dependencies": {
7
- "@artilleryio/int-commons": "2.0.2-fef0907",
7
+ "@artilleryio/int-commons": "2.0.4-12670e3",
8
8
  "@artilleryio/sketches-js": "^2.1.1",
9
9
  "agentkeepalive": "^4.1.0",
10
10
  "arrivals": "^2.1.2",