@artilleryio/int-core 2.0.0 → 2.0.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.
@@ -8,6 +8,7 @@ const async = require('async');
8
8
  const _ = require('lodash');
9
9
 
10
10
  const io = require('socket.io-client');
11
+ const wildcardPatch = require('socketio-wildcard')(io.Manager);
11
12
 
12
13
  const deepEqual = require('fast-deep-equal');
13
14
  const debug = require('debug')('socketio');
@@ -302,7 +303,9 @@ SocketIoEngine.prototype.loadContextSocket = function (namespace, context, cb) {
302
303
  const socket = io(target, options);
303
304
  context.sockets[namespace] = socket;
304
305
 
305
- socket.onAny(() => {
306
+ wildcardPatch(socket);
307
+
308
+ socket.on('*', function () {
306
309
  context.__receivedMessageCount++;
307
310
  });
308
311
 
package/lib/phases.js CHANGED
@@ -12,6 +12,7 @@ const arrivals = require('arrivals');
12
12
  const debug = require('debug')('phases');
13
13
  const crypto = require('crypto');
14
14
  const driftless = require('driftless');
15
+ const sleep = require('../../artillery/lib/util/sleep');
15
16
 
16
17
  module.exports = phaser;
17
18
 
@@ -96,50 +97,67 @@ function createRamp(spec, ee) {
96
97
  const duration = spec.duration || 1;
97
98
  const arrivalRate = spec.arrivalRate;
98
99
  const rampTo = spec.rampTo;
100
+ const worker = spec.worker;
101
+ const totalWorkers = spec.totalWorkers;
99
102
 
100
- // smallest tick we can get away with. Both arrivalRate and rampTo
101
- // can be zero. So in that case we use 1s ticks even tho no
102
- // arrivals will be generated
103
- let tick = 1000 / Math.max(Math.max(arrivalRate, rampTo), 1);
104
103
  const difference = rampTo - arrivalRate;
105
- const periods = duration * 1000 / tick;
104
+ const periods = duration;
105
+ debug(`worker ${worker} totalWorkers ${totalWorkers} arrivalRate ${arrivalRate} rampTo ${rampTo} difference ${difference} periods ${periods}`);
106
+
107
+ const periodArrivals = [];
108
+ const periodTick = [];
109
+ // if there is only one peridod we generate mean arrivals
110
+ if (periods === 1) {
111
+ periodArrivals[0] = Math.floor((rampTo + arrivalRate) / 2);
112
+ periodTick[0] = 1000 / periodArrivals;
113
+ } else {
114
+ // for each period we calculate the corresponding arrivals:
115
+ // knowing that arrivals(0) = arrivalRate and arrivals(duration -1) = rampTo
116
+ // then: arrivals(t) = difference / (duration-1) * t + arrivalRate
117
+ for (let i = 0; i < periods; i++) {
118
+ const rawPeriodArrivals = (difference / (duration - 1)) * i + arrivalRate;
119
+
120
+ // We use the floor of the expected arrivals, then we add up all decimal digits
121
+ // and evaluate if one or more workers should bump their arrivalRate.
122
+ periodArrivals[i] = Math.floor(rawPeriodArrivals);
123
+
124
+ // Think of fractionalPart * workers as the amount of arrivals that could not be
125
+ // shared evenly across all workers.
126
+ if (Math.round((rawPeriodArrivals % 1) * totalWorkers) >= worker) {
127
+ periodArrivals[i] = periodArrivals[i] + 1;
128
+ }
106
129
 
107
- function arrivalProbability(currentStep) {
108
- // linear function ax + b
109
- // normalized to 0 <= f(t) <= 1
110
- // Anything under function value should be an arrival
130
+ // Needed ticks to get to periodArrivals in 1000ms
131
+ periodTick[i] = periodArrivals[i] > 0 ? Math.floor(1000 / periodArrivals[i]) : 1000;
132
+ }
133
+ }
111
134
 
112
- let t = currentStep * tick / 1000;
113
- return ((difference / duration) * t + arrivalRate) / Math.max(rampTo, arrivalRate) || 0;
114
- };
135
+ debug(`periodArrivals ${periodArrivals}`);
136
+ debug(`periodTick ${periodTick}`);
115
137
 
116
- let probabilities = Array.from({length: periods}, () => Math.random());
138
+ return async function rampTask(callback) {
139
+ ee.emit('phaseStarted', spec);
140
+ for (let period = 0; period < periods; period++) {
141
+ ticker(period);
142
+ await sleep(1000);
143
+ }
117
144
 
118
- debug(
119
- `rampTo: tick = ${tick}; difference = ${difference}; rampTo = ${rampTo}; arrivalRate = ${arrivalRate}; periods = ${periods}`
120
- );
145
+ ee.emit('phaseCompleted', spec);
146
+ }
121
147
 
122
- return function rampTask(callback) {
123
- ee.emit('phaseStarted', spec);
124
- let currentStep = 1;
125
- const timer = driftless.setDriftlessInterval(function maybeArrival() {
126
- if (currentStep <= periods) {
127
- let arrivalBreakpoint = arrivalProbability(currentStep);
128
- let roll = probabilities[currentStep-1];
129
- debug(`roll:${roll} <= breakpoint:${arrivalBreakpoint}`);
130
- if (roll <= arrivalBreakpoint) {
131
- ee.emit('arrival', spec);
132
- }
133
-
134
- currentStep++;
148
+ function ticker(currentPeriod) {
149
+ let currentArrivals = 0;
150
+ let arrivalTimer = driftless.setDriftlessInterval(function arrivals() {
151
+ if (currentArrivals < periodArrivals[currentPeriod]) {
152
+ ee.emit('arrival', spec);
153
+ currentArrivals++;
135
154
  } else {
136
- driftless.clearDriftless(timer);
137
- ee.emit('phaseCompleted', spec);
138
-
139
- return callback(null);
155
+ currentPeriod++;
156
+ driftless.clearDriftless(arrivalTimer);
140
157
  }
141
- }, tick);
142
- };
158
+ }, periodTick[currentPeriod]);
159
+ return;
160
+ }
143
161
  }
144
162
 
145
163
  function createArrivalCount(spec, ee) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artilleryio/int-core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "main": "./index.js",
5
5
  "dependencies": {
6
6
  "@artilleryio/sketches-js": "^1.0.4",
@@ -39,6 +39,8 @@
39
39
  "ws": "^7.5.7"
40
40
  },
41
41
  "scripts": {
42
+ "lint": "eslint --ext \".js,.ts,.tsx\" .",
43
+ "lint-fix": "npm run lint -- --fix",
42
44
  "test": "tap --no-coverage --timeout=300 test/core/unit/*.test.js && bash test/core/run.sh"
43
45
  },
44
46
  "devDependencies": {