@artilleryio/int-core 2.0.10 → 2.0.11-006b8d0

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.
@@ -85,6 +85,10 @@ function HttpEngine(script) {
85
85
  this.config.http = {};
86
86
  }
87
87
 
88
+ if (typeof this.config.http.defaults === 'undefined') {
89
+ this.config.http.defaults = {};
90
+ }
91
+
88
92
  if (typeof this.config.http.cookieJarOptions === 'undefined') {
89
93
  this.config.http.cookieJarOptions = {};
90
94
  }
@@ -197,7 +201,10 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
197
201
  }
198
202
 
199
203
  if (typeof requestSpec.think !== 'undefined') {
200
- return engineUtil.createThink(requestSpec, self.config.defaults.think);
204
+ return engineUtil.createThink(
205
+ requestSpec,
206
+ self.config.http.defaults.think || self.config.defaults.think
207
+ );
201
208
  }
202
209
 
203
210
  if (typeof requestSpec.log !== 'undefined') {
@@ -350,8 +357,11 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
350
357
 
351
358
  // Request.js -> Got.js translation
352
359
  if (params.qs) {
353
- requestParams.searchParams = template(params.qs, context);
360
+ requestParams.searchParams = qs.stringify(
361
+ template(params.qs, context)
362
+ );
354
363
  }
364
+
355
365
  if (typeof params.gzip === 'boolean') {
356
366
  requestParams.decompress = params.gzip;
357
367
  } else {
@@ -384,7 +394,8 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
384
394
 
385
395
  // Assign default headers then overwrite as needed
386
396
  let defaultHeaders = lowcaseKeys(
387
- config.defaults.headers || { 'user-agent': USER_AGENT }
397
+ config.http.defaults.headers ||
398
+ config.defaults.headers || { 'user-agent': USER_AGENT }
388
399
  );
389
400
  const combinedHeaders = _.extend(
390
401
  defaultHeaders,
@@ -808,7 +819,9 @@ function lastRequest(res, requestParams) {
808
819
  HttpEngine.prototype.setInitialContext = function (initialContext) {
809
820
  initialContext._successCount = 0;
810
821
 
811
- initialContext._defaultStrictCapture = this.config.defaults.strictCapture;
822
+ initialContext._defaultStrictCapture =
823
+ this.config.http.defaults.strictCapture ||
824
+ this.config.defaults.strictCapture;
812
825
  initialContext._jar = new tough.CookieJar(
813
826
  null,
814
827
  this.config.http.cookieJarOptions
@@ -816,8 +829,12 @@ HttpEngine.prototype.setInitialContext = function (initialContext) {
816
829
 
817
830
  initialContext._enableCookieJar = false;
818
831
  // If a default cookie is set, we will use the jar straightaway:
819
- if (typeof this.config.defaults.cookie === 'object') {
820
- initialContext._defaultCookie = this.config.defaults.cookie;
832
+ if (
833
+ typeof this.config.http.defaults.cookie === 'object' ||
834
+ typeof this.config.defaults.cookie === 'object'
835
+ ) {
836
+ initialContext._defaultCookie =
837
+ this.config.http.defaults.cookie || this.config.defaults.cookie;
821
838
  initialContext._enableCookieJar = true;
822
839
  }
823
840
 
package/lib/phases.js CHANGED
@@ -10,8 +10,9 @@ const _ = require('lodash');
10
10
  const isUndefined = _.isUndefined;
11
11
  const arrivals = require('arrivals');
12
12
  const debug = require('debug')('phases');
13
- const crypto = require('crypto');
13
+ const { randomUUID } = require('crypto');
14
14
  const driftless = require('driftless');
15
+ const ms = require('ms');
15
16
 
16
17
  module.exports = phaser;
17
18
 
@@ -25,7 +26,6 @@ function phaser(phaseSpecs) {
25
26
  let ee = new EventEmitter();
26
27
 
27
28
  let tasks = _.map(phaseSpecs, function (spec, i) {
28
- // Cast defined but non-number (eg: from ENV) values
29
29
  [
30
30
  'arrivalRate',
31
31
  'arrivalCount',
@@ -34,9 +34,27 @@ function phaser(phaseSpecs) {
34
34
  'duration',
35
35
  'maxVusers'
36
36
  ].forEach(function (k) {
37
- if (!isUndefined(spec[k]) && typeof spec[k] !== 'number') {
38
- spec[k] = _.toNumber(spec[k]);
37
+ if (isUndefined(spec[k]) || spec[k] == 'number') {
38
+ return;
39
39
  }
40
+
41
+ if (k == 'duration' || k == 'pause') {
42
+ //if it's already a number in string format, don't apply ms, as it's the default behaviour, so we don't want to do ms calculations
43
+ //otherwise, ms returns the value in milliseconds, so we need to convert to seconds
44
+ const convertedDuration = Number.isInteger(_.toNumber(spec[k]))
45
+ ? spec[k]
46
+ : ms(spec[k]) / 1000;
47
+
48
+ //throw error if invalid time format to prevent test from running infinitely
49
+ if (!convertedDuration) {
50
+ throw new Error(`Invalid ${k} for phase: ${spec[k]}`);
51
+ }
52
+
53
+ spec[k] = convertedDuration;
54
+ }
55
+
56
+ // Cast defined but non-number (eg: from ENV) values
57
+ spec[k] = _.toNumber(spec[k]);
40
58
  });
41
59
 
42
60
  if (isUndefined(spec.index)) {
@@ -89,8 +107,11 @@ function phaser(phaseSpecs) {
89
107
  function createPause(spec, ee) {
90
108
  const duration = spec.pause * 1000;
91
109
  const task = function (callback) {
110
+ spec.startTime = Date.now();
111
+ spec.id = randomUUID();
92
112
  ee.emit('phaseStarted', spec);
93
113
  setTimeout(function () {
114
+ spec.endTime = Date.now();
94
115
  ee.emit('phaseCompleted', spec);
95
116
  return callback(null);
96
117
  }, duration);
@@ -144,12 +165,14 @@ function createRamp(spec, ee) {
144
165
  debug(`periodTick ${periodTick}`);
145
166
 
146
167
  return async function rampTask(callback) {
168
+ spec.startTime = Date.now();
169
+ spec.id = randomUUID();
147
170
  ee.emit('phaseStarted', spec);
148
171
  for (let period = 0; period < periods; period++) {
149
172
  ticker(period);
150
173
  await sleep(1000);
151
174
  }
152
-
175
+ spec.endTime = Date.now();
153
176
  ee.emit('phaseCompleted', spec);
154
177
  };
155
178
 
@@ -185,6 +208,8 @@ function createRamp(spec, ee) {
185
208
 
186
209
  function createArrivalCount(spec, ee) {
187
210
  const task = function (callback) {
211
+ spec.startTime = Date.now();
212
+ spec.id = randomUUID();
188
213
  ee.emit('phaseStarted', spec);
189
214
  const duration = spec.duration * 1000;
190
215
 
@@ -195,6 +220,7 @@ function createArrivalCount(spec, ee) {
195
220
  ee.emit('arrival', spec);
196
221
  });
197
222
  p.on('finished', function () {
223
+ spec.endTime = Date.now();
198
224
  ee.emit('phaseCompleted', spec);
199
225
  return callback(null);
200
226
  });
@@ -209,6 +235,8 @@ function createArrivalCount(spec, ee) {
209
235
 
210
236
  function createArrivalRate(spec, ee) {
211
237
  const task = function (callback) {
238
+ spec.startTime = Date.now();
239
+ spec.id = randomUUID();
212
240
  ee.emit('phaseStarted', spec);
213
241
  const ar = 1000 / spec.arrivalRate;
214
242
  const duration = spec.duration * 1000;
@@ -218,6 +246,7 @@ function createArrivalRate(spec, ee) {
218
246
  ee.emit('arrival', spec);
219
247
  });
220
248
  p.on('finished', function () {
249
+ spec.endTime = Date.now();
221
250
  ee.emit('phaseCompleted', spec);
222
251
  return callback(null);
223
252
  });
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@artilleryio/int-core",
3
- "version": "2.0.10",
3
+ "version": "2.0.11-006b8d0",
4
4
  "main": "./index.js",
5
5
  "dependencies": {
6
- "@artilleryio/int-commons": "latest",
6
+ "@artilleryio/int-commons": "2.0.1-006b8d0",
7
7
  "@artilleryio/sketches-js": "^2.1.1",
8
8
  "agentkeepalive": "^4.1.0",
9
9
  "arrivals": "^2.1.2",
@@ -25,6 +25,7 @@
25
25
  "hpagent": "^0.1.1",
26
26
  "https-proxy-agent": "^5.0.0",
27
27
  "lodash": "^4.17.19",
28
+ "ms": "^2.1.3",
28
29
  "protobufjs": "^7.2.4",
29
30
  "proxy": "^1.0.2",
30
31
  "socket.io-client": "^4.5.1",
@@ -37,7 +38,9 @@
37
38
  "scripts": {
38
39
  "lint": "eslint --ext \".js,.ts,.tsx\" .",
39
40
  "lint-fix": "npm run lint -- --fix",
40
- "test": "tap --no-coverage --timeout=300 test/core/unit/*.test.js && bash test/core/run.sh"
41
+ "test": "npm run test:unit && npm run test:acceptance",
42
+ "test:unit": "tap --no-coverage --color --timeout=300 test/core/unit/*.test.js",
43
+ "test:acceptance": "bash test/core/run.sh"
41
44
  },
42
45
  "devDependencies": {
43
46
  "@hapi/basic": "^6.0.0",
@@ -47,6 +50,6 @@
47
50
  "rewiremock": "^3.14.3",
48
51
  "sinon": "^4.5.0",
49
52
  "socket.io": "^4.7.1",
50
- "tap": "15.2.3"
53
+ "tap": "^16.3.7"
51
54
  }
52
- }
55
+ }