@webex/internal-plugin-mercury 3.0.0-beta.42 → 3.0.0-beta.420
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/README.md +14 -1
- package/dist/mercury.js +64 -53
- package/dist/mercury.js.map +1 -1
- package/dist/socket/socket-base.js +43 -27
- package/dist/socket/socket-base.js.map +1 -1
- package/package.json +14 -14
- package/src/mercury.js +63 -52
- package/src/socket/socket-base.js +61 -28
- package/test/integration/spec/webex.js +3 -2
- package/test/unit/spec/mercury.js +86 -9
- package/test/unit/spec/socket.js +18 -1
|
@@ -152,9 +152,7 @@ describe('plugin-mercury', () => {
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
describe('when `maxRetries` is set', () => {
|
|
155
|
-
|
|
156
|
-
skipInBrowser(it)('fails after `maxRetries` attempts', () => {
|
|
157
|
-
mercury.config.maxRetries = 2;
|
|
155
|
+
const check = () => {
|
|
158
156
|
socketOpenStub.restore();
|
|
159
157
|
socketOpenStub = sinon.stub(Socket.prototype, 'open');
|
|
160
158
|
socketOpenStub.returns(Promise.reject(new ConnectionError()));
|
|
@@ -182,12 +180,42 @@ describe('plugin-mercury', () => {
|
|
|
182
180
|
.then(() => {
|
|
183
181
|
assert.calledThrice(Socket.prototype.open);
|
|
184
182
|
clock.tick(5 * mercury.config.backoffTimeReset);
|
|
185
|
-
|
|
186
183
|
return assert.isRejected(promise);
|
|
187
184
|
})
|
|
188
185
|
.then(() => {
|
|
189
186
|
assert.calledThrice(Socket.prototype.open);
|
|
190
187
|
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// skipping due to apparent bug with lolex in all browsers but Chrome.
|
|
191
|
+
// if initial retries is zero and mercury has never connected max retries is used
|
|
192
|
+
skipInBrowser(it)('fails after `maxRetries` attempts', () => {
|
|
193
|
+
mercury.config.maxRetries = 2;
|
|
194
|
+
mercury.config.initialConnectionMaxRetries = 0;
|
|
195
|
+
|
|
196
|
+
return check();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// initial retries is non-zero so takes precedence over maxRetries when mercury has never connected
|
|
200
|
+
skipInBrowser(it)('fails after `initialConnectionMaxRetries` attempts', () => {
|
|
201
|
+
mercury.config.maxRetries = 0;
|
|
202
|
+
mercury.config.initialConnectionMaxRetries = 2;
|
|
203
|
+
return check();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// initial retries is non-zero so takes precedence over maxRetries when mercury has never connected
|
|
207
|
+
skipInBrowser(it)('fails after `initialConnectionMaxRetries` attempts', () => {
|
|
208
|
+
mercury.config.initialConnectionMaxRetries = 2;
|
|
209
|
+
mercury.config.maxRetries = 5;
|
|
210
|
+
return check();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// when mercury has connected maxRetries is used and the initialConnectionMaxRetries is ignored
|
|
214
|
+
skipInBrowser(it)('fails after `initialConnectionMaxRetries` attempts', () => {
|
|
215
|
+
mercury.config.initialConnectionMaxRetries = 5;
|
|
216
|
+
mercury.config.maxRetries = 2;
|
|
217
|
+
mercury.hasEverConnected = true;
|
|
218
|
+
return check();
|
|
191
219
|
});
|
|
192
220
|
});
|
|
193
221
|
|
|
@@ -541,7 +569,10 @@ describe('plugin-mercury', () => {
|
|
|
541
569
|
// The socket will never be unset (which seems bad)
|
|
542
570
|
assert.isDefined(mercury.socket, 'Mercury socket is not defined');
|
|
543
571
|
|
|
544
|
-
return assert.isRejected(promise)
|
|
572
|
+
return assert.isRejected(promise).then((error) => {
|
|
573
|
+
// connection did not fail, so no last error
|
|
574
|
+
assert.isUndefined(mercury.getLastError());
|
|
575
|
+
});
|
|
545
576
|
});
|
|
546
577
|
});
|
|
547
578
|
|
|
@@ -560,20 +591,53 @@ describe('plugin-mercury', () => {
|
|
|
560
591
|
return promiseTick(webex.internal.mercury.config.backoffTimeReset).then(() => {
|
|
561
592
|
assert.equal(
|
|
562
593
|
reason.message,
|
|
563
|
-
'
|
|
594
|
+
'Mercury: prevent socket open when backoffCall no longer defined'
|
|
564
595
|
);
|
|
565
596
|
});
|
|
566
597
|
});
|
|
598
|
+
|
|
599
|
+
it('sets lastError when retrying', () => {
|
|
600
|
+
const realError = new Error('FORCED');
|
|
601
|
+
|
|
602
|
+
socketOpenStub.restore();
|
|
603
|
+
socketOpenStub = sinon.stub(Socket.prototype, 'open');
|
|
604
|
+
socketOpenStub.onCall(0).returns(Promise.reject(realError));
|
|
605
|
+
const promise = mercury.connect();
|
|
606
|
+
|
|
607
|
+
// Wait for the connect call to setup
|
|
608
|
+
return promiseTick(webex.internal.mercury.config.backoffTimeReset).then(() => {
|
|
609
|
+
// Calling disconnect will abort the backoffCall, close the socket, and
|
|
610
|
+
// reject the connect
|
|
611
|
+
mercury.disconnect();
|
|
612
|
+
|
|
613
|
+
return assert.isRejected(promise).then((error) => {
|
|
614
|
+
const lastError = mercury.getLastError();
|
|
615
|
+
|
|
616
|
+
assert.equal(error.message, "Mercury Connection Aborted");
|
|
617
|
+
assert.isDefined(lastError);
|
|
618
|
+
assert.equal(lastError, realError);
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
});
|
|
567
622
|
});
|
|
568
623
|
});
|
|
569
624
|
|
|
570
625
|
describe('#_emit()', () => {
|
|
571
|
-
it('emits Error-safe events', () => {
|
|
626
|
+
it('emits Error-safe events and log the error with the call parameters', () => {
|
|
627
|
+
const error = 'error';
|
|
628
|
+
const event = {data: 'some data'};
|
|
572
629
|
mercury.on('break', () => {
|
|
573
|
-
throw
|
|
630
|
+
throw error;
|
|
574
631
|
});
|
|
632
|
+
sinon.stub(mercury.logger, 'error');
|
|
575
633
|
|
|
576
|
-
return Promise.resolve(mercury._emit('break'))
|
|
634
|
+
return Promise.resolve(mercury._emit('break', event)).then((res) => {
|
|
635
|
+
assert.calledWith(mercury.logger.error, 'Mercury: error occurred in event handler', {
|
|
636
|
+
error,
|
|
637
|
+
arguments: ['break', event],
|
|
638
|
+
});
|
|
639
|
+
return res;
|
|
640
|
+
});
|
|
577
641
|
});
|
|
578
642
|
});
|
|
579
643
|
|
|
@@ -707,5 +771,18 @@ describe('plugin-mercury', () => {
|
|
|
707
771
|
.then((wsUrl) => assert.match(wsUrl, /multipleConnections/)));
|
|
708
772
|
});
|
|
709
773
|
});
|
|
774
|
+
|
|
775
|
+
describe('ping pong latency event is forwarded', () => {
|
|
776
|
+
it('should forward ping pong latency event', () => {
|
|
777
|
+
const spy = sinon.spy();
|
|
778
|
+
|
|
779
|
+
mercury.on('ping-pong-latency', spy);
|
|
780
|
+
|
|
781
|
+
return mercury.connect().then(() => {
|
|
782
|
+
assert.calledWith(spy, 0);
|
|
783
|
+
assert.calledOnce(spy);
|
|
784
|
+
});
|
|
785
|
+
});
|
|
786
|
+
});
|
|
710
787
|
});
|
|
711
788
|
});
|
package/test/unit/spec/socket.js
CHANGED
|
@@ -39,7 +39,7 @@ describe('plugin-mercury', () => {
|
|
|
39
39
|
clock.uninstall();
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
beforeEach(
|
|
42
|
+
beforeEach(() => {
|
|
43
43
|
sinon.stub(Socket, 'getWebSocketConstructor').callsFake(
|
|
44
44
|
() =>
|
|
45
45
|
function (...args) {
|
|
@@ -809,6 +809,23 @@ describe('plugin-mercury', () => {
|
|
|
809
809
|
reason: 'Pong mismatch',
|
|
810
810
|
});
|
|
811
811
|
});
|
|
812
|
+
|
|
813
|
+
it('emits ping pong latency correctly', () => {
|
|
814
|
+
const spy = sinon.spy();
|
|
815
|
+
|
|
816
|
+
socket.on('ping-pong-latency', spy);
|
|
817
|
+
|
|
818
|
+
socket._ping(123);
|
|
819
|
+
mockWebSocket.emit('message', {
|
|
820
|
+
data: JSON.stringify({
|
|
821
|
+
type: 'pong',
|
|
822
|
+
id: 123,
|
|
823
|
+
}),
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
assert.calledWith(spy, 0);
|
|
827
|
+
assert.calledOnce(spy);
|
|
828
|
+
});
|
|
812
829
|
});
|
|
813
830
|
});
|
|
814
831
|
});
|