@webex/calling 3.12.0-mobius-socket.18 → 3.12.0-mobius-socket.20
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/dist/CallingClient/utils/request.js +6 -3
- package/dist/CallingClient/utils/request.js.map +1 -1
- package/dist/CallingClient/utils/request.test.js +2 -2
- package/dist/CallingClient/utils/request.test.js.map +1 -1
- package/dist/CallingClient/utils/types.js.map +1 -1
- package/dist/mobius-socket/config.js +7 -44
- package/dist/mobius-socket/config.js.map +1 -1
- package/dist/mobius-socket/errors.js +71 -26
- package/dist/mobius-socket/errors.js.map +1 -1
- package/dist/mobius-socket/index.js +4 -54
- package/dist/mobius-socket/index.js.map +1 -1
- package/dist/mobius-socket/mobius-socket-events.test.js +20 -48
- package/dist/mobius-socket/mobius-socket-events.test.js.map +1 -1
- package/dist/mobius-socket/mobius-socket.js +359 -748
- package/dist/mobius-socket/mobius-socket.js.map +1 -1
- package/dist/mobius-socket/mobius-socket.test.js +452 -728
- package/dist/mobius-socket/mobius-socket.test.js.map +1 -1
- package/dist/mobius-socket/socket/constants.js +14 -0
- package/dist/mobius-socket/socket/constants.js.map +1 -1
- package/dist/mobius-socket/socket/socket-base.js +152 -205
- package/dist/mobius-socket/socket/socket-base.js.map +1 -1
- package/dist/mobius-socket/socket/types.js.map +1 -1
- package/dist/mobius-socket/socket.test.js +38 -63
- package/dist/mobius-socket/socket.test.js.map +1 -1
- package/dist/mobius-socket/types.js.map +1 -1
- package/dist/module/CallingClient/utils/request.js +3 -2
- package/dist/module/mobius-socket/config.js +7 -10
- package/dist/module/mobius-socket/errors.js +34 -0
- package/dist/module/mobius-socket/index.js +0 -3
- package/dist/module/mobius-socket/mobius-socket.js +237 -426
- package/dist/module/mobius-socket/socket/socket-base.js +79 -116
- package/dist/types/CallingClient/utils/request.d.ts.map +1 -1
- package/dist/types/CallingClient/utils/types.d.ts +1 -1
- package/dist/types/CallingClient/utils/types.d.ts.map +1 -1
- package/dist/types/mobius-socket/config.d.ts +7 -8
- package/dist/types/mobius-socket/config.d.ts.map +1 -1
- package/dist/types/mobius-socket/errors.d.ts +11 -1
- package/dist/types/mobius-socket/errors.d.ts.map +1 -1
- package/dist/types/mobius-socket/index.d.ts +1 -5
- package/dist/types/mobius-socket/index.d.ts.map +1 -1
- package/dist/types/mobius-socket/mobius-socket.d.ts +33 -35
- package/dist/types/mobius-socket/mobius-socket.d.ts.map +1 -1
- package/dist/types/mobius-socket/socket/constants.d.ts.map +1 -1
- package/dist/types/mobius-socket/socket/socket-base.d.ts +9 -10
- package/dist/types/mobius-socket/socket/socket-base.d.ts.map +1 -1
- package/dist/types/mobius-socket/socket/types.d.ts +0 -8
- package/dist/types/mobius-socket/socket/types.d.ts.map +1 -1
- package/dist/types/mobius-socket/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -24,6 +24,9 @@ var _testHelperChai = require("@webex/test-helper-chai");
|
|
|
24
24
|
var _testHelperMockWebex = _interopRequireDefault(require("@webex/test-helper-mock-webex"));
|
|
25
25
|
var _testHelperMockWebSocket = _interopRequireDefault(require("@webex/test-helper-mock-web-socket"));
|
|
26
26
|
var _index = _interopRequireWildcard(require("./index"));
|
|
27
|
+
var _errors = require("./errors");
|
|
28
|
+
var _config = _interopRequireDefault(require("./config"));
|
|
29
|
+
var _socket = _interopRequireDefault(require("./socket"));
|
|
27
30
|
var _mochaHelpers = require("./test/mocha-helpers");
|
|
28
31
|
var _constants = require("./socket/constants");
|
|
29
32
|
var _promiseTick = _interopRequireDefault(require("./test/promise-tick"));
|
|
@@ -50,7 +53,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
50
53
|
var configuredWebex = new _testHelperMockWebex.default();
|
|
51
54
|
var instance = (0, _index.getMobiusSocketInstance)(configuredWebex);
|
|
52
55
|
_testHelperChai.assert.instanceOf(instance, _index.default);
|
|
53
|
-
_testHelperChai.assert.deepEqual(instance.config,
|
|
56
|
+
_testHelperChai.assert.deepEqual(instance.config, _config.default.mobiusSocket);
|
|
54
57
|
});
|
|
55
58
|
it('uses consumer config when it is provided', function () {
|
|
56
59
|
var configuredWebex = new _testHelperMockWebex.default();
|
|
@@ -60,7 +63,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
60
63
|
};
|
|
61
64
|
var instance = (0, _index.getMobiusSocketInstance)(configuredWebex, consumerConfig);
|
|
62
65
|
_testHelperChai.assert.instanceOf(instance, _index.default);
|
|
63
|
-
_testHelperChai.assert.deepEqual(instance.config, _objectSpread(_objectSpread({},
|
|
66
|
+
_testHelperChai.assert.deepEqual(instance.config, _objectSpread(_objectSpread({}, _config.default.mobiusSocket), consumerConfig));
|
|
64
67
|
});
|
|
65
68
|
});
|
|
66
69
|
describe('MobiusSocket', function () {
|
|
@@ -116,9 +119,9 @@ describe('plugin-mobius-socket', function () {
|
|
|
116
119
|
removeAllListeners: _sinon.default.stub()
|
|
117
120
|
};
|
|
118
121
|
};
|
|
119
|
-
var countGenericEventEmits = function countGenericEventEmits(emitSpy
|
|
122
|
+
var countGenericEventEmits = function countGenericEventEmits(emitSpy) {
|
|
120
123
|
return emitSpy.getCalls().filter(function (call) {
|
|
121
|
-
return call.args[0] ===
|
|
124
|
+
return call.args[0] === 'event';
|
|
122
125
|
}).length;
|
|
123
126
|
};
|
|
124
127
|
beforeEach(function () {
|
|
@@ -155,7 +158,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
155
158
|
webex.internal.metrics.submitClientMetrics = _sinon.default.stub();
|
|
156
159
|
webex.trackingId = 'fakeTrackingId';
|
|
157
160
|
webex.logger = console;
|
|
158
|
-
_sinon.default.stub(
|
|
161
|
+
_sinon.default.stub(_socket.default, 'getWebSocketConstructor').callsFake(function () {
|
|
159
162
|
return function () {
|
|
160
163
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
161
164
|
args[_key] = arguments[_key];
|
|
@@ -164,8 +167,8 @@ describe('plugin-mobius-socket', function () {
|
|
|
164
167
|
return mockWebSocket;
|
|
165
168
|
};
|
|
166
169
|
});
|
|
167
|
-
var origOpen =
|
|
168
|
-
socketOpenStub = _sinon.default.stub(
|
|
170
|
+
var origOpen = _socket.default.prototype.open;
|
|
171
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open').callsFake(function () {
|
|
169
172
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
170
173
|
args[_key2] = arguments[_key2];
|
|
171
174
|
}
|
|
@@ -179,8 +182,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
179
182
|
});
|
|
180
183
|
return promise;
|
|
181
184
|
});
|
|
182
|
-
mobiusSocket = new _index.default(webex, _objectSpread({},
|
|
183
|
-
mobiusSocket.defaultSessionId = 'mobius-websocket-session';
|
|
185
|
+
mobiusSocket = new _index.default(webex, _objectSpread({}, _config.default.mobiusSocket));
|
|
184
186
|
});
|
|
185
187
|
afterEach(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
186
188
|
var _t;
|
|
@@ -194,12 +196,12 @@ describe('plugin-mobius-socket', function () {
|
|
|
194
196
|
|
|
195
197
|
// Clean up MobiusSocket connections and internal state
|
|
196
198
|
if (!mobiusSocket) {
|
|
197
|
-
_context.next =
|
|
199
|
+
_context.next = 4;
|
|
198
200
|
break;
|
|
199
201
|
}
|
|
200
202
|
_context.prev = 1;
|
|
201
203
|
_context.next = 2;
|
|
202
|
-
return mobiusSocket.
|
|
204
|
+
return mobiusSocket.disconnect();
|
|
203
205
|
case 2:
|
|
204
206
|
_context.next = 4;
|
|
205
207
|
break;
|
|
@@ -207,11 +209,6 @@ describe('plugin-mobius-socket', function () {
|
|
|
207
209
|
_context.prev = 3;
|
|
208
210
|
_t = _context["catch"](1);
|
|
209
211
|
case 4:
|
|
210
|
-
// Clear any remaining connection promises
|
|
211
|
-
if (mobiusSocket._connectPromises) {
|
|
212
|
-
mobiusSocket._connectPromises.clear();
|
|
213
|
-
}
|
|
214
|
-
case 5:
|
|
215
212
|
// Ensure mock socket is properly closed
|
|
216
213
|
if (mockWebSocket && typeof mockWebSocket.close === 'function') {
|
|
217
214
|
try {
|
|
@@ -223,16 +220,16 @@ describe('plugin-mobius-socket', function () {
|
|
|
223
220
|
if (socketOpenStub) {
|
|
224
221
|
socketOpenStub.restore();
|
|
225
222
|
}
|
|
226
|
-
if (
|
|
227
|
-
|
|
223
|
+
if (_socket.default.getWebSocketConstructor.restore) {
|
|
224
|
+
_socket.default.getWebSocketConstructor.restore();
|
|
228
225
|
}
|
|
229
226
|
|
|
230
227
|
// Small delay to ensure all async operations complete
|
|
231
|
-
_context.next =
|
|
228
|
+
_context.next = 5;
|
|
232
229
|
return new _promise.default(function (resolve) {
|
|
233
230
|
setTimeout(resolve, 10);
|
|
234
231
|
});
|
|
235
|
-
case
|
|
232
|
+
case 5:
|
|
236
233
|
case "end":
|
|
237
234
|
return _context.stop();
|
|
238
235
|
}
|
|
@@ -248,15 +245,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
248
245
|
});
|
|
249
246
|
});
|
|
250
247
|
it('connects to MobiusSocket using default url', function () {
|
|
251
|
-
webex.internal.feature.updateFeature = _sinon.default.stub();
|
|
252
248
|
var promise = mobiusSocket.connect();
|
|
253
|
-
var envelope = {
|
|
254
|
-
data: {
|
|
255
|
-
featureToggle: {
|
|
256
|
-
'feature-name': true
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
249
|
_testHelperChai.assert.isFalse(mobiusSocket.connected, 'MobiusSocket is not connected');
|
|
261
250
|
_testHelperChai.assert.isTrue(mobiusSocket.connecting, 'MobiusSocket is connecting');
|
|
262
251
|
mockWebSocket.open();
|
|
@@ -264,94 +253,31 @@ describe('plugin-mobius-socket', function () {
|
|
|
264
253
|
_testHelperChai.assert.isTrue(mobiusSocket.connected, 'MobiusSocket is connected');
|
|
265
254
|
_testHelperChai.assert.isFalse(mobiusSocket.connecting, 'MobiusSocket is not connecting');
|
|
266
255
|
_testHelperChai.assert.calledWith(socketOpenStub, 'ws://example.com', _sinon.default.match.any);
|
|
267
|
-
mobiusSocket.emit('event:featureToggle_update', envelope);
|
|
268
|
-
_testHelperChai.assert.calledOnceWithExactly(webex.internal.feature.updateFeature, envelope.data.featureToggle);
|
|
269
|
-
_sinon.default.restore();
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
it('connects to MobiusSocket but does not call updateFeature', function () {
|
|
273
|
-
webex.internal.feature.updateFeature = _sinon.default.stub();
|
|
274
|
-
var promise = mobiusSocket.connect();
|
|
275
|
-
var envelope = {};
|
|
276
|
-
return promise.then(function () {
|
|
277
|
-
mobiusSocket.emit('event:featureToggle_update', envelope);
|
|
278
|
-
_testHelperChai.assert.notCalled(webex.internal.feature.updateFeature);
|
|
279
|
-
_sinon.default.restore();
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
it('MobiusSocket emit event:ActiveClusterStatusEvent, call services switchActiveClusterIds', function () {
|
|
283
|
-
var promise = mobiusSocket.connect();
|
|
284
|
-
var activeClusterEventEnvelope = {
|
|
285
|
-
data: {
|
|
286
|
-
activeClusters: {
|
|
287
|
-
wdm: 'wdm-cluster-id.com'
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
mockWebSocket.open();
|
|
292
|
-
return promise.then(function () {
|
|
293
|
-
mobiusSocket.emit('event:ActiveClusterStatusEvent', activeClusterEventEnvelope);
|
|
294
|
-
_testHelperChai.assert.calledOnceWithExactly(webex.internal.services.switchActiveClusterIds, activeClusterEventEnvelope.data.activeClusters);
|
|
295
|
-
_sinon.default.restore();
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
it('MobiusSocket emit event:ActiveClusterStatusEvent with no data, not call services switchActiveClusterIds', function () {
|
|
299
|
-
webex.internal.feature.updateFeature = _sinon.default.stub();
|
|
300
|
-
var promise = mobiusSocket.connect();
|
|
301
|
-
var envelope = {};
|
|
302
|
-
return promise.then(function () {
|
|
303
|
-
mobiusSocket.emit('event:ActiveClusterStatusEvent', envelope);
|
|
304
|
-
_testHelperChai.assert.notCalled(webex.internal.services.switchActiveClusterIds);
|
|
305
|
-
_sinon.default.restore();
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
it('MobiusSocket emit event:u2c.cache-invalidation, call services invalidateCache', function () {
|
|
309
|
-
var promise = mobiusSocket.connect();
|
|
310
|
-
var u2cInvalidateEventEnvelope = {
|
|
311
|
-
data: {
|
|
312
|
-
timestamp: '1759289614'
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
mockWebSocket.open();
|
|
316
|
-
return promise.then(function () {
|
|
317
|
-
mobiusSocket.emit('event:u2c.cache-invalidation', u2cInvalidateEventEnvelope);
|
|
318
|
-
_testHelperChai.assert.calledOnceWithExactly(webex.internal.services.invalidateCache, u2cInvalidateEventEnvelope.data.timestamp);
|
|
319
|
-
_sinon.default.restore();
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
it('MobiusSocket emit event:u2c.cache-invalidation with no data, not call services switchActiveClusterIds', function () {
|
|
323
|
-
webex.internal.feature.updateFeature = _sinon.default.stub();
|
|
324
|
-
var promise = mobiusSocket.connect();
|
|
325
|
-
var envelope = {};
|
|
326
|
-
return promise.then(function () {
|
|
327
|
-
mobiusSocket.emit('event:u2c.cache-invalidation', envelope);
|
|
328
|
-
_testHelperChai.assert.notCalled(webex.internal.services.invalidateCache);
|
|
329
|
-
_sinon.default.restore();
|
|
330
256
|
});
|
|
331
257
|
});
|
|
332
258
|
describe('when `maxRetries` is set', function () {
|
|
333
259
|
var check = function check() {
|
|
334
260
|
socketOpenStub.restore();
|
|
335
|
-
socketOpenStub = _sinon.default.stub(
|
|
336
|
-
socketOpenStub.returns(_promise.default.reject(new
|
|
337
|
-
_testHelperChai.assert.notCalled(
|
|
261
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open');
|
|
262
|
+
socketOpenStub.returns(_promise.default.reject(new _errors.ConnectionError()));
|
|
263
|
+
_testHelperChai.assert.notCalled(_socket.default.prototype.open);
|
|
338
264
|
var promise = mobiusSocket.connect();
|
|
339
265
|
return (0, _promiseTick.default)(5).then(function () {
|
|
340
|
-
_testHelperChai.assert.calledOnce(
|
|
266
|
+
_testHelperChai.assert.calledOnce(_socket.default.prototype.open);
|
|
341
267
|
return (0, _promiseTick.default)(5);
|
|
342
268
|
}).then(function () {
|
|
343
269
|
jest.advanceTimersByTime(mobiusSocket.config.backoffTimeReset);
|
|
344
270
|
return (0, _promiseTick.default)(5);
|
|
345
271
|
}).then(function () {
|
|
346
|
-
_testHelperChai.assert.calledTwice(
|
|
272
|
+
_testHelperChai.assert.calledTwice(_socket.default.prototype.open);
|
|
347
273
|
jest.advanceTimersByTime(2 * mobiusSocket.config.backoffTimeReset);
|
|
348
274
|
return (0, _promiseTick.default)(5);
|
|
349
275
|
}).then(function () {
|
|
350
|
-
_testHelperChai.assert.calledThrice(
|
|
276
|
+
_testHelperChai.assert.calledThrice(_socket.default.prototype.open);
|
|
351
277
|
jest.advanceTimersByTime(5 * mobiusSocket.config.backoffTimeReset);
|
|
352
278
|
return _testHelperChai.assert.isRejected(promise);
|
|
353
279
|
}).then(function () {
|
|
354
|
-
_testHelperChai.assert.calledThrice(
|
|
280
|
+
_testHelperChai.assert.calledThrice(_socket.default.prototype.open);
|
|
355
281
|
});
|
|
356
282
|
};
|
|
357
283
|
|
|
@@ -368,15 +294,15 @@ describe('plugin-mobius-socket', function () {
|
|
|
368
294
|
mobiusSocket.config.maxRetries = 2;
|
|
369
295
|
mobiusSocket.config.initialConnectionMaxRetries = 0;
|
|
370
296
|
socketOpenStub.restore();
|
|
371
|
-
socketOpenStub = _sinon.default.stub(
|
|
372
|
-
socketOpenStub.returns(_promise.default.reject(new
|
|
373
|
-
_testHelperChai.assert.notCalled(
|
|
297
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open');
|
|
298
|
+
socketOpenStub.returns(_promise.default.reject(new _errors.ConnectionError()));
|
|
299
|
+
_testHelperChai.assert.notCalled(_socket.default.prototype.open);
|
|
374
300
|
var promise = mobiusSocket.connect();
|
|
375
301
|
return (0, _promiseTick.default)(5).then(function () {
|
|
376
|
-
_testHelperChai.assert.calledOnce(
|
|
302
|
+
_testHelperChai.assert.calledOnce(_socket.default.prototype.open);
|
|
377
303
|
return _testHelperChai.assert.isRejected(promise);
|
|
378
304
|
}).then(function () {
|
|
379
|
-
_testHelperChai.assert.calledOnce(
|
|
305
|
+
_testHelperChai.assert.calledOnce(_socket.default.prototype.open);
|
|
380
306
|
});
|
|
381
307
|
});
|
|
382
308
|
|
|
@@ -406,7 +332,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
406
332
|
var promise = _promise.default.all([mobiusSocket.connect(), mobiusSocket.connect(), mobiusSocket.connect(), mobiusSocket.connect()]);
|
|
407
333
|
mockWebSocket.open();
|
|
408
334
|
return promise.then(function () {
|
|
409
|
-
_testHelperChai.assert.calledOnce(
|
|
335
|
+
_testHelperChai.assert.calledOnce(_socket.default.prototype.open);
|
|
410
336
|
});
|
|
411
337
|
});
|
|
412
338
|
|
|
@@ -415,16 +341,16 @@ describe('plugin-mobius-socket', function () {
|
|
|
415
341
|
it('backs off exponentially', function () {
|
|
416
342
|
mobiusSocket.config.initialConnectionMaxRetries = 2;
|
|
417
343
|
socketOpenStub.restore();
|
|
418
|
-
socketOpenStub = _sinon.default.stub(
|
|
419
|
-
socketOpenStub.returns(_promise.default.reject(new
|
|
344
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open');
|
|
345
|
+
socketOpenStub.returns(_promise.default.reject(new _errors.ConnectionError({
|
|
420
346
|
code: 4001
|
|
421
347
|
})));
|
|
422
348
|
// Note: onCall is zero-based
|
|
423
349
|
socketOpenStub.onCall(2).returns(_promise.default.resolve(new _testHelperMockWebSocket.default()));
|
|
424
|
-
_testHelperChai.assert.notCalled(
|
|
350
|
+
_testHelperChai.assert.notCalled(_socket.default.prototype.open);
|
|
425
351
|
var promise = mobiusSocket.connect();
|
|
426
352
|
return (0, _promiseTick.default)(5).then(function () {
|
|
427
|
-
_testHelperChai.assert.calledOnce(
|
|
353
|
+
_testHelperChai.assert.calledOnce(_socket.default.prototype.open);
|
|
428
354
|
|
|
429
355
|
// I'm not sure why, but it's important the clock doesn't advance
|
|
430
356
|
// until a tick happens
|
|
@@ -433,19 +359,19 @@ describe('plugin-mobius-socket', function () {
|
|
|
433
359
|
jest.advanceTimersByTime(mobiusSocket.config.backoffTimeReset);
|
|
434
360
|
return (0, _promiseTick.default)(5);
|
|
435
361
|
}).then(function () {
|
|
436
|
-
_testHelperChai.assert.calledTwice(
|
|
362
|
+
_testHelperChai.assert.calledTwice(_socket.default.prototype.open);
|
|
437
363
|
jest.advanceTimersByTime(2 * mobiusSocket.config.backoffTimeReset);
|
|
438
364
|
return (0, _promiseTick.default)(5);
|
|
439
365
|
}).then(function () {
|
|
440
|
-
_testHelperChai.assert.calledThrice(
|
|
366
|
+
_testHelperChai.assert.calledThrice(_socket.default.prototype.open);
|
|
441
367
|
jest.advanceTimersByTime(5 * mobiusSocket.config.backoffTimeReset);
|
|
442
368
|
return promise;
|
|
443
369
|
}).then(function () {
|
|
444
|
-
_testHelperChai.assert.calledThrice(
|
|
370
|
+
_testHelperChai.assert.calledThrice(_socket.default.prototype.open);
|
|
445
371
|
jest.advanceTimersByTime(8 * mobiusSocket.config.backoffTimeReset);
|
|
446
372
|
return (0, _promiseTick.default)(5);
|
|
447
373
|
}).then(function () {
|
|
448
|
-
_testHelperChai.assert.calledThrice(
|
|
374
|
+
_testHelperChai.assert.calledThrice(_socket.default.prototype.open);
|
|
449
375
|
});
|
|
450
376
|
});
|
|
451
377
|
describe('with `BadRequest`', function () {
|
|
@@ -453,7 +379,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
453
379
|
jest.useRealTimers();
|
|
454
380
|
usingFakeTimers = false;
|
|
455
381
|
socketOpenStub.restore();
|
|
456
|
-
socketOpenStub = _sinon.default.stub(
|
|
382
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open').returns(_promise.default.reject(new _errors.BadRequest({
|
|
457
383
|
code: 4400
|
|
458
384
|
})));
|
|
459
385
|
return _testHelperChai.assert.isRejected(mobiusSocket.connect());
|
|
@@ -463,8 +389,8 @@ describe('plugin-mobius-socket', function () {
|
|
|
463
389
|
it('triggers a device refresh', function () {
|
|
464
390
|
mobiusSocket.config.initialConnectionMaxRetries = 1;
|
|
465
391
|
socketOpenStub.restore();
|
|
466
|
-
socketOpenStub = _sinon.default.stub(
|
|
467
|
-
socketOpenStub.onCall(0).returns(_promise.default.reject(new
|
|
392
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open').returns(_promise.default.resolve());
|
|
393
|
+
socketOpenStub.onCall(0).returns(_promise.default.reject(new _errors.UnknownResponse({
|
|
468
394
|
code: 4444
|
|
469
395
|
})));
|
|
470
396
|
_testHelperChai.assert.notCalled(webex.credentials.refresh);
|
|
@@ -482,8 +408,8 @@ describe('plugin-mobius-socket', function () {
|
|
|
482
408
|
it('triggers a token refresh', function () {
|
|
483
409
|
mobiusSocket.config.initialConnectionMaxRetries = 1;
|
|
484
410
|
socketOpenStub.restore();
|
|
485
|
-
socketOpenStub = _sinon.default.stub(
|
|
486
|
-
socketOpenStub.onCall(0).returns(_promise.default.reject(new
|
|
411
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open').returns(_promise.default.resolve());
|
|
412
|
+
socketOpenStub.onCall(0).returns(_promise.default.reject(new _errors.NotAuthorized({
|
|
487
413
|
code: 4401
|
|
488
414
|
})));
|
|
489
415
|
_testHelperChai.assert.notCalled(webex.credentials.refresh);
|
|
@@ -502,7 +428,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
502
428
|
jest.useRealTimers();
|
|
503
429
|
usingFakeTimers = false;
|
|
504
430
|
socketOpenStub.restore();
|
|
505
|
-
socketOpenStub = _sinon.default.stub(
|
|
431
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open').returns(_promise.default.reject(new _errors.Forbidden({
|
|
506
432
|
code: 4403
|
|
507
433
|
})));
|
|
508
434
|
return _testHelperChai.assert.isRejected(mobiusSocket.connect());
|
|
@@ -550,7 +476,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
550
476
|
jest.advanceTimersByTime(6 * mobiusSocket.config.backoffTimeReset);
|
|
551
477
|
return (0, _promiseTick.default)(2);
|
|
552
478
|
}).then(function () {
|
|
553
|
-
_testHelperChai.assert.calledOnce(
|
|
479
|
+
_testHelperChai.assert.calledOnce(_socket.default.prototype.open);
|
|
554
480
|
});
|
|
555
481
|
});
|
|
556
482
|
});
|
|
@@ -565,13 +491,13 @@ describe('plugin-mobius-socket', function () {
|
|
|
565
491
|
return promise.then(function () {
|
|
566
492
|
_testHelperChai.assert.isTrue(mobiusSocket.connected, 'MobiusSocket is connected');
|
|
567
493
|
_testHelperChai.assert.isFalse(mobiusSocket.connecting, 'MobiusSocket is not connecting');
|
|
568
|
-
_testHelperChai.assert.calledWith(
|
|
494
|
+
_testHelperChai.assert.calledWith(_socket.default.prototype.open, 'ws://providedurl.com', _sinon.default.match.any);
|
|
569
495
|
});
|
|
570
496
|
});
|
|
571
497
|
});
|
|
572
498
|
describe('when config.initialConnectionMaxRetries is set to 0', function () {
|
|
573
499
|
it('connects successfully through the shared backoff flow', function () {
|
|
574
|
-
var backoffSpy = _sinon.default.spy(mobiusSocket, '
|
|
500
|
+
var backoffSpy = _sinon.default.spy(mobiusSocket, 'connectWithBackoff');
|
|
575
501
|
mobiusSocket.config.initialConnectionMaxRetries = 0;
|
|
576
502
|
var promise = mobiusSocket.connect('ws://example.com');
|
|
577
503
|
_testHelperChai.assert.isTrue(mobiusSocket.connecting, 'MobiusSocket is connecting');
|
|
@@ -581,7 +507,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
581
507
|
_testHelperChai.assert.isTrue(mobiusSocket.connected, 'MobiusSocket is connected');
|
|
582
508
|
_testHelperChai.assert.isFalse(mobiusSocket.connecting, 'MobiusSocket is not connecting');
|
|
583
509
|
_testHelperChai.assert.isTrue(mobiusSocket.hasEverConnected, 'hasEverConnected is true');
|
|
584
|
-
_testHelperChai.assert.calledOnce(
|
|
510
|
+
_testHelperChai.assert.calledOnce(_socket.default.prototype.open);
|
|
585
511
|
_testHelperChai.assert.calledOnce(backoffSpy);
|
|
586
512
|
_testHelperChai.assert.isUndefined((_backoffSpy$firstCall = backoffSpy.firstCall.args[2]) === null || _backoffSpy$firstCall === void 0 ? void 0 : _backoffSpy$firstCall.initialConnectionMaxRetries);
|
|
587
513
|
backoffSpy.restore();
|
|
@@ -591,18 +517,18 @@ describe('plugin-mobius-socket', function () {
|
|
|
591
517
|
jest.useRealTimers();
|
|
592
518
|
usingFakeTimers = false;
|
|
593
519
|
socketOpenStub.restore();
|
|
594
|
-
socketOpenStub = _sinon.default.stub(
|
|
520
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open').returns(_promise.default.reject(new _errors.ConnectionError({
|
|
595
521
|
code: 4001
|
|
596
522
|
})));
|
|
597
523
|
mobiusSocket.config.initialConnectionMaxRetries = 0;
|
|
598
524
|
var promise = mobiusSocket.connect('ws://example.com');
|
|
599
525
|
return _testHelperChai.assert.isRejected(promise).then(function () {
|
|
600
|
-
_testHelperChai.assert.calledOnce(
|
|
526
|
+
_testHelperChai.assert.calledOnce(_socket.default.prototype.open);
|
|
601
527
|
_testHelperChai.assert.isFalse(mobiusSocket.connected, 'MobiusSocket is not connected');
|
|
602
528
|
});
|
|
603
529
|
});
|
|
604
530
|
it('uses config-driven initial retry behavior in the shared backoff strategy', function () {
|
|
605
|
-
var backoffSpy = _sinon.default.spy(mobiusSocket, '
|
|
531
|
+
var backoffSpy = _sinon.default.spy(mobiusSocket, 'connectWithBackoff');
|
|
606
532
|
mobiusSocket.config.initialConnectionMaxRetries = 0;
|
|
607
533
|
var promise = mobiusSocket.connect('ws://example.com');
|
|
608
534
|
mockWebSocket.open();
|
|
@@ -621,12 +547,12 @@ describe('plugin-mobius-socket', function () {
|
|
|
621
547
|
mobiusSocket.config.initialConnectionMaxRetries = 0;
|
|
622
548
|
mobiusSocket.config.maxRetries = 5;
|
|
623
549
|
socketOpenStub.restore();
|
|
624
|
-
socketOpenStub = _sinon.default.stub(
|
|
550
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open').returns(_promise.default.reject(new _errors.ConnectionError({
|
|
625
551
|
code: 4001
|
|
626
552
|
})));
|
|
627
553
|
var promise = mobiusSocket.connect('ws://new-url.com');
|
|
628
554
|
return _testHelperChai.assert.isRejected(promise).then(function () {
|
|
629
|
-
_testHelperChai.assert.calledOnce(
|
|
555
|
+
_testHelperChai.assert.calledOnce(_socket.default.prototype.open);
|
|
630
556
|
_testHelperChai.assert.equal(mobiusSocket.socketUrl, 'ws://new-url.com');
|
|
631
557
|
_testHelperChai.assert.isFalse(mobiusSocket.hasEverConnected, 'hasEverConnected is false');
|
|
632
558
|
});
|
|
@@ -670,40 +596,6 @@ describe('plugin-mobius-socket', function () {
|
|
|
670
596
|
});
|
|
671
597
|
});
|
|
672
598
|
});
|
|
673
|
-
describe('#logout()', function () {
|
|
674
|
-
it('calls disconnectAll and logs', function () {
|
|
675
|
-
_sinon.default.stub(mobiusSocket.logger, 'info');
|
|
676
|
-
_sinon.default.stub(mobiusSocket, 'disconnectAll');
|
|
677
|
-
mobiusSocket.logout();
|
|
678
|
-
_testHelperChai.assert.called(mobiusSocket.disconnectAll);
|
|
679
|
-
_testHelperChai.assert.calledOnce(mobiusSocket.logger.info);
|
|
680
|
-
_testHelperChai.assert.calledWith(mobiusSocket.logger.info.getCall(0), 'MobiusSocket: logout() called');
|
|
681
|
-
});
|
|
682
|
-
it('uses the config.beforeLogoutOptionsCloseReason to disconnect and will send code 3050 for logout', function () {
|
|
683
|
-
_sinon.default.stub(mobiusSocket, 'disconnectAll');
|
|
684
|
-
mobiusSocket.config.beforeLogoutOptionsCloseReason = 'done (permanent)';
|
|
685
|
-
mobiusSocket.logout();
|
|
686
|
-
_testHelperChai.assert.calledWith(mobiusSocket.disconnectAll, {
|
|
687
|
-
code: 3050,
|
|
688
|
-
reason: 'done (permanent)'
|
|
689
|
-
});
|
|
690
|
-
});
|
|
691
|
-
it('uses the config.beforeLogoutOptionsCloseReason to disconnect and will send code 3050 for logout if the reason is different than standard', function () {
|
|
692
|
-
_sinon.default.stub(mobiusSocket, 'disconnectAll');
|
|
693
|
-
mobiusSocket.config.beforeLogoutOptionsCloseReason = 'test';
|
|
694
|
-
mobiusSocket.logout();
|
|
695
|
-
_testHelperChai.assert.calledWith(mobiusSocket.disconnectAll, {
|
|
696
|
-
code: 3050,
|
|
697
|
-
reason: 'test'
|
|
698
|
-
});
|
|
699
|
-
});
|
|
700
|
-
it('uses the config.beforeLogoutOptionsCloseReason to disconnect and will send undefined for logout if the reason is same as standard', function () {
|
|
701
|
-
_sinon.default.stub(mobiusSocket, 'disconnectAll');
|
|
702
|
-
mobiusSocket.config.beforeLogoutOptionsCloseReason = 'done (forced)';
|
|
703
|
-
mobiusSocket.logout();
|
|
704
|
-
_testHelperChai.assert.calledWith(mobiusSocket.disconnectAll, undefined);
|
|
705
|
-
});
|
|
706
|
-
});
|
|
707
599
|
describe('#disconnect()', function () {
|
|
708
600
|
it('disconnects the WebSocket', function () {
|
|
709
601
|
return mobiusSocket.connect().then(function () {
|
|
@@ -777,7 +669,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
777
669
|
describe('when there is a connection attempt inflight', function () {
|
|
778
670
|
it('stops the attempt when disconnect called', function () {
|
|
779
671
|
socketOpenStub.restore();
|
|
780
|
-
socketOpenStub = _sinon.default.stub(
|
|
672
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open');
|
|
781
673
|
socketOpenStub.onCall(0).returns(
|
|
782
674
|
// Delay the opening of the socket so that disconnect is called while open
|
|
783
675
|
// is in progress
|
|
@@ -796,20 +688,17 @@ describe('plugin-mobius-socket', function () {
|
|
|
796
688
|
case 0:
|
|
797
689
|
// By this time backoffCall and mobiusSocket socket should be defined by the
|
|
798
690
|
// 'connect' call
|
|
799
|
-
_testHelperChai.assert.isDefined(mobiusSocket.
|
|
691
|
+
_testHelperChai.assert.isDefined(mobiusSocket.backoffCall, 'MobiusSocket backoffCall is not defined');
|
|
800
692
|
_testHelperChai.assert.isDefined(mobiusSocket.socket, 'MobiusSocket socket is not defined');
|
|
801
693
|
// Calling disconnect will abort the backoffCall, close the socket, and
|
|
802
694
|
// reject the connect
|
|
803
695
|
mobiusSocket.disconnect();
|
|
804
|
-
_testHelperChai.assert.isUndefined(mobiusSocket.
|
|
696
|
+
_testHelperChai.assert.isUndefined(mobiusSocket.backoffCall, 'MobiusSocket backoffCall is still defined');
|
|
805
697
|
// The socket will never be unset (which seems bad)
|
|
806
698
|
_testHelperChai.assert.isDefined(mobiusSocket.socket, 'MobiusSocket socket is not defined');
|
|
807
699
|
_context2.next = 1;
|
|
808
700
|
return _testHelperChai.assert.isRejected(promise);
|
|
809
701
|
case 1:
|
|
810
|
-
// connection did not fail, so no last error
|
|
811
|
-
_testHelperChai.assert.isUndefined(mobiusSocket.getLastError());
|
|
812
|
-
case 2:
|
|
813
702
|
case "end":
|
|
814
703
|
return _context2.stop();
|
|
815
704
|
}
|
|
@@ -818,64 +707,32 @@ describe('plugin-mobius-socket', function () {
|
|
|
818
707
|
});
|
|
819
708
|
it('stops the attempt when backoffCall is undefined', function () {
|
|
820
709
|
socketOpenStub.restore();
|
|
821
|
-
socketOpenStub = _sinon.default.stub(
|
|
710
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open');
|
|
822
711
|
socketOpenStub.returns(_promise.default.resolve());
|
|
823
712
|
var reason;
|
|
824
|
-
mobiusSocket.
|
|
825
|
-
var promise = mobiusSocket.
|
|
713
|
+
mobiusSocket.backoffCall = undefined;
|
|
714
|
+
var promise = mobiusSocket.attemptConnection('ws://example.com', function (_reason) {
|
|
826
715
|
reason = _reason;
|
|
827
716
|
});
|
|
828
717
|
return (0, _promiseTick.default)(mobiusSocket.config.backoffTimeReset).then(function () {
|
|
829
|
-
_testHelperChai.assert.
|
|
718
|
+
_testHelperChai.assert.match(reason.message, /prevent socket open when backoffCall no longer defined/);
|
|
830
719
|
|
|
831
720
|
// Ensure the promise was actually rejected (short-circuited)
|
|
832
721
|
return _testHelperChai.assert.isRejected(promise);
|
|
833
722
|
});
|
|
834
723
|
});
|
|
835
|
-
it('sets lastError when retrying', function () {
|
|
836
|
-
var realError = new Error('FORCED');
|
|
837
|
-
mobiusSocket.config.initialConnectionMaxRetries = 1;
|
|
838
|
-
socketOpenStub.restore();
|
|
839
|
-
socketOpenStub = _sinon.default.stub(_index.Socket.prototype, 'open');
|
|
840
|
-
socketOpenStub.onCall(0).returns(_promise.default.reject(realError));
|
|
841
|
-
var promise = mobiusSocket.connect();
|
|
842
|
-
|
|
843
|
-
// Wait for the connect call to setup
|
|
844
|
-
return (0, _promiseTick.default)(mobiusSocket.config.backoffTimeReset).then(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
845
|
-
var error, lastError;
|
|
846
|
-
return _regenerator.default.wrap(function (_context3) {
|
|
847
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
848
|
-
case 0:
|
|
849
|
-
// Calling disconnect will abort the backoffCall, close the socket, and
|
|
850
|
-
// reject the connect
|
|
851
|
-
mobiusSocket.disconnect();
|
|
852
|
-
_context3.next = 1;
|
|
853
|
-
return _testHelperChai.assert.isRejected(promise);
|
|
854
|
-
case 1:
|
|
855
|
-
error = _context3.sent;
|
|
856
|
-
lastError = mobiusSocket.getLastError();
|
|
857
|
-
_testHelperChai.assert.match(error.message, /MobiusSocket Connection Aborted/);
|
|
858
|
-
_testHelperChai.assert.isDefined(lastError);
|
|
859
|
-
_testHelperChai.assert.equal(lastError, realError);
|
|
860
|
-
case 2:
|
|
861
|
-
case "end":
|
|
862
|
-
return _context3.stop();
|
|
863
|
-
}
|
|
864
|
-
}, _callee3);
|
|
865
|
-
})));
|
|
866
|
-
});
|
|
867
724
|
});
|
|
868
725
|
});
|
|
869
726
|
describe('#sendWssRequest()', function () {
|
|
870
727
|
beforeEach(function () {
|
|
871
728
|
mobiusSocket.config.wssResponseTimeout = 100;
|
|
872
729
|
});
|
|
873
|
-
it('resolves when a matching response_event arrives', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
730
|
+
it('resolves when a matching response_event arrives', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
874
731
|
var requestPromise, requestPayload, response;
|
|
875
|
-
return _regenerator.default.wrap(function (
|
|
876
|
-
while (1) switch (
|
|
732
|
+
return _regenerator.default.wrap(function (_context3) {
|
|
733
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
877
734
|
case 0:
|
|
878
|
-
|
|
735
|
+
_context3.next = 1;
|
|
879
736
|
return mobiusSocket.connect();
|
|
880
737
|
case 1:
|
|
881
738
|
requestPromise = mobiusSocket.sendWssRequest({
|
|
@@ -884,7 +741,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
884
741
|
token: 'test'
|
|
885
742
|
}
|
|
886
743
|
});
|
|
887
|
-
|
|
744
|
+
_context3.next = 2;
|
|
888
745
|
return (0, _promiseTick.default)();
|
|
889
746
|
case 2:
|
|
890
747
|
requestPayload = JSON.parse(mockWebSocket.send.lastCall.args[0]);
|
|
@@ -898,26 +755,26 @@ describe('plugin-mobius-socket', function () {
|
|
|
898
755
|
statusMessage: 'OK'
|
|
899
756
|
})
|
|
900
757
|
});
|
|
901
|
-
|
|
758
|
+
_context3.next = 3;
|
|
902
759
|
return requestPromise;
|
|
903
760
|
case 3:
|
|
904
|
-
response =
|
|
761
|
+
response = _context3.sent;
|
|
905
762
|
_testHelperChai.assert.equal(response.type, 'response_event');
|
|
906
763
|
_testHelperChai.assert.equal(response.subtype, 'auth');
|
|
907
764
|
_testHelperChai.assert.equal(response.trackingId, requestPayload.trackingId);
|
|
908
765
|
_testHelperChai.assert.equal(response.statusCode, 200);
|
|
909
766
|
case 4:
|
|
910
767
|
case "end":
|
|
911
|
-
return
|
|
768
|
+
return _context3.stop();
|
|
912
769
|
}
|
|
913
|
-
},
|
|
770
|
+
}, _callee3);
|
|
914
771
|
})));
|
|
915
|
-
it('strips the Bearer prefix from connect-time auth token', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
772
|
+
it('strips the Bearer prefix from connect-time auth token', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4() {
|
|
916
773
|
var authPayload;
|
|
917
|
-
return _regenerator.default.wrap(function (
|
|
918
|
-
while (1) switch (
|
|
774
|
+
return _regenerator.default.wrap(function (_context4) {
|
|
775
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
919
776
|
case 0:
|
|
920
|
-
|
|
777
|
+
_context4.next = 1;
|
|
921
778
|
return mobiusSocket.connect();
|
|
922
779
|
case 1:
|
|
923
780
|
authPayload = JSON.parse(mockWebSocket.send.firstCall.args[0]);
|
|
@@ -925,16 +782,16 @@ describe('plugin-mobius-socket', function () {
|
|
|
925
782
|
_testHelperChai.assert.equal(authPayload.data.token, 'FAKE');
|
|
926
783
|
case 2:
|
|
927
784
|
case "end":
|
|
928
|
-
return
|
|
785
|
+
return _context4.stop();
|
|
929
786
|
}
|
|
930
|
-
},
|
|
787
|
+
}, _callee4);
|
|
931
788
|
})));
|
|
932
|
-
it('rejects when a matching response_event is non-2xx', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
789
|
+
it('rejects when a matching response_event is non-2xx', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5() {
|
|
933
790
|
var requestPromise, requestPayload, error;
|
|
934
|
-
return _regenerator.default.wrap(function (
|
|
935
|
-
while (1) switch (
|
|
791
|
+
return _regenerator.default.wrap(function (_context5) {
|
|
792
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
936
793
|
case 0:
|
|
937
|
-
|
|
794
|
+
_context5.next = 1;
|
|
938
795
|
return mobiusSocket.connect();
|
|
939
796
|
case 1:
|
|
940
797
|
requestPromise = mobiusSocket.sendWssRequest({
|
|
@@ -943,7 +800,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
943
800
|
token: 'test'
|
|
944
801
|
}
|
|
945
802
|
});
|
|
946
|
-
|
|
803
|
+
_context5.next = 2;
|
|
947
804
|
return (0, _promiseTick.default)();
|
|
948
805
|
case 2:
|
|
949
806
|
requestPayload = JSON.parse(mockWebSocket.send.lastCall.args[0]);
|
|
@@ -956,26 +813,26 @@ describe('plugin-mobius-socket', function () {
|
|
|
956
813
|
statusMessage: 'Forbidden'
|
|
957
814
|
})
|
|
958
815
|
});
|
|
959
|
-
|
|
816
|
+
_context5.next = 3;
|
|
960
817
|
return _testHelperChai.assert.isRejected(requestPromise);
|
|
961
818
|
case 3:
|
|
962
|
-
error =
|
|
819
|
+
error = _context5.sent;
|
|
963
820
|
_testHelperChai.assert.equal(error.name, 'MobiusSocketResponseError');
|
|
964
821
|
_testHelperChai.assert.equal(error.statusCode, 403);
|
|
965
822
|
_testHelperChai.assert.equal(error.statusMessage, 'Forbidden');
|
|
966
823
|
_testHelperChai.assert.equal(error.trackingId, requestPayload.trackingId);
|
|
967
824
|
case 4:
|
|
968
825
|
case "end":
|
|
969
|
-
return
|
|
826
|
+
return _context5.stop();
|
|
970
827
|
}
|
|
971
|
-
},
|
|
828
|
+
}, _callee5);
|
|
972
829
|
})));
|
|
973
|
-
it('rejects when the matching response does not arrive before timeout', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
830
|
+
it('rejects when the matching response does not arrive before timeout', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6() {
|
|
974
831
|
var requestPromise, error;
|
|
975
|
-
return _regenerator.default.wrap(function (
|
|
976
|
-
while (1) switch (
|
|
832
|
+
return _regenerator.default.wrap(function (_context6) {
|
|
833
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
977
834
|
case 0:
|
|
978
|
-
|
|
835
|
+
_context6.next = 1;
|
|
979
836
|
return mobiusSocket.connect();
|
|
980
837
|
case 1:
|
|
981
838
|
requestPromise = mobiusSocket.sendWssRequest({
|
|
@@ -985,28 +842,28 @@ describe('plugin-mobius-socket', function () {
|
|
|
985
842
|
}
|
|
986
843
|
});
|
|
987
844
|
jest.advanceTimersByTime(101);
|
|
988
|
-
|
|
845
|
+
_context6.next = 2;
|
|
989
846
|
return (0, _promiseTick.default)();
|
|
990
847
|
case 2:
|
|
991
|
-
|
|
848
|
+
_context6.next = 3;
|
|
992
849
|
return _testHelperChai.assert.isRejected(requestPromise);
|
|
993
850
|
case 3:
|
|
994
|
-
error =
|
|
851
|
+
error = _context6.sent;
|
|
995
852
|
_testHelperChai.assert.equal(error.name, 'MobiusSocketResponseError');
|
|
996
853
|
_testHelperChai.assert.equal(error.statusCode, 408);
|
|
997
854
|
_testHelperChai.assert.equal(error.statusMessage, 'Mobius websocket response timed out');
|
|
998
855
|
case 4:
|
|
999
856
|
case "end":
|
|
1000
|
-
return
|
|
857
|
+
return _context6.stop();
|
|
1001
858
|
}
|
|
1002
|
-
},
|
|
859
|
+
}, _callee6);
|
|
1003
860
|
})));
|
|
1004
|
-
it('rejects with a clear error when the matching response is missing status code', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
861
|
+
it('rejects with a clear error when the matching response is missing status code', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7() {
|
|
1005
862
|
var requestPromise, requestPayload, error;
|
|
1006
|
-
return _regenerator.default.wrap(function (
|
|
1007
|
-
while (1) switch (
|
|
863
|
+
return _regenerator.default.wrap(function (_context7) {
|
|
864
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
1008
865
|
case 0:
|
|
1009
|
-
|
|
866
|
+
_context7.next = 1;
|
|
1010
867
|
return mobiusSocket.connect();
|
|
1011
868
|
case 1:
|
|
1012
869
|
requestPromise = mobiusSocket.sendWssRequest({
|
|
@@ -1015,7 +872,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
1015
872
|
token: 'test'
|
|
1016
873
|
}
|
|
1017
874
|
});
|
|
1018
|
-
|
|
875
|
+
_context7.next = 2;
|
|
1019
876
|
return (0, _promiseTick.default)();
|
|
1020
877
|
case 2:
|
|
1021
878
|
requestPayload = JSON.parse(mockWebSocket.send.lastCall.args[0]);
|
|
@@ -1026,25 +883,25 @@ describe('plugin-mobius-socket', function () {
|
|
|
1026
883
|
trackingId: requestPayload.trackingId
|
|
1027
884
|
})
|
|
1028
885
|
});
|
|
1029
|
-
|
|
886
|
+
_context7.next = 3;
|
|
1030
887
|
return _testHelperChai.assert.isRejected(requestPromise);
|
|
1031
888
|
case 3:
|
|
1032
|
-
error =
|
|
889
|
+
error = _context7.sent;
|
|
1033
890
|
_testHelperChai.assert.equal(error.name, 'MobiusSocketResponseError');
|
|
1034
891
|
_testHelperChai.assert.isUndefined(error.statusCode);
|
|
1035
892
|
_testHelperChai.assert.equal(error.statusMessage, 'Socket response missing status code');
|
|
1036
893
|
case 4:
|
|
1037
894
|
case "end":
|
|
1038
|
-
return
|
|
895
|
+
return _context7.stop();
|
|
1039
896
|
}
|
|
1040
|
-
},
|
|
897
|
+
}, _callee7);
|
|
1041
898
|
})));
|
|
1042
|
-
it('rejects pending requests when the active socket closes', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
899
|
+
it('rejects pending requests when the active socket closes', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee8() {
|
|
1043
900
|
var requestPromise, error;
|
|
1044
|
-
return _regenerator.default.wrap(function (
|
|
1045
|
-
while (1) switch (
|
|
901
|
+
return _regenerator.default.wrap(function (_context8) {
|
|
902
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
1046
903
|
case 0:
|
|
1047
|
-
|
|
904
|
+
_context8.next = 1;
|
|
1048
905
|
return mobiusSocket.connect();
|
|
1049
906
|
case 1:
|
|
1050
907
|
requestPromise = mobiusSocket.sendWssRequest({
|
|
@@ -1057,52 +914,52 @@ describe('plugin-mobius-socket', function () {
|
|
|
1057
914
|
code: 1003,
|
|
1058
915
|
reason: 'service rejected request'
|
|
1059
916
|
});
|
|
1060
|
-
|
|
917
|
+
_context8.next = 2;
|
|
1061
918
|
return _testHelperChai.assert.isRejected(requestPromise);
|
|
1062
919
|
case 2:
|
|
1063
|
-
error =
|
|
1064
|
-
_testHelperChai.assert.instanceOf(error,
|
|
920
|
+
error = _context8.sent;
|
|
921
|
+
_testHelperChai.assert.instanceOf(error, _errors.ConnectionError);
|
|
1065
922
|
_testHelperChai.assert.equal(error.code, 1003);
|
|
1066
923
|
_testHelperChai.assert.equal(error.reason, 'service rejected request');
|
|
1067
924
|
case 3:
|
|
1068
925
|
case "end":
|
|
1069
|
-
return
|
|
926
|
+
return _context8.stop();
|
|
1070
927
|
}
|
|
1071
|
-
},
|
|
928
|
+
}, _callee8);
|
|
1072
929
|
})));
|
|
1073
|
-
it('rejects array payloads', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
930
|
+
it('rejects array payloads', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee9() {
|
|
1074
931
|
var error;
|
|
1075
|
-
return _regenerator.default.wrap(function (
|
|
1076
|
-
while (1) switch (
|
|
932
|
+
return _regenerator.default.wrap(function (_context9) {
|
|
933
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1077
934
|
case 0:
|
|
1078
|
-
|
|
935
|
+
_context9.next = 1;
|
|
1079
936
|
return mobiusSocket.connect();
|
|
1080
937
|
case 1:
|
|
1081
|
-
|
|
938
|
+
_context9.next = 2;
|
|
1082
939
|
return _testHelperChai.assert.isRejected(mobiusSocket.sendWssRequest([]));
|
|
1083
940
|
case 2:
|
|
1084
|
-
error =
|
|
941
|
+
error = _context9.sent;
|
|
1085
942
|
_testHelperChai.assert.equal(error.message, '`payload` is required');
|
|
1086
943
|
case 3:
|
|
1087
944
|
case "end":
|
|
1088
|
-
return
|
|
945
|
+
return _context9.stop();
|
|
1089
946
|
}
|
|
1090
|
-
},
|
|
947
|
+
}, _callee9);
|
|
1091
948
|
})));
|
|
1092
949
|
});
|
|
1093
950
|
describe('#getConnectedWebSocketUrl()', function () {
|
|
1094
|
-
it('returns the connected websocket url
|
|
1095
|
-
mobiusSocket.
|
|
951
|
+
it('returns the connected websocket url', function () {
|
|
952
|
+
mobiusSocket.socket = {
|
|
1096
953
|
connected: true,
|
|
1097
954
|
url: 'ws://connected-url.com'
|
|
1098
|
-
}
|
|
955
|
+
};
|
|
1099
956
|
_testHelperChai.assert.equal(mobiusSocket.getConnectedWebSocketUrl(), 'ws://connected-url.com');
|
|
1100
957
|
});
|
|
1101
|
-
it('returns undefined when
|
|
1102
|
-
mobiusSocket.
|
|
958
|
+
it('returns undefined when not connected', function () {
|
|
959
|
+
mobiusSocket.socket = {
|
|
1103
960
|
connected: false,
|
|
1104
961
|
url: 'ws://disconnected-url.com'
|
|
1105
|
-
}
|
|
962
|
+
};
|
|
1106
963
|
_testHelperChai.assert.isUndefined(mobiusSocket.getConnectedWebSocketUrl());
|
|
1107
964
|
});
|
|
1108
965
|
});
|
|
@@ -1116,96 +973,20 @@ describe('plugin-mobius-socket', function () {
|
|
|
1116
973
|
throw error;
|
|
1117
974
|
});
|
|
1118
975
|
_sinon.default.stub(mobiusSocket.logger, 'error');
|
|
1119
|
-
return _promise.default.resolve(mobiusSocket.
|
|
1120
|
-
_testHelperChai.assert.calledWith(mobiusSocket.logger.error, 'MobiusSocket: error occurred in event handler:', error, ' with args: ', [
|
|
976
|
+
return _promise.default.resolve(mobiusSocket.emitEvent('break', event)).then(function (res) {
|
|
977
|
+
_testHelperChai.assert.calledWith(mobiusSocket.logger.error, 'MobiusSocket: error occurred in event handler:', error, ' with args: ', ['break', event]);
|
|
1121
978
|
return res;
|
|
1122
979
|
});
|
|
1123
980
|
});
|
|
1124
981
|
});
|
|
1125
|
-
describe('#_applyOverrides()', function () {
|
|
1126
|
-
var lastSeenActivityDate = 'Some date';
|
|
1127
|
-
var lastReadableActivityDate = 'Some other date';
|
|
1128
|
-
it('merges a single header field with data', function () {
|
|
1129
|
-
var envelope = {
|
|
1130
|
-
headers: {
|
|
1131
|
-
'data.activity.target.lastSeenActivityDate': lastSeenActivityDate
|
|
1132
|
-
},
|
|
1133
|
-
data: {
|
|
1134
|
-
activity: {}
|
|
1135
|
-
}
|
|
1136
|
-
};
|
|
1137
|
-
mobiusSocket._applyOverrides(envelope);
|
|
1138
|
-
_testHelperChai.assert.equal(envelope.data.activity.target.lastSeenActivityDate, lastSeenActivityDate);
|
|
1139
|
-
});
|
|
1140
|
-
it('merges a multiple header fields with data', function () {
|
|
1141
|
-
var envelope = {
|
|
1142
|
-
headers: {
|
|
1143
|
-
'data.activity.target.lastSeenActivityDate': lastSeenActivityDate,
|
|
1144
|
-
'data.activity.target.lastReadableActivityDate': lastReadableActivityDate
|
|
1145
|
-
},
|
|
1146
|
-
data: {
|
|
1147
|
-
activity: {}
|
|
1148
|
-
}
|
|
1149
|
-
};
|
|
1150
|
-
mobiusSocket._applyOverrides(envelope);
|
|
1151
|
-
_testHelperChai.assert.equal(envelope.data.activity.target.lastSeenActivityDate, lastSeenActivityDate);
|
|
1152
|
-
_testHelperChai.assert.equal(envelope.data.activity.target.lastReadableActivityDate, lastReadableActivityDate);
|
|
1153
|
-
});
|
|
1154
|
-
it('merges headers when MobiusSocket messages arrive', function () {
|
|
1155
|
-
var envelope = {
|
|
1156
|
-
headers: {
|
|
1157
|
-
'data.activity.target.lastSeenActivityDate': lastSeenActivityDate
|
|
1158
|
-
},
|
|
1159
|
-
data: {
|
|
1160
|
-
activity: {}
|
|
1161
|
-
}
|
|
1162
|
-
};
|
|
1163
|
-
mobiusSocket._applyOverrides(envelope);
|
|
1164
|
-
_testHelperChai.assert.equal(envelope.data.activity.target.lastSeenActivityDate, lastSeenActivityDate);
|
|
1165
|
-
});
|
|
1166
|
-
});
|
|
1167
|
-
describe('#_setTimeOffset', function () {
|
|
1168
|
-
it('sets mercuryTimeOffset based on the difference between wsWriteTimestamp and now', function () {
|
|
1169
|
-
var event = {
|
|
1170
|
-
data: {
|
|
1171
|
-
wsWriteTimestamp: (0, _now.default)() - 60000
|
|
1172
|
-
}
|
|
1173
|
-
};
|
|
1174
|
-
_testHelperChai.assert.isUndefined(mobiusSocket.mercuryTimeOffset);
|
|
1175
|
-
mobiusSocket._setTimeOffset('mobius-websocket-session', event);
|
|
1176
|
-
_testHelperChai.assert.isDefined(mobiusSocket.mercuryTimeOffset);
|
|
1177
|
-
_testHelperChai.assert.isTrue(mobiusSocket.mercuryTimeOffset > 0);
|
|
1178
|
-
});
|
|
1179
|
-
it('handles negative offsets', function () {
|
|
1180
|
-
var event = {
|
|
1181
|
-
data: {
|
|
1182
|
-
wsWriteTimestamp: (0, _now.default)() + 60000
|
|
1183
|
-
}
|
|
1184
|
-
};
|
|
1185
|
-
mobiusSocket._setTimeOffset('mobius-websocket-session', event);
|
|
1186
|
-
_testHelperChai.assert.isTrue(mobiusSocket.mercuryTimeOffset < 0);
|
|
1187
|
-
});
|
|
1188
|
-
it('handles invalid wsWriteTimestamp', function () {
|
|
1189
|
-
var invalidTimestamps = [null, -1, 'invalid', undefined];
|
|
1190
|
-
invalidTimestamps.forEach(function (invalidTimestamp) {
|
|
1191
|
-
var event = {
|
|
1192
|
-
data: {
|
|
1193
|
-
wsWriteTimestamp: invalidTimestamp
|
|
1194
|
-
}
|
|
1195
|
-
};
|
|
1196
|
-
mobiusSocket._setTimeOffset('mobius-websocket-session', event);
|
|
1197
|
-
_testHelperChai.assert.isUndefined(mobiusSocket.mercuryTimeOffset);
|
|
1198
|
-
});
|
|
1199
|
-
});
|
|
1200
|
-
});
|
|
1201
982
|
describe('#_prepareUrl()', function () {
|
|
1202
983
|
it('returns the provided URL as-is (no Mercury URL transforms)', function () {
|
|
1203
|
-
return mobiusSocket.
|
|
984
|
+
return mobiusSocket.prepareUrl('ws://provided.com').then(function (wsUrl) {
|
|
1204
985
|
_testHelperChai.assert.equal(wsUrl, 'ws://provided.com');
|
|
1205
986
|
});
|
|
1206
987
|
});
|
|
1207
988
|
it('falls back to device webSocketUrl when no URL is provided', function () {
|
|
1208
|
-
return mobiusSocket.
|
|
989
|
+
return mobiusSocket.prepareUrl().then(function (wsUrl) {
|
|
1209
990
|
_testHelperChai.assert.equal(wsUrl, 'ws://example.com');
|
|
1210
991
|
});
|
|
1211
992
|
});
|
|
@@ -1213,78 +994,66 @@ describe('plugin-mobius-socket', function () {
|
|
|
1213
994
|
describe('shutdown protocol', function () {
|
|
1214
995
|
describe('#_handleImminentShutdown()', function () {
|
|
1215
996
|
var connectWithBackoffStub;
|
|
1216
|
-
var sessionId = 'mobius-websocket-session';
|
|
1217
997
|
beforeEach(function () {
|
|
1218
998
|
mobiusSocket.connected = true;
|
|
1219
|
-
mobiusSocket.
|
|
999
|
+
mobiusSocket.socket = {
|
|
1220
1000
|
url: 'ws://old-socket.com',
|
|
1221
1001
|
removeAllListeners: _sinon.default.stub()
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
connectWithBackoffStub = _sinon.default.stub(mobiusSocket, '_connectWithBackoff');
|
|
1002
|
+
};
|
|
1003
|
+
connectWithBackoffStub = _sinon.default.stub(mobiusSocket, 'connectWithBackoff');
|
|
1225
1004
|
connectWithBackoffStub.returns(_promise.default.resolve());
|
|
1226
|
-
_sinon.default.stub(mobiusSocket, '
|
|
1005
|
+
_sinon.default.stub(mobiusSocket, 'emitEvent');
|
|
1227
1006
|
});
|
|
1228
1007
|
afterEach(function () {
|
|
1229
1008
|
connectWithBackoffStub.restore();
|
|
1230
|
-
mobiusSocket.
|
|
1231
|
-
mobiusSocket.sockets.clear();
|
|
1009
|
+
mobiusSocket.emitEvent.restore();
|
|
1232
1010
|
});
|
|
1233
1011
|
it('should be idempotent - no-op if already in progress', function () {
|
|
1234
|
-
|
|
1235
|
-
mobiusSocket._shutdownSwitchoverBackoffCalls.set(sessionId, {
|
|
1012
|
+
mobiusSocket.shutdownSwitchoverBackoffCall = {
|
|
1236
1013
|
placeholder: true
|
|
1237
|
-
}
|
|
1238
|
-
mobiusSocket.
|
|
1014
|
+
};
|
|
1015
|
+
mobiusSocket.handleImminentShutdown();
|
|
1239
1016
|
_testHelperChai.assert.notCalled(connectWithBackoffStub);
|
|
1240
1017
|
});
|
|
1241
1018
|
it('should set switchover flags when called', function () {
|
|
1242
|
-
mobiusSocket.
|
|
1019
|
+
mobiusSocket.handleImminentShutdown();
|
|
1243
1020
|
_testHelperChai.assert.calledOnce(connectWithBackoffStub);
|
|
1244
1021
|
var callArgs = connectWithBackoffStub.firstCall.args;
|
|
1245
1022
|
_testHelperChai.assert.isUndefined(callArgs[0]); // webSocketUrl
|
|
1246
|
-
_testHelperChai.assert.
|
|
1247
|
-
_testHelperChai.assert.
|
|
1248
|
-
_testHelperChai.assert.
|
|
1249
|
-
_testHelperChai.assert.
|
|
1250
|
-
_testHelperChai.assert.isTrue(callArgs[2].attemptOptions.isShutdownSwitchover);
|
|
1023
|
+
_testHelperChai.assert.isObject(callArgs[1]); // context
|
|
1024
|
+
_testHelperChai.assert.isTrue(callArgs[1].isShutdownSwitchover);
|
|
1025
|
+
_testHelperChai.assert.isObject(callArgs[1].attemptOptions);
|
|
1026
|
+
_testHelperChai.assert.isTrue(callArgs[1].attemptOptions.isShutdownSwitchover);
|
|
1251
1027
|
});
|
|
1252
1028
|
it('should call _connectWithBackoff with correct parameters', function (done) {
|
|
1253
|
-
mobiusSocket.
|
|
1029
|
+
mobiusSocket.handleImminentShutdown();
|
|
1254
1030
|
process.nextTick(function () {
|
|
1255
1031
|
_testHelperChai.assert.calledOnce(connectWithBackoffStub);
|
|
1256
1032
|
var callArgs = connectWithBackoffStub.firstCall.args;
|
|
1257
1033
|
_testHelperChai.assert.isUndefined(callArgs[0]); // webSocketUrl
|
|
1258
|
-
_testHelperChai.assert.
|
|
1259
|
-
_testHelperChai.assert.
|
|
1260
|
-
_testHelperChai.assert.
|
|
1261
|
-
_testHelperChai.assert.
|
|
1262
|
-
_testHelperChai.assert.isTrue(callArgs[2].attemptOptions.isShutdownSwitchover);
|
|
1034
|
+
_testHelperChai.assert.isObject(callArgs[1]); // context
|
|
1035
|
+
_testHelperChai.assert.isTrue(callArgs[1].isShutdownSwitchover);
|
|
1036
|
+
_testHelperChai.assert.isObject(callArgs[1].attemptOptions);
|
|
1037
|
+
_testHelperChai.assert.isTrue(callArgs[1].attemptOptions.isShutdownSwitchover);
|
|
1263
1038
|
done();
|
|
1264
1039
|
});
|
|
1265
1040
|
});
|
|
1266
1041
|
it('should handle exceptions during switchover', function () {
|
|
1267
1042
|
connectWithBackoffStub.restore();
|
|
1268
|
-
_sinon.default.stub(mobiusSocket, '
|
|
1269
|
-
mobiusSocket.
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
// should be removed from the map.
|
|
1273
|
-
var switchoverCall = mobiusSocket._shutdownSwitchoverBackoffCalls.get(sessionId);
|
|
1274
|
-
_testHelperChai.assert.isUndefined(switchoverCall);
|
|
1275
|
-
mobiusSocket._connectWithBackoff.restore();
|
|
1043
|
+
_sinon.default.stub(mobiusSocket, 'connectWithBackoff').throws(new Error('Connection failed'));
|
|
1044
|
+
mobiusSocket.handleImminentShutdown();
|
|
1045
|
+
_testHelperChai.assert.isUndefined(mobiusSocket.shutdownSwitchoverBackoffCall);
|
|
1046
|
+
mobiusSocket.connectWithBackoff.restore();
|
|
1276
1047
|
});
|
|
1277
1048
|
});
|
|
1278
1049
|
describe('#_onmessage() with shutdown message', function () {
|
|
1279
1050
|
beforeEach(function () {
|
|
1280
|
-
_sinon.default.stub(mobiusSocket, '
|
|
1281
|
-
_sinon.default.stub(mobiusSocket, '
|
|
1282
|
-
_sinon.default.stub(mobiusSocket, '_setTimeOffset');
|
|
1051
|
+
_sinon.default.stub(mobiusSocket, 'handleImminentShutdown');
|
|
1052
|
+
_sinon.default.stub(mobiusSocket, 'emitEvent');
|
|
1283
1053
|
});
|
|
1284
1054
|
afterEach(function () {
|
|
1285
|
-
mobiusSocket.
|
|
1286
|
-
mobiusSocket.
|
|
1287
|
-
mobiusSocket._setTimeOffset.restore();
|
|
1055
|
+
mobiusSocket.handleImminentShutdown.restore();
|
|
1056
|
+
mobiusSocket.emitEvent.restore();
|
|
1288
1057
|
});
|
|
1289
1058
|
it('should trigger _handleImminentShutdown on shutdown message', function () {
|
|
1290
1059
|
var shutdownEvent = {
|
|
@@ -1292,9 +1061,9 @@ describe('plugin-mobius-socket', function () {
|
|
|
1292
1061
|
type: 'shutdown'
|
|
1293
1062
|
}
|
|
1294
1063
|
};
|
|
1295
|
-
var result = mobiusSocket.
|
|
1296
|
-
_testHelperChai.assert.calledOnce(mobiusSocket.
|
|
1297
|
-
_testHelperChai.assert.calledWith(mobiusSocket.
|
|
1064
|
+
var result = mobiusSocket.onmessage(shutdownEvent);
|
|
1065
|
+
_testHelperChai.assert.calledOnce(mobiusSocket.handleImminentShutdown);
|
|
1066
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'event:mobius_shutdown_imminent', shutdownEvent.data);
|
|
1298
1067
|
_testHelperChai.assert.instanceOf(result, _promise.default);
|
|
1299
1068
|
});
|
|
1300
1069
|
it('should handle shutdown message without additional data gracefully', function () {
|
|
@@ -1303,8 +1072,8 @@ describe('plugin-mobius-socket', function () {
|
|
|
1303
1072
|
type: 'shutdown'
|
|
1304
1073
|
}
|
|
1305
1074
|
};
|
|
1306
|
-
mobiusSocket.
|
|
1307
|
-
_testHelperChai.assert.calledOnce(mobiusSocket.
|
|
1075
|
+
mobiusSocket.onmessage(shutdownEvent);
|
|
1076
|
+
_testHelperChai.assert.calledOnce(mobiusSocket.handleImminentShutdown);
|
|
1308
1077
|
});
|
|
1309
1078
|
it('should not trigger shutdown handling for non-shutdown messages', function () {
|
|
1310
1079
|
var regularEvent = {
|
|
@@ -1315,20 +1084,16 @@ describe('plugin-mobius-socket', function () {
|
|
|
1315
1084
|
}
|
|
1316
1085
|
}
|
|
1317
1086
|
};
|
|
1318
|
-
mobiusSocket.
|
|
1319
|
-
_testHelperChai.assert.notCalled(mobiusSocket.
|
|
1087
|
+
mobiusSocket.onmessage(regularEvent);
|
|
1088
|
+
_testHelperChai.assert.notCalled(mobiusSocket.handleImminentShutdown);
|
|
1320
1089
|
});
|
|
1321
1090
|
});
|
|
1322
1091
|
describe('#_onmessage() with missing data or eventType', function () {
|
|
1323
1092
|
beforeEach(function () {
|
|
1324
|
-
_sinon.default.stub(mobiusSocket, '
|
|
1325
|
-
_sinon.default.stub(mobiusSocket, '_setTimeOffset');
|
|
1326
|
-
_sinon.default.stub(mobiusSocket, '_applyOverrides');
|
|
1093
|
+
_sinon.default.stub(mobiusSocket, 'emitEvent');
|
|
1327
1094
|
});
|
|
1328
1095
|
afterEach(function () {
|
|
1329
|
-
mobiusSocket.
|
|
1330
|
-
mobiusSocket._setTimeOffset.restore();
|
|
1331
|
-
mobiusSocket._applyOverrides.restore();
|
|
1096
|
+
mobiusSocket.emitEvent.restore();
|
|
1332
1097
|
});
|
|
1333
1098
|
it('should not throw when envelope.data is undefined', function () {
|
|
1334
1099
|
var event = {
|
|
@@ -1337,9 +1102,9 @@ describe('plugin-mobius-socket', function () {
|
|
|
1337
1102
|
// no nested data property
|
|
1338
1103
|
}
|
|
1339
1104
|
};
|
|
1340
|
-
var result = mobiusSocket.
|
|
1105
|
+
var result = mobiusSocket.onmessage(event);
|
|
1341
1106
|
_testHelperChai.assert.instanceOf(result, _promise.default);
|
|
1342
|
-
_testHelperChai.assert.calledWith(mobiusSocket.
|
|
1107
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'event', event.data);
|
|
1343
1108
|
});
|
|
1344
1109
|
it('should not throw when data.eventType is undefined', function () {
|
|
1345
1110
|
var event = {
|
|
@@ -1351,9 +1116,9 @@ describe('plugin-mobius-socket', function () {
|
|
|
1351
1116
|
}
|
|
1352
1117
|
}
|
|
1353
1118
|
};
|
|
1354
|
-
var result = mobiusSocket.
|
|
1119
|
+
var result = mobiusSocket.onmessage(event);
|
|
1355
1120
|
_testHelperChai.assert.instanceOf(result, _promise.default);
|
|
1356
|
-
_testHelperChai.assert.calledWith(mobiusSocket.
|
|
1121
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'event', event.data);
|
|
1357
1122
|
});
|
|
1358
1123
|
it('should emit generic event for messages without eventType (e.g. subscription responses)', function () {
|
|
1359
1124
|
var event = {
|
|
@@ -1365,15 +1130,15 @@ describe('plugin-mobius-socket', function () {
|
|
|
1365
1130
|
}
|
|
1366
1131
|
}
|
|
1367
1132
|
};
|
|
1368
|
-
var result = mobiusSocket.
|
|
1133
|
+
var result = mobiusSocket.onmessage(event);
|
|
1369
1134
|
_testHelperChai.assert.instanceOf(result, _promise.default);
|
|
1370
|
-
_testHelperChai.assert.calledOnce(mobiusSocket.
|
|
1371
|
-
_testHelperChai.assert.calledWith(mobiusSocket.
|
|
1135
|
+
_testHelperChai.assert.calledOnce(mobiusSocket.emitEvent);
|
|
1136
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'event', event.data);
|
|
1372
1137
|
});
|
|
1373
|
-
it('should still process messages with a valid eventType', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1138
|
+
it('should still process messages with a valid eventType', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee0() {
|
|
1374
1139
|
var event;
|
|
1375
|
-
return _regenerator.default.wrap(function (
|
|
1376
|
-
while (1) switch (
|
|
1140
|
+
return _regenerator.default.wrap(function (_context0) {
|
|
1141
|
+
while (1) switch (_context0.prev = _context0.next) {
|
|
1377
1142
|
case 0:
|
|
1378
1143
|
event = {
|
|
1379
1144
|
data: {
|
|
@@ -1382,18 +1147,16 @@ describe('plugin-mobius-socket', function () {
|
|
|
1382
1147
|
}
|
|
1383
1148
|
}
|
|
1384
1149
|
};
|
|
1385
|
-
|
|
1386
|
-
return mobiusSocket.
|
|
1150
|
+
_context0.next = 1;
|
|
1151
|
+
return mobiusSocket.onmessage(event);
|
|
1387
1152
|
case 1:
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
_testHelperChai.assert.calledWith(mobiusSocket._emit, mobiusSocket.defaultSessionId, 'event:conversation', event.data);
|
|
1391
|
-
_testHelperChai.assert.calledWith(mobiusSocket._emit, mobiusSocket.defaultSessionId, 'event:conversation.activity', event.data);
|
|
1153
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'event:conversation', event.data);
|
|
1154
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'event:conversation.activity', event.data);
|
|
1392
1155
|
case 2:
|
|
1393
1156
|
case "end":
|
|
1394
|
-
return
|
|
1157
|
+
return _context0.stop();
|
|
1395
1158
|
}
|
|
1396
|
-
},
|
|
1159
|
+
}, _callee0);
|
|
1397
1160
|
})));
|
|
1398
1161
|
});
|
|
1399
1162
|
describe('#_onmessage() async_event deduplication', function () {
|
|
@@ -1404,19 +1167,41 @@ describe('plugin-mobius-socket', function () {
|
|
|
1404
1167
|
afterEach(function () {
|
|
1405
1168
|
mobiusSocket.config.dedupCacheMaxSize = originalDedupCacheMaxSize;
|
|
1406
1169
|
});
|
|
1407
|
-
it('suppresses duplicate async_event messages
|
|
1170
|
+
it('suppresses duplicate async_event messages', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee1() {
|
|
1171
|
+
var emitSpy;
|
|
1172
|
+
return _regenerator.default.wrap(function (_context1) {
|
|
1173
|
+
while (1) switch (_context1.prev = _context1.next) {
|
|
1174
|
+
case 0:
|
|
1175
|
+
emitSpy = _sinon.default.spy(mobiusSocket, 'emitEvent');
|
|
1176
|
+
_context1.next = 1;
|
|
1177
|
+
return mobiusSocket.onmessage(createAsyncEvent('evt-1'));
|
|
1178
|
+
case 1:
|
|
1179
|
+
_context1.next = 2;
|
|
1180
|
+
return mobiusSocket.onmessage(createAsyncEvent('evt-1'));
|
|
1181
|
+
case 2:
|
|
1182
|
+
_testHelperChai.assert.equal(countGenericEventEmits(emitSpy), 1);
|
|
1183
|
+
emitSpy.restore();
|
|
1184
|
+
case 3:
|
|
1185
|
+
case "end":
|
|
1186
|
+
return _context1.stop();
|
|
1187
|
+
}
|
|
1188
|
+
}, _callee1);
|
|
1189
|
+
})));
|
|
1190
|
+
it('suppresses duplicate async_event messages across socket replacement without disconnect', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee10() {
|
|
1408
1191
|
var emitSpy;
|
|
1409
1192
|
return _regenerator.default.wrap(function (_context10) {
|
|
1410
1193
|
while (1) switch (_context10.prev = _context10.next) {
|
|
1411
1194
|
case 0:
|
|
1412
|
-
emitSpy = _sinon.default.spy(mobiusSocket, '
|
|
1195
|
+
emitSpy = _sinon.default.spy(mobiusSocket, 'emitEvent');
|
|
1196
|
+
mobiusSocket.socket = createSessionSocket();
|
|
1413
1197
|
_context10.next = 1;
|
|
1414
|
-
return mobiusSocket.
|
|
1198
|
+
return mobiusSocket.onmessage(createAsyncEvent('evt-2'));
|
|
1415
1199
|
case 1:
|
|
1200
|
+
mobiusSocket.socket = createSessionSocket();
|
|
1416
1201
|
_context10.next = 2;
|
|
1417
|
-
return mobiusSocket.
|
|
1202
|
+
return mobiusSocket.onmessage(createAsyncEvent('evt-2'));
|
|
1418
1203
|
case 2:
|
|
1419
|
-
_testHelperChai.assert.equal(countGenericEventEmits(emitSpy
|
|
1204
|
+
_testHelperChai.assert.equal(countGenericEventEmits(emitSpy), 1);
|
|
1420
1205
|
emitSpy.restore();
|
|
1421
1206
|
case 3:
|
|
1422
1207
|
case "end":
|
|
@@ -1424,105 +1209,63 @@ describe('plugin-mobius-socket', function () {
|
|
|
1424
1209
|
}
|
|
1425
1210
|
}, _callee10);
|
|
1426
1211
|
})));
|
|
1427
|
-
it('
|
|
1428
|
-
var
|
|
1212
|
+
it('evicts only the oldest eventId when the dedup cache exceeds max size', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee11() {
|
|
1213
|
+
var emitSpy;
|
|
1429
1214
|
return _regenerator.default.wrap(function (_context11) {
|
|
1430
1215
|
while (1) switch (_context11.prev = _context11.next) {
|
|
1431
1216
|
case 0:
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
mobiusSocket.sockets.set(sessionId, createSessionSocket());
|
|
1217
|
+
emitSpy = _sinon.default.spy(mobiusSocket, 'emitEvent');
|
|
1218
|
+
mobiusSocket.config.dedupCacheMaxSize = 3;
|
|
1435
1219
|
_context11.next = 1;
|
|
1436
|
-
return mobiusSocket.
|
|
1220
|
+
return mobiusSocket.onmessage(createAsyncEvent('e1'));
|
|
1437
1221
|
case 1:
|
|
1438
|
-
mobiusSocket.sockets.set(sessionId, createSessionSocket());
|
|
1439
1222
|
_context11.next = 2;
|
|
1440
|
-
return mobiusSocket.
|
|
1223
|
+
return mobiusSocket.onmessage(createAsyncEvent('e2'));
|
|
1441
1224
|
case 2:
|
|
1442
|
-
|
|
1443
|
-
|
|
1225
|
+
_context11.next = 3;
|
|
1226
|
+
return mobiusSocket.onmessage(createAsyncEvent('e3'));
|
|
1444
1227
|
case 3:
|
|
1228
|
+
_context11.next = 4;
|
|
1229
|
+
return mobiusSocket.onmessage(createAsyncEvent('e4'));
|
|
1230
|
+
case 4:
|
|
1231
|
+
_context11.next = 5;
|
|
1232
|
+
return mobiusSocket.onmessage(createAsyncEvent('e2'));
|
|
1233
|
+
case 5:
|
|
1234
|
+
_context11.next = 6;
|
|
1235
|
+
return mobiusSocket.onmessage(createAsyncEvent('e1'));
|
|
1236
|
+
case 6:
|
|
1237
|
+
_testHelperChai.assert.equal(countGenericEventEmits(emitSpy), 5);
|
|
1238
|
+
emitSpy.restore();
|
|
1239
|
+
case 7:
|
|
1445
1240
|
case "end":
|
|
1446
1241
|
return _context11.stop();
|
|
1447
1242
|
}
|
|
1448
1243
|
}, _callee11);
|
|
1449
1244
|
})));
|
|
1450
|
-
it('
|
|
1245
|
+
it('clears the dedup cache on disconnect', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee12() {
|
|
1451
1246
|
var emitSpy;
|
|
1452
1247
|
return _regenerator.default.wrap(function (_context12) {
|
|
1453
1248
|
while (1) switch (_context12.prev = _context12.next) {
|
|
1454
1249
|
case 0:
|
|
1455
|
-
emitSpy = _sinon.default.spy(mobiusSocket, '
|
|
1456
|
-
mobiusSocket.config.dedupCacheMaxSize = 3;
|
|
1250
|
+
emitSpy = _sinon.default.spy(mobiusSocket, 'emitEvent');
|
|
1457
1251
|
_context12.next = 1;
|
|
1458
|
-
return mobiusSocket.
|
|
1252
|
+
return mobiusSocket.onmessage(createAsyncEvent('evt-3'));
|
|
1459
1253
|
case 1:
|
|
1254
|
+
mobiusSocket.socket = createSessionSocket();
|
|
1460
1255
|
_context12.next = 2;
|
|
1461
|
-
return mobiusSocket.
|
|
1256
|
+
return mobiusSocket.disconnect();
|
|
1462
1257
|
case 2:
|
|
1463
1258
|
_context12.next = 3;
|
|
1464
|
-
return mobiusSocket.
|
|
1259
|
+
return mobiusSocket.onmessage(createAsyncEvent('evt-3'));
|
|
1465
1260
|
case 3:
|
|
1466
|
-
|
|
1467
|
-
return mobiusSocket._onmessage('session-a', createAsyncEvent('e4'));
|
|
1468
|
-
case 4:
|
|
1469
|
-
_context12.next = 5;
|
|
1470
|
-
return mobiusSocket._onmessage('session-a', createAsyncEvent('e2'));
|
|
1471
|
-
case 5:
|
|
1472
|
-
_context12.next = 6;
|
|
1473
|
-
return mobiusSocket._onmessage('session-a', createAsyncEvent('e1'));
|
|
1474
|
-
case 6:
|
|
1475
|
-
_testHelperChai.assert.equal(countGenericEventEmits(emitSpy, 'session-a'), 5);
|
|
1261
|
+
_testHelperChai.assert.equal(countGenericEventEmits(emitSpy), 2);
|
|
1476
1262
|
emitSpy.restore();
|
|
1477
|
-
case
|
|
1263
|
+
case 4:
|
|
1478
1264
|
case "end":
|
|
1479
1265
|
return _context12.stop();
|
|
1480
1266
|
}
|
|
1481
1267
|
}, _callee12);
|
|
1482
1268
|
})));
|
|
1483
|
-
it('clears the session dedup cache on disconnect', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee13() {
|
|
1484
|
-
var sessionId, emitSpy;
|
|
1485
|
-
return _regenerator.default.wrap(function (_context13) {
|
|
1486
|
-
while (1) switch (_context13.prev = _context13.next) {
|
|
1487
|
-
case 0:
|
|
1488
|
-
sessionId = 'session-a';
|
|
1489
|
-
emitSpy = _sinon.default.spy(mobiusSocket, '_emit');
|
|
1490
|
-
_context13.next = 1;
|
|
1491
|
-
return mobiusSocket._onmessage(sessionId, createAsyncEvent('evt-3'));
|
|
1492
|
-
case 1:
|
|
1493
|
-
mobiusSocket.sockets.set(sessionId, createSessionSocket());
|
|
1494
|
-
_context13.next = 2;
|
|
1495
|
-
return mobiusSocket.disconnect(undefined, sessionId);
|
|
1496
|
-
case 2:
|
|
1497
|
-
_context13.next = 3;
|
|
1498
|
-
return mobiusSocket._onmessage(sessionId, createAsyncEvent('evt-3'));
|
|
1499
|
-
case 3:
|
|
1500
|
-
_testHelperChai.assert.equal(countGenericEventEmits(emitSpy, sessionId), 2);
|
|
1501
|
-
emitSpy.restore();
|
|
1502
|
-
case 4:
|
|
1503
|
-
case "end":
|
|
1504
|
-
return _context13.stop();
|
|
1505
|
-
}
|
|
1506
|
-
}, _callee13);
|
|
1507
|
-
})));
|
|
1508
|
-
});
|
|
1509
|
-
describe('#_getEventHandlers()', function () {
|
|
1510
|
-
it('should return an empty array when eventType is undefined', function () {
|
|
1511
|
-
var result = mobiusSocket._getEventHandlers(undefined);
|
|
1512
|
-
_testHelperChai.assert.deepEqual(result, []);
|
|
1513
|
-
});
|
|
1514
|
-
it('should return an empty array when eventType is null', function () {
|
|
1515
|
-
var result = mobiusSocket._getEventHandlers(null);
|
|
1516
|
-
_testHelperChai.assert.deepEqual(result, []);
|
|
1517
|
-
});
|
|
1518
|
-
it('should return an empty array when eventType is an empty string', function () {
|
|
1519
|
-
var result = mobiusSocket._getEventHandlers('');
|
|
1520
|
-
_testHelperChai.assert.deepEqual(result, []);
|
|
1521
|
-
});
|
|
1522
|
-
it('should return an empty array when namespace is not registered', function () {
|
|
1523
|
-
var result = mobiusSocket._getEventHandlers('unknownNamespace.someEvent');
|
|
1524
|
-
_testHelperChai.assert.deepEqual(result, []);
|
|
1525
|
-
});
|
|
1526
1269
|
});
|
|
1527
1270
|
describe('#_onclose() with code 4001 (shutdown replacement)', function () {
|
|
1528
1271
|
var mockSocket;
|
|
@@ -1537,23 +1280,22 @@ describe('plugin-mobius-socket', function () {
|
|
|
1537
1280
|
removeAllListeners: _sinon.default.stub()
|
|
1538
1281
|
};
|
|
1539
1282
|
mobiusSocket.socket = mockSocket;
|
|
1540
|
-
mobiusSocket.sockets.set(mobiusSocket.defaultSessionId, mockSocket);
|
|
1541
1283
|
mobiusSocket.connected = true;
|
|
1542
|
-
_sinon.default.stub(mobiusSocket, '
|
|
1543
|
-
_sinon.default.stub(mobiusSocket, '
|
|
1284
|
+
_sinon.default.stub(mobiusSocket, 'emitEvent');
|
|
1285
|
+
_sinon.default.stub(mobiusSocket, 'reconnect');
|
|
1544
1286
|
});
|
|
1545
1287
|
afterEach(function () {
|
|
1546
|
-
mobiusSocket.
|
|
1547
|
-
mobiusSocket.
|
|
1288
|
+
mobiusSocket.emitEvent.restore();
|
|
1289
|
+
mobiusSocket.reconnect.restore();
|
|
1548
1290
|
});
|
|
1549
1291
|
it('should handle active socket close with 4001 - permanent failure', function () {
|
|
1550
1292
|
var closeEvent = {
|
|
1551
1293
|
code: 4001,
|
|
1552
1294
|
reason: 'replaced during shutdown'
|
|
1553
1295
|
};
|
|
1554
|
-
mobiusSocket.
|
|
1555
|
-
_testHelperChai.assert.calledWith(mobiusSocket.
|
|
1556
|
-
_testHelperChai.assert.notCalled(mobiusSocket.
|
|
1296
|
+
mobiusSocket.onclose(closeEvent, mockSocket);
|
|
1297
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'offline.permanent', closeEvent);
|
|
1298
|
+
_testHelperChai.assert.notCalled(mobiusSocket.reconnect);
|
|
1557
1299
|
_testHelperChai.assert.isFalse(mobiusSocket.connected);
|
|
1558
1300
|
});
|
|
1559
1301
|
it('should handle non-active socket close with 4001 - no reconnect needed', function () {
|
|
@@ -1561,10 +1303,10 @@ describe('plugin-mobius-socket', function () {
|
|
|
1561
1303
|
code: 4001,
|
|
1562
1304
|
reason: 'replaced during shutdown'
|
|
1563
1305
|
};
|
|
1564
|
-
mobiusSocket.
|
|
1565
|
-
_testHelperChai.assert.calledWith(mobiusSocket.
|
|
1566
|
-
_testHelperChai.assert.notCalled(mobiusSocket.
|
|
1567
|
-
_testHelperChai.assert.isTrue(mobiusSocket.connected);
|
|
1306
|
+
mobiusSocket.onclose(closeEvent, anotherSocket);
|
|
1307
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'offline.replaced', closeEvent);
|
|
1308
|
+
_testHelperChai.assert.notCalled(mobiusSocket.reconnect);
|
|
1309
|
+
_testHelperChai.assert.isTrue(mobiusSocket.connected);
|
|
1568
1310
|
_testHelperChai.assert.strictEqual(mobiusSocket.socket, mockSocket);
|
|
1569
1311
|
});
|
|
1570
1312
|
it('should distinguish between active and non-active socket closes', function () {
|
|
@@ -1574,40 +1316,31 @@ describe('plugin-mobius-socket', function () {
|
|
|
1574
1316
|
};
|
|
1575
1317
|
|
|
1576
1318
|
// Test non-active socket
|
|
1577
|
-
mobiusSocket.
|
|
1578
|
-
_testHelperChai.assert.calledWith(mobiusSocket.
|
|
1319
|
+
mobiusSocket.onclose(closeEvent, anotherSocket);
|
|
1320
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'offline.replaced', closeEvent);
|
|
1579
1321
|
|
|
1580
1322
|
// Reset the spy call history
|
|
1581
|
-
mobiusSocket.
|
|
1323
|
+
mobiusSocket.emitEvent.resetHistory();
|
|
1582
1324
|
|
|
1583
1325
|
// Test active socket
|
|
1584
|
-
mobiusSocket.
|
|
1585
|
-
|
|
1586
|
-
_testHelperChai.assert.calledWith(mobiusSocket._emit, mobiusSocket.defaultSessionId, 'offline.permanent', closeEvent);
|
|
1326
|
+
mobiusSocket.onclose(closeEvent, mockSocket);
|
|
1327
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'offline.permanent', closeEvent);
|
|
1587
1328
|
});
|
|
1588
1329
|
it('should handle missing sourceSocket parameter (treats as non-active)', function () {
|
|
1589
1330
|
var closeEvent = {
|
|
1590
1331
|
code: 4001,
|
|
1591
1332
|
reason: 'replaced during shutdown'
|
|
1592
1333
|
};
|
|
1593
|
-
mobiusSocket.
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
_testHelperChai.assert.calledWith(mobiusSocket._emit, mobiusSocket.defaultSessionId, 'offline.replaced', closeEvent);
|
|
1597
|
-
_testHelperChai.assert.notCalled(mobiusSocket._reconnect);
|
|
1334
|
+
mobiusSocket.onclose(closeEvent, undefined);
|
|
1335
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'offline.replaced', closeEvent);
|
|
1336
|
+
_testHelperChai.assert.notCalled(mobiusSocket.reconnect);
|
|
1598
1337
|
});
|
|
1599
1338
|
it('should clean up event listeners from non-active socket when it closes', function () {
|
|
1600
1339
|
var closeEvent = {
|
|
1601
1340
|
code: 4001,
|
|
1602
1341
|
reason: 'replaced during shutdown'
|
|
1603
1342
|
};
|
|
1604
|
-
|
|
1605
|
-
// Close non-active socket (not the active one)
|
|
1606
|
-
mobiusSocket._onclose(mobiusSocket.defaultSessionId, closeEvent, anotherSocket);
|
|
1607
|
-
|
|
1608
|
-
// Verify listeners were removed from the old socket
|
|
1609
|
-
// The _onclose method checks if sourceSocket !== this.socket (non-active)
|
|
1610
|
-
// and then calls removeAllListeners in the else branch
|
|
1343
|
+
mobiusSocket.onclose(closeEvent, anotherSocket);
|
|
1611
1344
|
_testHelperChai.assert.calledOnce(anotherSocket.removeAllListeners);
|
|
1612
1345
|
});
|
|
1613
1346
|
it('should not clean up listeners from active socket listeners until close handler runs', function () {
|
|
@@ -1615,128 +1348,115 @@ describe('plugin-mobius-socket', function () {
|
|
|
1615
1348
|
code: 4001,
|
|
1616
1349
|
reason: 'replaced during shutdown'
|
|
1617
1350
|
};
|
|
1618
|
-
|
|
1619
|
-
// Close active socket
|
|
1620
|
-
mobiusSocket._onclose(mobiusSocket.defaultSessionId, closeEvent, mockSocket);
|
|
1621
|
-
|
|
1622
|
-
// Verify listeners were removed from active socket
|
|
1351
|
+
mobiusSocket.onclose(closeEvent, mockSocket);
|
|
1623
1352
|
_testHelperChai.assert.calledOnce(mockSocket.removeAllListeners);
|
|
1624
1353
|
});
|
|
1625
1354
|
});
|
|
1626
1355
|
describe('shutdown switchover with retry logic', function () {
|
|
1627
1356
|
var connectWithBackoffStub;
|
|
1628
|
-
var sessionId = 'mobius-websocket-session';
|
|
1629
1357
|
beforeEach(function () {
|
|
1630
1358
|
mobiusSocket.connected = true;
|
|
1631
|
-
mobiusSocket.
|
|
1359
|
+
mobiusSocket.socket = {
|
|
1632
1360
|
url: 'ws://old-socket.com',
|
|
1633
1361
|
removeAllListeners: _sinon.default.stub()
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
_sinon.default.stub(mobiusSocket, '_emit');
|
|
1362
|
+
};
|
|
1363
|
+
connectWithBackoffStub = _sinon.default.stub(mobiusSocket, 'connectWithBackoff');
|
|
1364
|
+
_sinon.default.stub(mobiusSocket, 'emitEvent');
|
|
1638
1365
|
});
|
|
1639
1366
|
afterEach(function () {
|
|
1640
1367
|
connectWithBackoffStub.restore();
|
|
1641
|
-
mobiusSocket.
|
|
1642
|
-
mobiusSocket.sockets.clear();
|
|
1368
|
+
mobiusSocket.emitEvent.restore();
|
|
1643
1369
|
});
|
|
1644
1370
|
it('should call _connectWithBackoff with shutdown switchover context', function (done) {
|
|
1645
1371
|
connectWithBackoffStub.returns(_promise.default.resolve());
|
|
1646
|
-
mobiusSocket.
|
|
1372
|
+
mobiusSocket.handleImminentShutdown();
|
|
1647
1373
|
process.nextTick(function () {
|
|
1648
1374
|
_testHelperChai.assert.calledOnce(connectWithBackoffStub);
|
|
1649
1375
|
var callArgs = connectWithBackoffStub.firstCall.args;
|
|
1650
1376
|
_testHelperChai.assert.isUndefined(callArgs[0]); // webSocketUrl
|
|
1651
|
-
_testHelperChai.assert.
|
|
1652
|
-
_testHelperChai.assert.
|
|
1653
|
-
_testHelperChai.assert.
|
|
1654
|
-
_testHelperChai.assert.
|
|
1655
|
-
_testHelperChai.assert.isTrue(callArgs[2].attemptOptions.isShutdownSwitchover);
|
|
1377
|
+
_testHelperChai.assert.isObject(callArgs[1]);
|
|
1378
|
+
_testHelperChai.assert.isTrue(callArgs[1].isShutdownSwitchover);
|
|
1379
|
+
_testHelperChai.assert.isObject(callArgs[1].attemptOptions);
|
|
1380
|
+
_testHelperChai.assert.isTrue(callArgs[1].attemptOptions.isShutdownSwitchover);
|
|
1656
1381
|
done();
|
|
1657
1382
|
});
|
|
1658
1383
|
});
|
|
1659
|
-
it('should set
|
|
1660
|
-
// With the new behavior, "in progress" is represented by the presence
|
|
1661
|
-
// of an entry in _shutdownSwitchoverBackoffCalls.
|
|
1662
|
-
// Since _connectWithBackoff is stubbed in this suite, simulate its side-effect
|
|
1663
|
-
// of seeding the backoff-call map entry.
|
|
1384
|
+
it('should set shutdownSwitchoverBackoffCall during switchover', function () {
|
|
1664
1385
|
connectWithBackoffStub.callsFake(function () {
|
|
1665
|
-
mobiusSocket.
|
|
1386
|
+
mobiusSocket.shutdownSwitchoverBackoffCall = {
|
|
1666
1387
|
placeholder: true
|
|
1667
|
-
}
|
|
1388
|
+
};
|
|
1668
1389
|
return new _promise.default(function () {}); // Never resolves
|
|
1669
1390
|
});
|
|
1670
|
-
mobiusSocket.
|
|
1671
|
-
|
|
1672
|
-
_testHelperChai.assert.isOk(switchoverBackoffCall);
|
|
1391
|
+
mobiusSocket.handleImminentShutdown();
|
|
1392
|
+
_testHelperChai.assert.isOk(mobiusSocket.shutdownSwitchoverBackoffCall);
|
|
1673
1393
|
});
|
|
1674
|
-
it('should emit success event when switchover completes', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1394
|
+
it('should emit success event when switchover completes', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee13() {
|
|
1675
1395
|
var emitCalls, hasCompleteEvent;
|
|
1676
|
-
return _regenerator.default.wrap(function (
|
|
1677
|
-
while (1) switch (
|
|
1396
|
+
return _regenerator.default.wrap(function (_context13) {
|
|
1397
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1678
1398
|
case 0:
|
|
1679
|
-
connectWithBackoffStub.callsFake(function (url,
|
|
1399
|
+
connectWithBackoffStub.callsFake(function (url, context) {
|
|
1680
1400
|
if (context && context.attemptOptions && context.attemptOptions.onSuccess) {
|
|
1681
|
-
var
|
|
1401
|
+
var newSocket = {
|
|
1682
1402
|
url: 'ws://new-socket.com'
|
|
1683
1403
|
};
|
|
1684
|
-
context.attemptOptions.onSuccess(
|
|
1404
|
+
context.attemptOptions.onSuccess(newSocket, 'ws://new-socket.com');
|
|
1685
1405
|
}
|
|
1686
1406
|
return _promise.default.resolve();
|
|
1687
1407
|
});
|
|
1688
|
-
mobiusSocket.
|
|
1689
|
-
|
|
1408
|
+
mobiusSocket.handleImminentShutdown();
|
|
1409
|
+
_context13.next = 1;
|
|
1690
1410
|
return (0, _promiseTick.default)(50);
|
|
1691
1411
|
case 1:
|
|
1692
|
-
emitCalls = mobiusSocket.
|
|
1412
|
+
emitCalls = mobiusSocket.emitEvent.getCalls();
|
|
1693
1413
|
hasCompleteEvent = emitCalls.some(function (call) {
|
|
1694
|
-
return call.args[0] ===
|
|
1414
|
+
return call.args[0] === 'event:mobius_shutdown_switchover_complete';
|
|
1695
1415
|
});
|
|
1696
1416
|
_testHelperChai.assert.isTrue(hasCompleteEvent, 'Should emit switchover complete event');
|
|
1697
1417
|
case 2:
|
|
1698
1418
|
case "end":
|
|
1699
|
-
return
|
|
1419
|
+
return _context13.stop();
|
|
1700
1420
|
}
|
|
1701
|
-
},
|
|
1421
|
+
}, _callee13);
|
|
1702
1422
|
})));
|
|
1703
|
-
it('should emit failure event when switchover exhausts retries', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1423
|
+
it('should emit failure event when switchover exhausts retries', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee14() {
|
|
1704
1424
|
var testError, emitCalls, hasFailureEvent;
|
|
1705
|
-
return _regenerator.default.wrap(function (
|
|
1706
|
-
while (1) switch (
|
|
1425
|
+
return _regenerator.default.wrap(function (_context14) {
|
|
1426
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1707
1427
|
case 0:
|
|
1708
1428
|
testError = new Error('Connection failed');
|
|
1709
1429
|
connectWithBackoffStub.returns(_promise.default.reject(testError));
|
|
1710
|
-
mobiusSocket.
|
|
1711
|
-
|
|
1430
|
+
mobiusSocket.handleImminentShutdown();
|
|
1431
|
+
_context14.next = 1;
|
|
1712
1432
|
return (0, _promiseTick.default)(50);
|
|
1713
1433
|
case 1:
|
|
1714
|
-
emitCalls = mobiusSocket.
|
|
1434
|
+
emitCalls = mobiusSocket.emitEvent.getCalls();
|
|
1715
1435
|
hasFailureEvent = emitCalls.some(function (call) {
|
|
1716
|
-
return call.args[0] ===
|
|
1436
|
+
return call.args[0] === 'event:mobius_shutdown_switchover_failed' && call.args[1] && call.args[1].reason === testError;
|
|
1717
1437
|
});
|
|
1718
1438
|
_testHelperChai.assert.isTrue(hasFailureEvent, 'Should emit switchover failed event');
|
|
1719
1439
|
case 2:
|
|
1720
1440
|
case "end":
|
|
1721
|
-
return
|
|
1441
|
+
return _context14.stop();
|
|
1722
1442
|
}
|
|
1723
|
-
},
|
|
1443
|
+
}, _callee14);
|
|
1724
1444
|
})));
|
|
1725
|
-
it('should allow old socket to be closed by server after switchover failure', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1726
|
-
return _regenerator.default.wrap(function (
|
|
1727
|
-
while (1) switch (
|
|
1445
|
+
it('should allow old socket to be closed by server after switchover failure', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee15() {
|
|
1446
|
+
return _regenerator.default.wrap(function (_context15) {
|
|
1447
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1728
1448
|
case 0:
|
|
1729
1449
|
connectWithBackoffStub.returns(_promise.default.reject(new Error('Failed')));
|
|
1730
|
-
mobiusSocket.
|
|
1731
|
-
|
|
1450
|
+
mobiusSocket.handleImminentShutdown();
|
|
1451
|
+
_context15.next = 1;
|
|
1732
1452
|
return (0, _promiseTick.default)(50);
|
|
1733
1453
|
case 1:
|
|
1734
1454
|
_testHelperChai.assert.equal(mobiusSocket.socket.removeAllListeners.callCount, 0);
|
|
1735
1455
|
case 2:
|
|
1736
1456
|
case "end":
|
|
1737
|
-
return
|
|
1457
|
+
return _context15.stop();
|
|
1738
1458
|
}
|
|
1739
|
-
},
|
|
1459
|
+
}, _callee15);
|
|
1740
1460
|
})));
|
|
1741
1461
|
});
|
|
1742
1462
|
describe('#_prepareAndOpenSocket()', function () {
|
|
@@ -1747,7 +1467,7 @@ describe('plugin-mobius-socket', function () {
|
|
|
1747
1467
|
mockSocket = {
|
|
1748
1468
|
open: _sinon.default.stub().returns(_promise.default.resolve())
|
|
1749
1469
|
};
|
|
1750
|
-
prepareUrlStub = _sinon.default.stub(mobiusSocket, '
|
|
1470
|
+
prepareUrlStub = _sinon.default.stub(mobiusSocket, 'prepareUrl').returns(_promise.default.resolve('ws://example.com'));
|
|
1751
1471
|
getUserTokenStub = webex.credentials.getUserToken;
|
|
1752
1472
|
getUserTokenStub.returns(_promise.default.resolve({
|
|
1753
1473
|
toString: function toString() {
|
|
@@ -1758,29 +1478,29 @@ describe('plugin-mobius-socket', function () {
|
|
|
1758
1478
|
afterEach(function () {
|
|
1759
1479
|
prepareUrlStub.restore();
|
|
1760
1480
|
});
|
|
1761
|
-
it('should prepare URL and get user token', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1762
|
-
return _regenerator.default.wrap(function (
|
|
1763
|
-
while (1) switch (
|
|
1481
|
+
it('should prepare URL and get user token', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee16() {
|
|
1482
|
+
return _regenerator.default.wrap(function (_context16) {
|
|
1483
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1764
1484
|
case 0:
|
|
1765
|
-
|
|
1766
|
-
return mobiusSocket.
|
|
1485
|
+
_context16.next = 1;
|
|
1486
|
+
return mobiusSocket.prepareAndOpenSocket(mockSocket, 'ws://test.com', false);
|
|
1767
1487
|
case 1:
|
|
1768
1488
|
_testHelperChai.assert.calledOnce(prepareUrlStub);
|
|
1769
1489
|
_testHelperChai.assert.calledWith(prepareUrlStub, 'ws://test.com');
|
|
1770
1490
|
_testHelperChai.assert.calledOnce(getUserTokenStub);
|
|
1771
1491
|
case 2:
|
|
1772
1492
|
case "end":
|
|
1773
|
-
return
|
|
1493
|
+
return _context16.stop();
|
|
1774
1494
|
}
|
|
1775
|
-
},
|
|
1495
|
+
}, _callee16);
|
|
1776
1496
|
})));
|
|
1777
|
-
it('should open socket with correct options for normal connection', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1497
|
+
it('should open socket with correct options for normal connection', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee17() {
|
|
1778
1498
|
var callArgs;
|
|
1779
|
-
return _regenerator.default.wrap(function (
|
|
1780
|
-
while (1) switch (
|
|
1499
|
+
return _regenerator.default.wrap(function (_context17) {
|
|
1500
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1781
1501
|
case 0:
|
|
1782
|
-
|
|
1783
|
-
return mobiusSocket.
|
|
1502
|
+
_context17.next = 1;
|
|
1503
|
+
return mobiusSocket.prepareAndOpenSocket(mockSocket, undefined, false);
|
|
1784
1504
|
case 1:
|
|
1785
1505
|
_testHelperChai.assert.calledOnce(mockSocket.open);
|
|
1786
1506
|
callArgs = mockSocket.open.firstCall.args;
|
|
@@ -1791,212 +1511,218 @@ describe('plugin-mobius-socket', function () {
|
|
|
1791
1511
|
_testHelperChai.assert.isDefined(callArgs[1].wssResponseTimeout);
|
|
1792
1512
|
case 2:
|
|
1793
1513
|
case "end":
|
|
1794
|
-
return
|
|
1514
|
+
return _context17.stop();
|
|
1795
1515
|
}
|
|
1796
|
-
},
|
|
1516
|
+
}, _callee17);
|
|
1797
1517
|
})));
|
|
1798
|
-
it('should log with correct prefix for normal connection', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1799
|
-
return _regenerator.default.wrap(function (
|
|
1800
|
-
while (1) switch (
|
|
1518
|
+
it('should log with correct prefix for normal connection', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee18() {
|
|
1519
|
+
return _regenerator.default.wrap(function (_context18) {
|
|
1520
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1801
1521
|
case 0:
|
|
1802
|
-
|
|
1803
|
-
return mobiusSocket.
|
|
1522
|
+
_context18.next = 1;
|
|
1523
|
+
return mobiusSocket.prepareAndOpenSocket(mockSocket, undefined, false);
|
|
1804
1524
|
case 1:
|
|
1805
1525
|
// The method should complete successfully - we're testing it runs without error
|
|
1806
1526
|
// Actual log message verification is complex due to existing stubs in parent scope
|
|
1807
1527
|
_testHelperChai.assert.calledOnce(mockSocket.open);
|
|
1808
1528
|
case 2:
|
|
1809
1529
|
case "end":
|
|
1810
|
-
return
|
|
1530
|
+
return _context18.stop();
|
|
1811
1531
|
}
|
|
1812
|
-
},
|
|
1532
|
+
}, _callee18);
|
|
1813
1533
|
})));
|
|
1814
|
-
it('should log with shutdown prefix for shutdown connection', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1815
|
-
return _regenerator.default.wrap(function (
|
|
1816
|
-
while (1) switch (
|
|
1534
|
+
it('should log with shutdown prefix for shutdown connection', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee19() {
|
|
1535
|
+
return _regenerator.default.wrap(function (_context19) {
|
|
1536
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1817
1537
|
case 0:
|
|
1818
|
-
|
|
1819
|
-
return mobiusSocket.
|
|
1538
|
+
_context19.next = 1;
|
|
1539
|
+
return mobiusSocket.prepareAndOpenSocket(mockSocket, undefined, true);
|
|
1820
1540
|
case 1:
|
|
1821
1541
|
// The method should complete successfully with shutdown flag
|
|
1822
1542
|
_testHelperChai.assert.calledOnce(mockSocket.open);
|
|
1823
1543
|
case 2:
|
|
1824
1544
|
case "end":
|
|
1825
|
-
return
|
|
1545
|
+
return _context19.stop();
|
|
1826
1546
|
}
|
|
1827
|
-
},
|
|
1547
|
+
}, _callee19);
|
|
1828
1548
|
})));
|
|
1829
|
-
it('should merge custom mobiusSocket options when provided', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1549
|
+
it('should merge custom mobiusSocket options when provided', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee20() {
|
|
1830
1550
|
var callArgs;
|
|
1831
|
-
return _regenerator.default.wrap(function (
|
|
1832
|
-
while (1) switch (
|
|
1551
|
+
return _regenerator.default.wrap(function (_context20) {
|
|
1552
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1833
1553
|
case 0:
|
|
1834
1554
|
webex.config.defaultMobiusSocketOptions = {
|
|
1835
1555
|
customOption: 'test-value',
|
|
1836
1556
|
wssResponseTimeout: 99999
|
|
1837
1557
|
};
|
|
1838
|
-
|
|
1839
|
-
return mobiusSocket.
|
|
1558
|
+
_context20.next = 1;
|
|
1559
|
+
return mobiusSocket.prepareAndOpenSocket(mockSocket, undefined, false);
|
|
1840
1560
|
case 1:
|
|
1841
1561
|
callArgs = mockSocket.open.firstCall.args;
|
|
1842
1562
|
_testHelperChai.assert.equal(callArgs[1].customOption, 'test-value');
|
|
1843
1563
|
_testHelperChai.assert.equal(callArgs[1].wssResponseTimeout, 99999); // Custom value overrides default
|
|
1844
1564
|
case 2:
|
|
1845
1565
|
case "end":
|
|
1846
|
-
return
|
|
1566
|
+
return _context20.stop();
|
|
1847
1567
|
}
|
|
1848
|
-
},
|
|
1568
|
+
}, _callee20);
|
|
1849
1569
|
})));
|
|
1850
|
-
it('should return the webSocketUrl after opening', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1570
|
+
it('should return the webSocketUrl after opening', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee21() {
|
|
1851
1571
|
var result;
|
|
1852
|
-
return _regenerator.default.wrap(function (
|
|
1853
|
-
while (1) switch (
|
|
1572
|
+
return _regenerator.default.wrap(function (_context21) {
|
|
1573
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1854
1574
|
case 0:
|
|
1855
|
-
|
|
1856
|
-
return mobiusSocket.
|
|
1575
|
+
_context21.next = 1;
|
|
1576
|
+
return mobiusSocket.prepareAndOpenSocket(mockSocket, undefined, false);
|
|
1857
1577
|
case 1:
|
|
1858
|
-
result =
|
|
1578
|
+
result = _context21.sent;
|
|
1859
1579
|
_testHelperChai.assert.equal(result, 'ws://example.com');
|
|
1860
1580
|
case 2:
|
|
1861
1581
|
case "end":
|
|
1862
|
-
return
|
|
1582
|
+
return _context21.stop();
|
|
1863
1583
|
}
|
|
1864
|
-
},
|
|
1584
|
+
}, _callee21);
|
|
1865
1585
|
})));
|
|
1866
|
-
it('should handle errors during socket open', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1586
|
+
it('should handle errors during socket open', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee22() {
|
|
1867
1587
|
var _t2;
|
|
1868
|
-
return _regenerator.default.wrap(function (
|
|
1869
|
-
while (1) switch (
|
|
1588
|
+
return _regenerator.default.wrap(function (_context22) {
|
|
1589
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1870
1590
|
case 0:
|
|
1871
1591
|
mockSocket.open.returns(_promise.default.reject(new Error('Open failed')));
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
return mobiusSocket.
|
|
1592
|
+
_context22.prev = 1;
|
|
1593
|
+
_context22.next = 2;
|
|
1594
|
+
return mobiusSocket.prepareAndOpenSocket(mockSocket, undefined, false);
|
|
1875
1595
|
case 2:
|
|
1876
1596
|
_testHelperChai.assert.fail('Should have thrown an error');
|
|
1877
|
-
|
|
1597
|
+
_context22.next = 4;
|
|
1878
1598
|
break;
|
|
1879
1599
|
case 3:
|
|
1880
|
-
|
|
1881
|
-
_t2 =
|
|
1600
|
+
_context22.prev = 3;
|
|
1601
|
+
_t2 = _context22["catch"](1);
|
|
1882
1602
|
_testHelperChai.assert.equal(_t2.message, 'Open failed');
|
|
1883
1603
|
case 4:
|
|
1884
1604
|
case "end":
|
|
1885
|
-
return
|
|
1605
|
+
return _context22.stop();
|
|
1886
1606
|
}
|
|
1887
|
-
},
|
|
1607
|
+
}, _callee22, null, [[1, 3]]);
|
|
1888
1608
|
})));
|
|
1889
1609
|
});
|
|
1890
1610
|
describe('#_attemptConnection() with shutdown switchover', function () {
|
|
1891
1611
|
var prepareAndOpenSocketStub;
|
|
1892
1612
|
var callback;
|
|
1893
|
-
var sessionId = 'mobius-websocket-session';
|
|
1894
1613
|
beforeEach(function () {
|
|
1895
|
-
prepareAndOpenSocketStub = _sinon.default.stub(mobiusSocket, '
|
|
1614
|
+
prepareAndOpenSocketStub = _sinon.default.stub(mobiusSocket, 'prepareAndOpenSocket').returns(_promise.default.resolve('ws://new-socket.com'));
|
|
1896
1615
|
callback = _sinon.default.stub();
|
|
1897
|
-
mobiusSocket.
|
|
1616
|
+
mobiusSocket.shutdownSwitchoverBackoffCall = {
|
|
1898
1617
|
abort: _sinon.default.stub()
|
|
1899
|
-
}
|
|
1618
|
+
};
|
|
1900
1619
|
mobiusSocket.socket = {
|
|
1901
1620
|
url: 'ws://test.com'
|
|
1902
1621
|
};
|
|
1903
1622
|
mobiusSocket.connected = true;
|
|
1904
|
-
_sinon.default.stub(mobiusSocket, '
|
|
1905
|
-
_sinon.default.stub(mobiusSocket, '
|
|
1623
|
+
_sinon.default.stub(mobiusSocket, 'emitEvent');
|
|
1624
|
+
_sinon.default.stub(mobiusSocket, 'attachSocketEventListeners');
|
|
1906
1625
|
});
|
|
1907
1626
|
afterEach(function () {
|
|
1908
1627
|
prepareAndOpenSocketStub.restore();
|
|
1909
|
-
mobiusSocket.
|
|
1910
|
-
mobiusSocket.
|
|
1911
|
-
mobiusSocket.
|
|
1628
|
+
mobiusSocket.emitEvent.restore();
|
|
1629
|
+
mobiusSocket.attachSocketEventListeners.restore();
|
|
1630
|
+
mobiusSocket.shutdownSwitchoverBackoffCall = undefined;
|
|
1912
1631
|
});
|
|
1913
|
-
it('should not set socket reference before opening for shutdown switchover', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1632
|
+
it('should not set socket reference before opening for shutdown switchover', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee23() {
|
|
1914
1633
|
var originalSocket;
|
|
1915
|
-
return _regenerator.default.wrap(function (
|
|
1916
|
-
while (1) switch (
|
|
1634
|
+
return _regenerator.default.wrap(function (_context23) {
|
|
1635
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1917
1636
|
case 0:
|
|
1918
1637
|
originalSocket = mobiusSocket.socket;
|
|
1919
|
-
|
|
1920
|
-
return mobiusSocket.
|
|
1638
|
+
_context23.next = 1;
|
|
1639
|
+
return mobiusSocket.attemptConnection('ws://test.com', callback, {
|
|
1921
1640
|
isShutdownSwitchover: true,
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1641
|
+
attemptOptions: {
|
|
1642
|
+
onSuccess: function onSuccess(newSocket, url) {
|
|
1643
|
+
_testHelperChai.assert.exists(newSocket);
|
|
1644
|
+
_testHelperChai.assert.equal(url, 'ws://new-socket.com');
|
|
1645
|
+
}
|
|
1926
1646
|
}
|
|
1927
1647
|
});
|
|
1928
1648
|
case 1:
|
|
1649
|
+
// During shutdown switchover, this.socket should remain the old socket
|
|
1929
1650
|
_testHelperChai.assert.equal(mobiusSocket.socket, originalSocket);
|
|
1930
1651
|
case 2:
|
|
1931
1652
|
case "end":
|
|
1932
|
-
return
|
|
1653
|
+
return _context23.stop();
|
|
1933
1654
|
}
|
|
1934
|
-
},
|
|
1655
|
+
}, _callee23);
|
|
1935
1656
|
})));
|
|
1936
|
-
it('should call onSuccess callback with new socket and URL for shutdown', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1657
|
+
it('should call onSuccess callback with new socket and URL for shutdown', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee24() {
|
|
1937
1658
|
var onSuccessStub;
|
|
1938
|
-
return _regenerator.default.wrap(function (
|
|
1939
|
-
while (1) switch (
|
|
1659
|
+
return _regenerator.default.wrap(function (_context24) {
|
|
1660
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1940
1661
|
case 0:
|
|
1941
1662
|
onSuccessStub = _sinon.default.stub();
|
|
1942
|
-
|
|
1943
|
-
return mobiusSocket.
|
|
1663
|
+
_context24.next = 1;
|
|
1664
|
+
return mobiusSocket.attemptConnection('ws://test.com', callback, {
|
|
1944
1665
|
isShutdownSwitchover: true,
|
|
1945
|
-
|
|
1666
|
+
attemptOptions: {
|
|
1667
|
+
onSuccess: onSuccessStub
|
|
1668
|
+
}
|
|
1946
1669
|
});
|
|
1947
1670
|
case 1:
|
|
1948
1671
|
_testHelperChai.assert.calledOnce(onSuccessStub);
|
|
1949
1672
|
_testHelperChai.assert.equal(onSuccessStub.firstCall.args[1], 'ws://new-socket.com');
|
|
1950
1673
|
case 2:
|
|
1951
1674
|
case "end":
|
|
1952
|
-
return
|
|
1675
|
+
return _context24.stop();
|
|
1953
1676
|
}
|
|
1954
|
-
},
|
|
1677
|
+
}, _callee24);
|
|
1955
1678
|
})));
|
|
1956
|
-
it('should emit shutdown switchover complete event', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1957
|
-
return _regenerator.default.wrap(function (
|
|
1958
|
-
while (1) switch (
|
|
1679
|
+
it('should emit shutdown switchover complete event', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee25() {
|
|
1680
|
+
return _regenerator.default.wrap(function (_context25) {
|
|
1681
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
1959
1682
|
case 0:
|
|
1960
|
-
|
|
1961
|
-
return mobiusSocket.
|
|
1683
|
+
_context25.next = 1;
|
|
1684
|
+
return mobiusSocket.attemptConnection('ws://test.com', callback, {
|
|
1962
1685
|
isShutdownSwitchover: true,
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1686
|
+
attemptOptions: {
|
|
1687
|
+
onSuccess: function onSuccess(newSocket, url) {
|
|
1688
|
+
mobiusSocket.socket = newSocket;
|
|
1689
|
+
mobiusSocket.connected = true;
|
|
1690
|
+
mobiusSocket.emitEvent('event:mobius_shutdown_switchover_complete', {
|
|
1691
|
+
url: url
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1969
1694
|
}
|
|
1970
1695
|
});
|
|
1971
1696
|
case 1:
|
|
1972
|
-
_testHelperChai.assert.calledWith(mobiusSocket.
|
|
1697
|
+
_testHelperChai.assert.calledWith(mobiusSocket.emitEvent, 'event:mobius_shutdown_switchover_complete', _sinon.default.match.has('url', 'ws://new-socket.com'));
|
|
1973
1698
|
case 2:
|
|
1974
1699
|
case "end":
|
|
1975
|
-
return
|
|
1700
|
+
return _context25.stop();
|
|
1976
1701
|
}
|
|
1977
|
-
},
|
|
1702
|
+
}, _callee25);
|
|
1978
1703
|
})));
|
|
1979
|
-
it('should use simpler error handling for shutdown switchover failures', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
1980
|
-
return _regenerator.default.wrap(function (
|
|
1981
|
-
while (1) switch (
|
|
1704
|
+
it('should use simpler error handling for shutdown switchover failures', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee26() {
|
|
1705
|
+
return _regenerator.default.wrap(function (_context26) {
|
|
1706
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
1982
1707
|
case 0:
|
|
1983
1708
|
prepareAndOpenSocketStub.returns(_promise.default.reject(new Error('Connection failed')));
|
|
1984
|
-
|
|
1985
|
-
return mobiusSocket.
|
|
1986
|
-
isShutdownSwitchover: true
|
|
1709
|
+
_context26.next = 1;
|
|
1710
|
+
return mobiusSocket.attemptConnection('ws://test.com', callback, {
|
|
1711
|
+
isShutdownSwitchover: true,
|
|
1712
|
+
attemptOptions: {}
|
|
1987
1713
|
}).catch(function () {});
|
|
1988
1714
|
case 1:
|
|
1989
1715
|
_testHelperChai.assert.calledOnce(callback);
|
|
1990
1716
|
_testHelperChai.assert.instanceOf(callback.firstCall.args[0], Error);
|
|
1991
1717
|
case 2:
|
|
1992
1718
|
case "end":
|
|
1993
|
-
return
|
|
1719
|
+
return _context26.stop();
|
|
1994
1720
|
}
|
|
1995
|
-
},
|
|
1721
|
+
}, _callee26);
|
|
1996
1722
|
})));
|
|
1997
|
-
it('should check
|
|
1998
|
-
mobiusSocket.
|
|
1999
|
-
var result = mobiusSocket.
|
|
1723
|
+
it('should check shutdownSwitchoverBackoffCall for shutdown connections', function () {
|
|
1724
|
+
mobiusSocket.shutdownSwitchoverBackoffCall = undefined;
|
|
1725
|
+
var result = mobiusSocket.attemptConnection('ws://test.com', callback, {
|
|
2000
1726
|
isShutdownSwitchover: true
|
|
2001
1727
|
});
|
|
2002
1728
|
return result.catch(function (err) {
|
|
@@ -2006,20 +1732,19 @@ describe('plugin-mobius-socket', function () {
|
|
|
2006
1732
|
});
|
|
2007
1733
|
});
|
|
2008
1734
|
describe('#_connectWithBackoff() with shutdown switchover', function () {
|
|
2009
|
-
var sessionId = 'mobius-websocket-session';
|
|
2010
1735
|
it('should use shutdown-specific parameters when called', function () {
|
|
2011
|
-
var connectWithBackoffStub = _sinon.default.stub(mobiusSocket, '
|
|
2012
|
-
mobiusSocket.
|
|
1736
|
+
var connectWithBackoffStub = _sinon.default.stub(mobiusSocket, 'connectWithBackoff').returns(_promise.default.resolve());
|
|
1737
|
+
mobiusSocket.handleImminentShutdown();
|
|
2013
1738
|
_testHelperChai.assert.calledOnce(connectWithBackoffStub);
|
|
2014
1739
|
var callArgs = connectWithBackoffStub.firstCall.args;
|
|
2015
|
-
_testHelperChai.assert.
|
|
2016
|
-
_testHelperChai.assert.isObject(callArgs[
|
|
2017
|
-
_testHelperChai.assert.isTrue(callArgs[
|
|
1740
|
+
_testHelperChai.assert.isUndefined(callArgs[0]); // webSocketUrl
|
|
1741
|
+
_testHelperChai.assert.isObject(callArgs[1]);
|
|
1742
|
+
_testHelperChai.assert.isTrue(callArgs[1].isShutdownSwitchover);
|
|
2018
1743
|
connectWithBackoffStub.restore();
|
|
2019
1744
|
});
|
|
2020
1745
|
it('should pass shutdown switchover options to _attemptConnection', function () {
|
|
2021
|
-
var attemptStub = _sinon.default.stub(mobiusSocket, '
|
|
2022
|
-
attemptStub.callsFake(function (url,
|
|
1746
|
+
var attemptStub = _sinon.default.stub(mobiusSocket, 'attemptConnection');
|
|
1747
|
+
attemptStub.callsFake(function (url, cb) {
|
|
2023
1748
|
return cb();
|
|
2024
1749
|
});
|
|
2025
1750
|
var context = {
|
|
@@ -2029,24 +1754,23 @@ describe('plugin-mobius-socket', function () {
|
|
|
2029
1754
|
onSuccess: function onSuccess() {}
|
|
2030
1755
|
}
|
|
2031
1756
|
};
|
|
2032
|
-
var promise = mobiusSocket.
|
|
1757
|
+
var promise = mobiusSocket.connectWithBackoff(undefined, context);
|
|
2033
1758
|
return promise.then(function () {
|
|
2034
1759
|
_testHelperChai.assert.calledOnce(attemptStub);
|
|
2035
1760
|
var callArgs = attemptStub.firstCall.args;
|
|
2036
|
-
_testHelperChai.assert.
|
|
2037
|
-
_testHelperChai.assert.
|
|
2038
|
-
_testHelperChai.assert.isTrue(callArgs[3].isShutdownSwitchover);
|
|
1761
|
+
_testHelperChai.assert.isObject(callArgs[2]);
|
|
1762
|
+
_testHelperChai.assert.isTrue(callArgs[2].isShutdownSwitchover);
|
|
2039
1763
|
attemptStub.restore();
|
|
2040
1764
|
});
|
|
2041
1765
|
});
|
|
2042
1766
|
it('should set and clear state flags appropriately', function () {
|
|
2043
|
-
_sinon.default.stub(mobiusSocket, '
|
|
1767
|
+
_sinon.default.stub(mobiusSocket, 'attemptConnection').callsFake(function (url, cb) {
|
|
2044
1768
|
return cb();
|
|
2045
1769
|
});
|
|
2046
|
-
mobiusSocket.
|
|
1770
|
+
mobiusSocket.shutdownSwitchoverBackoffCall = {
|
|
2047
1771
|
placeholder: true
|
|
2048
|
-
}
|
|
2049
|
-
var promise = mobiusSocket.
|
|
1772
|
+
};
|
|
1773
|
+
var promise = mobiusSocket.connectWithBackoff(undefined, {
|
|
2050
1774
|
isShutdownSwitchover: true,
|
|
2051
1775
|
attemptOptions: {
|
|
2052
1776
|
isShutdownSwitchover: true,
|
|
@@ -2054,53 +1778,53 @@ describe('plugin-mobius-socket', function () {
|
|
|
2054
1778
|
}
|
|
2055
1779
|
});
|
|
2056
1780
|
return promise.then(function () {
|
|
2057
|
-
_testHelperChai.assert.isUndefined(mobiusSocket.
|
|
2058
|
-
mobiusSocket.
|
|
1781
|
+
_testHelperChai.assert.isUndefined(mobiusSocket.shutdownSwitchoverBackoffCall);
|
|
1782
|
+
mobiusSocket.attemptConnection.restore();
|
|
2059
1783
|
});
|
|
2060
1784
|
});
|
|
2061
1785
|
});
|
|
2062
1786
|
describe('#disconnect() with shutdown switchover in progress', function () {
|
|
2063
1787
|
var abortStub;
|
|
2064
|
-
var sessionId = 'mobius-websocket-session';
|
|
2065
1788
|
beforeEach(function () {
|
|
2066
|
-
mobiusSocket.
|
|
2067
|
-
mobiusSocket.sockets.set(sessionId, {
|
|
1789
|
+
mobiusSocket.socket = {
|
|
2068
1790
|
close: _sinon.default.stub().returns(_promise.default.resolve()),
|
|
2069
|
-
removeAllListeners: _sinon.default.stub()
|
|
2070
|
-
|
|
1791
|
+
removeAllListeners: _sinon.default.stub(),
|
|
1792
|
+
connecting: false,
|
|
1793
|
+
connected: true
|
|
1794
|
+
};
|
|
2071
1795
|
abortStub = _sinon.default.stub();
|
|
2072
|
-
mobiusSocket.
|
|
1796
|
+
mobiusSocket.shutdownSwitchoverBackoffCall = {
|
|
2073
1797
|
abort: abortStub
|
|
2074
|
-
}
|
|
1798
|
+
};
|
|
2075
1799
|
});
|
|
2076
|
-
it('should abort shutdown switchover backoff call on disconnect', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
2077
|
-
return _regenerator.default.wrap(function (
|
|
2078
|
-
while (1) switch (
|
|
1800
|
+
it('should abort shutdown switchover backoff call on disconnect', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee27() {
|
|
1801
|
+
return _regenerator.default.wrap(function (_context27) {
|
|
1802
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
2079
1803
|
case 0:
|
|
2080
|
-
|
|
2081
|
-
return mobiusSocket.disconnect(
|
|
1804
|
+
_context27.next = 1;
|
|
1805
|
+
return mobiusSocket.disconnect();
|
|
2082
1806
|
case 1:
|
|
2083
1807
|
_testHelperChai.assert.calledOnce(abortStub);
|
|
2084
1808
|
case 2:
|
|
2085
1809
|
case "end":
|
|
2086
|
-
return
|
|
1810
|
+
return _context27.stop();
|
|
2087
1811
|
}
|
|
2088
|
-
},
|
|
1812
|
+
}, _callee27);
|
|
2089
1813
|
})));
|
|
2090
|
-
it('should handle disconnect when no switchover is in progress', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function
|
|
2091
|
-
return _regenerator.default.wrap(function (
|
|
2092
|
-
while (1) switch (
|
|
1814
|
+
it('should handle disconnect when no switchover is in progress', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee28() {
|
|
1815
|
+
return _regenerator.default.wrap(function (_context28) {
|
|
1816
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
2093
1817
|
case 0:
|
|
2094
|
-
mobiusSocket.
|
|
2095
|
-
|
|
2096
|
-
return mobiusSocket.disconnect(
|
|
1818
|
+
mobiusSocket.shutdownSwitchoverBackoffCall = undefined;
|
|
1819
|
+
_context28.next = 1;
|
|
1820
|
+
return mobiusSocket.disconnect();
|
|
2097
1821
|
case 1:
|
|
2098
|
-
_testHelperChai.assert.calledOnce(mobiusSocket.
|
|
1822
|
+
_testHelperChai.assert.calledOnce(mobiusSocket.socket.close);
|
|
2099
1823
|
case 2:
|
|
2100
1824
|
case "end":
|
|
2101
|
-
return
|
|
1825
|
+
return _context28.stop();
|
|
2102
1826
|
}
|
|
2103
|
-
},
|
|
1827
|
+
}, _callee28);
|
|
2104
1828
|
})));
|
|
2105
1829
|
});
|
|
2106
1830
|
});
|