@artilleryio/int-core 2.1.0-77ea3e9 → 2.1.0-8622de3

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.
@@ -167,7 +167,7 @@ HttpEngine.prototype.createScenario = function (scenarioSpec, ee) {
167
167
  });
168
168
  });
169
169
 
170
- return self.compile(tasks, scenarioSpec.flow, ee);
170
+ return self.compile(tasks, scenarioSpec, ee);
171
171
  };
172
172
 
173
173
  HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
@@ -868,6 +868,7 @@ HttpEngine.prototype.compile = function compile(tasks, scenarioSpec, ee) {
868
868
 
869
869
  return async function scenario(initialContext, callback) {
870
870
  initialContext = self.setInitialContext(initialContext);
871
+
871
872
  ee.emit('started');
872
873
  let context = initialContext;
873
874
  for (const task of tasks) {
package/lib/runner.js CHANGED
@@ -200,7 +200,13 @@ function run(script, ee, options, runState, contextVars) {
200
200
  if (runState.pendingScenarios >= spec.maxVusers) {
201
201
  metrics.counter('vusers.skipped', 1);
202
202
  } else {
203
- scenarioContext = runScenario(script, metrics, runState, contextVars);
203
+ scenarioContext = runScenario(
204
+ script,
205
+ metrics,
206
+ runState,
207
+ contextVars,
208
+ options
209
+ );
204
210
  }
205
211
  });
206
212
  phaser.on('phaseStarted', function (spec) {
@@ -242,7 +248,7 @@ function run(script, ee, options, runState, contextVars) {
242
248
  phaser.run();
243
249
  }
244
250
 
245
- function runScenario(script, metrics, runState, contextVars) {
251
+ function runScenario(script, metrics, runState, contextVars, options) {
246
252
  const start = process.hrtime();
247
253
 
248
254
  //
@@ -263,7 +269,7 @@ function runScenario(script, metrics, runState, contextVars) {
263
269
  const w = engineUtil.template(scenario.weight, {
264
270
  vars: variableValues
265
271
  });
266
- scenario.weight = isNaN(parseInt(w)) ? 0 : parseInt(w);
272
+ scenario.weight = isNaN(parseInt(w)) ? 0 : parseInt(w); //eslint-disable-line radix
267
273
  debug(
268
274
  `scenario ${scenario.name} weight has been set to ${scenario.weight}`
269
275
  );
@@ -315,8 +321,29 @@ function runScenario(script, metrics, runState, contextVars) {
315
321
  );
316
322
  }
317
323
 
324
+ //default to weighted picked scenario
318
325
  let i = runState.picker()[0];
319
326
 
327
+ if (options.scenarioName) {
328
+ let foundIndex;
329
+ const foundScenario = script.scenarios.filter((scenario, index) => {
330
+ foundIndex = index;
331
+ return new RegExp(options.scenarioName).test(scenario.name);
332
+ });
333
+
334
+ if (foundScenario?.length === 0) {
335
+ throw new Error(
336
+ `Scenario ${options.scenarioName} not found in script. Make sure your chosen scenario matches the one in your script exactly.`
337
+ );
338
+ } else if (foundScenario.length > 1) {
339
+ throw new Error(
340
+ `Multiple scenarios for ${options.scenarioName} found in script. Make sure you give unique names to your scenarios in your script.`
341
+ );
342
+ } else {
343
+ debug(`Scenario ${options.scenarioName} found in script. running it!`);
344
+ i = foundIndex;
345
+ }
346
+ }
320
347
  debug(
321
348
  'picking scenario %s (%s) weight = %s',
322
349
  i,
@@ -328,7 +355,9 @@ function runScenario(script, metrics, runState, contextVars) {
328
355
  metrics.counter('vusers.created', 1);
329
356
 
330
357
  const scenarioStartedAt = process.hrtime();
331
- const scenarioContext = createContext(script, contextVars);
358
+ const scenarioContext = createContext(script, contextVars, {
359
+ scenario: script.scenarios[i]
360
+ });
332
361
 
333
362
  const finish = process.hrtime(start);
334
363
  const runScenarioDelta = finish[0] * 1e9 + finish[1];
@@ -391,7 +420,13 @@ function inlineVariables(script) {
391
420
  /**
392
421
  * Create initial context for a scenario.
393
422
  */
394
- function createContext(script, contextVars) {
423
+ function createContext(script, contextVars, additionalProperties = {}) {
424
+ //allow for additional properties to be passed in, but not override vars and funcs
425
+ const additionalPropertiesWithoutOverride = _.omit(additionalProperties, [
426
+ 'vars',
427
+ 'funcs'
428
+ ]);
429
+
395
430
  const INITIAL_CONTEXT = {
396
431
  vars: Object.assign(
397
432
  {
@@ -406,7 +441,8 @@ function createContext(script, contextVars) {
406
441
  $randomNumber: $randomNumber,
407
442
  $randomString: $randomString,
408
443
  $template: (input) => engineUtil.template(input, { vars: result.vars })
409
- }
444
+ },
445
+ ...additionalPropertiesWithoutOverride
410
446
  };
411
447
 
412
448
  let result = INITIAL_CONTEXT;
@@ -453,7 +489,10 @@ function handleScriptHook(hook, script, hookEvents, contextVars = {}) {
453
489
  const name = script[hook].engine || 'http';
454
490
  const engine = engines.find((e) => e.__name === name);
455
491
  const hookScenario = engine.createScenario(script[hook], ee);
456
- const hookContext = createContext(script, contextVars);
492
+ const hookContext = createContext(script, contextVars, {
493
+ scenario: script[hook]
494
+ });
495
+
457
496
  hookScenario(hookContext, function (err, context) {
458
497
  if (err) {
459
498
  debug(err);
package/lib/ssms.js CHANGED
@@ -626,6 +626,7 @@ function summarizeHistogram(h) {
626
626
  min: round(h.min, 1),
627
627
  max: round(h.max, 1),
628
628
  count: h.count,
629
+ mean: round(h.sum/h.count, 1),
629
630
  p50: round(h.getValueAtQuantile(0.5), 1),
630
631
  median: round(h.getValueAtQuantile(0.5), 1), // Here for compatibility
631
632
  p75: round(h.getValueAtQuantile(0.75), 1),
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@artilleryio/int-core",
3
- "version": "2.1.0-77ea3e9",
3
+ "version": "2.1.0-8622de3",
4
4
  "main": "./index.js",
5
5
  "license": "MPL-2.0",
6
6
  "dependencies": {
7
- "@artilleryio/int-commons": "2.0.1-77ea3e9",
7
+ "@artilleryio/int-commons": "2.0.1-8622de3",
8
8
  "@artilleryio/sketches-js": "^2.1.1",
9
9
  "agentkeepalive": "^4.1.0",
10
10
  "arrivals": "^2.1.2",