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