@webex/calling 3.8.1-next.2 → 3.8.1-next.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/CallSettings/WxCallBackendConnector.js +2 -2
- package/dist/CallSettings/WxCallBackendConnector.js.map +1 -1
- package/dist/CallSettings/WxCallBackendConnector.test.js +94 -27
- package/dist/CallSettings/WxCallBackendConnector.test.js.map +1 -1
- package/dist/CallSettings/types.js.map +1 -1
- package/dist/CallingClient/CallingClient.js +56 -21
- package/dist/CallingClient/CallingClient.js.map +1 -1
- package/dist/CallingClient/CallingClient.test.js +168 -102
- package/dist/CallingClient/CallingClient.test.js.map +1 -1
- package/dist/CallingClient/constants.js +3 -4
- package/dist/CallingClient/constants.js.map +1 -1
- package/dist/CallingClient/line/line.test.js +4 -10
- package/dist/CallingClient/line/line.test.js.map +1 -1
- package/dist/CallingClient/registration/register.js +371 -285
- package/dist/CallingClient/registration/register.js.map +1 -1
- package/dist/CallingClient/registration/register.test.js +412 -300
- package/dist/CallingClient/registration/register.test.js.map +1 -1
- package/dist/CallingClient/registration/types.js.map +1 -1
- package/dist/CallingClient/registration/webWorker.js +115 -0
- package/dist/CallingClient/registration/webWorker.js.map +1 -0
- package/dist/CallingClient/registration/webWorker.test.js +256 -0
- package/dist/CallingClient/registration/webWorker.test.js.map +1 -0
- package/dist/CallingClient/registration/webWorkerStr.js +15 -0
- package/dist/CallingClient/registration/webWorkerStr.js.map +1 -0
- package/dist/common/Utils.js +13 -7
- package/dist/common/Utils.js.map +1 -1
- package/dist/common/Utils.test.js +265 -119
- package/dist/common/Utils.test.js.map +1 -1
- package/dist/common/types.js +8 -1
- package/dist/common/types.js.map +1 -1
- package/dist/module/CallSettings/WxCallBackendConnector.js +1 -1
- package/dist/module/CallingClient/CallingClient.js +23 -8
- package/dist/module/CallingClient/constants.js +1 -2
- package/dist/module/CallingClient/registration/register.js +93 -60
- package/dist/module/CallingClient/registration/webWorker.js +59 -0
- package/dist/module/CallingClient/registration/webWorkerStr.js +93 -0
- package/dist/module/common/Utils.js +8 -1
- package/dist/module/common/types.js +7 -0
- package/dist/types/CallSettings/types.d.ts +1 -1
- package/dist/types/CallSettings/types.d.ts.map +1 -1
- package/dist/types/CallingClient/CallingClient.d.ts.map +1 -1
- package/dist/types/CallingClient/constants.d.ts +1 -2
- package/dist/types/CallingClient/constants.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/register.d.ts +2 -2
- package/dist/types/CallingClient/registration/register.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/types.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/webWorker.d.ts +2 -0
- package/dist/types/CallingClient/registration/webWorker.d.ts.map +1 -0
- package/dist/types/CallingClient/registration/webWorkerStr.d.ts +3 -0
- package/dist/types/CallingClient/registration/webWorkerStr.d.ts.map +1 -0
- package/dist/types/common/Utils.d.ts.map +1 -1
- package/dist/types/common/types.d.ts +12 -0
- package/dist/types/common/types.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -117,6 +117,7 @@ describe('Registration Tests', function () {
|
|
|
117
117
|
var restartSpy;
|
|
118
118
|
var restoreSpy;
|
|
119
119
|
var postRegistrationSpy;
|
|
120
|
+
var deregisterSpy;
|
|
120
121
|
var failoverSpy;
|
|
121
122
|
var retry429Spy;
|
|
122
123
|
var metricSpy;
|
|
@@ -128,6 +129,7 @@ describe('Registration Tests', function () {
|
|
|
128
129
|
restartSpy = jest.spyOn(reg, 'restartRegistration');
|
|
129
130
|
restoreSpy = jest.spyOn(reg, 'restorePreviousRegistration');
|
|
130
131
|
postRegistrationSpy = jest.spyOn(reg, 'postRegistration');
|
|
132
|
+
deregisterSpy = jest.spyOn(reg, 'deregister');
|
|
131
133
|
failoverSpy = jest.spyOn(reg, 'startFailoverTimer');
|
|
132
134
|
retry429Spy = jest.spyOn(reg, 'handle429Retry');
|
|
133
135
|
metricSpy = jest.spyOn(reg.metricManager, 'submitRegistrationMetric');
|
|
@@ -467,7 +469,7 @@ describe('Registration Tests', function () {
|
|
|
467
469
|
_context7.next = 5;
|
|
468
470
|
return reg.triggerRegistration();
|
|
469
471
|
case 5:
|
|
470
|
-
jest.advanceTimersByTime(_constants.
|
|
472
|
+
jest.advanceTimersByTime(_constants.REG_TRY_BACKUP_TIMER_VAL_IN_SEC * _constants.SEC_TO_MSEC_MFACTOR);
|
|
471
473
|
_context7.next = 8;
|
|
472
474
|
return flushPromises();
|
|
473
475
|
case 8:
|
|
@@ -628,7 +630,7 @@ describe('Registration Tests', function () {
|
|
|
628
630
|
_context11.next = 6;
|
|
629
631
|
return reg.triggerRegistration();
|
|
630
632
|
case 6:
|
|
631
|
-
jest.advanceTimersByTime(_constants.
|
|
633
|
+
jest.advanceTimersByTime(_constants.REG_TRY_BACKUP_TIMER_VAL_IN_SEC * _constants.SEC_TO_MSEC_MFACTOR);
|
|
632
634
|
_context11.next = 9;
|
|
633
635
|
return flushPromises();
|
|
634
636
|
case 9:
|
|
@@ -697,21 +699,23 @@ describe('Registration Tests', function () {
|
|
|
697
699
|
})));
|
|
698
700
|
});
|
|
699
701
|
describe('Registration failback tests', function () {
|
|
702
|
+
var isPrimaryActiveSpy;
|
|
700
703
|
beforeEach( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13() {
|
|
701
704
|
return _regenerator.default.wrap(function _callee13$(_context13) {
|
|
702
705
|
while (1) switch (_context13.prev = _context13.next) {
|
|
703
706
|
case 0:
|
|
707
|
+
isPrimaryActiveSpy = jest.spyOn(reg, 'isPrimaryActive');
|
|
708
|
+
isPrimaryActiveSpy.mockReturnValue(true);
|
|
704
709
|
/* keep keepalive as active so that it wont interfere with the failback tests */
|
|
705
|
-
jest.spyOn(reg, 'postKeepAlive').mockResolvedValue(successPayload);
|
|
706
710
|
jest.useFakeTimers();
|
|
707
711
|
postRegistrationSpy.mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockResolvedValueOnce(successPayload);
|
|
708
|
-
_context13.next =
|
|
712
|
+
_context13.next = 6;
|
|
709
713
|
return reg.triggerRegistration();
|
|
710
|
-
case
|
|
714
|
+
case 6:
|
|
711
715
|
jest.advanceTimersByTime(_constants.REG_TRY_BACKUP_TIMER_VAL_IN_SEC * _constants.SEC_TO_MSEC_MFACTOR);
|
|
712
|
-
_context13.next =
|
|
716
|
+
_context13.next = 9;
|
|
713
717
|
return flushPromises();
|
|
714
|
-
case
|
|
718
|
+
case 9:
|
|
715
719
|
reg.rehomingIntervalMin = _constants.DEFAULT_REHOMING_INTERVAL_MIN;
|
|
716
720
|
reg.rehomingIntervalMax = _constants.DEFAULT_REHOMING_INTERVAL_MAX;
|
|
717
721
|
|
|
@@ -721,7 +725,7 @@ describe('Registration Tests', function () {
|
|
|
721
725
|
/* Active Url must match with the backup url as per the test */
|
|
722
726
|
expect(reg.getActiveMobiusUrl()).toStrictEqual(mobiusUris.backup[0]);
|
|
723
727
|
expect(reg.getStatus()).toEqual(_types.RegistrationStatus.ACTIVE);
|
|
724
|
-
case
|
|
728
|
+
case 14:
|
|
725
729
|
case "end":
|
|
726
730
|
return _context13.stop();
|
|
727
731
|
}
|
|
@@ -876,13 +880,14 @@ describe('Registration Tests', function () {
|
|
|
876
880
|
});
|
|
877
881
|
|
|
878
882
|
/* Active Url must now match with the primary url */
|
|
883
|
+
expect(deregisterSpy).toBeCalledOnceWith();
|
|
879
884
|
expect(reg.getActiveMobiusUrl()).toStrictEqual(mobiusUris.primary[0]);
|
|
880
885
|
expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
|
|
881
886
|
expect(reg.failbackTimer).toBe(undefined);
|
|
882
887
|
expect(restoreSpy).not.toBeCalled();
|
|
883
888
|
expect(reg.rehomingIntervalMin).toBe(_registerFixtures.mockPostResponse.rehomingIntervalMin);
|
|
884
889
|
expect(reg.rehomingIntervalMax).toBe(_registerFixtures.mockPostResponse.rehomingIntervalMax);
|
|
885
|
-
case
|
|
890
|
+
case 12:
|
|
886
891
|
case "end":
|
|
887
892
|
return _context18.stop();
|
|
888
893
|
}
|
|
@@ -902,7 +907,7 @@ describe('Registration Tests', function () {
|
|
|
902
907
|
_context19.next = 6;
|
|
903
908
|
return flushPromises();
|
|
904
909
|
case 6:
|
|
905
|
-
expect(infoSpy).toBeCalledWith("Active calls present, deferring failback to next cycle.", {
|
|
910
|
+
expect(infoSpy).toBeCalledWith("Active calls present or primary Mobius is down, deferring failback to next cycle.", {
|
|
906
911
|
method: 'executeFailback',
|
|
907
912
|
file: _constants.REGISTRATION_FILE
|
|
908
913
|
});
|
|
@@ -910,415 +915,417 @@ describe('Registration Tests', function () {
|
|
|
910
915
|
/* Active Url should still match backup url */
|
|
911
916
|
expect(reg.getActiveMobiusUrl()).toStrictEqual(mobiusUris.backup[0]);
|
|
912
917
|
expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
|
|
918
|
+
expect(deregisterSpy).not.toBeCalled();
|
|
913
919
|
expect(restoreSpy).not.toBeCalled();
|
|
914
920
|
expect(restartSpy).not.toBeCalled();
|
|
915
|
-
expect(infoSpy).toBeCalledWith('Active calls present, deferring failback to next cycle.', {
|
|
921
|
+
expect(infoSpy).toBeCalledWith('Active calls present or primary Mobius is down, deferring failback to next cycle.', {
|
|
916
922
|
file: _constants.REGISTRATION_FILE,
|
|
917
923
|
method: _constants.FAILBACK_UTIL
|
|
918
924
|
});
|
|
919
925
|
expect(reg.rehomingIntervalMin).toBe(_constants.DEFAULT_REHOMING_INTERVAL_MIN);
|
|
920
926
|
expect(reg.rehomingIntervalMax).toBe(_constants.DEFAULT_REHOMING_INTERVAL_MAX);
|
|
921
|
-
case
|
|
927
|
+
case 15:
|
|
922
928
|
case "end":
|
|
923
929
|
return _context19.stop();
|
|
924
930
|
}
|
|
925
931
|
}, _callee19);
|
|
926
932
|
})));
|
|
933
|
+
it('verify unsuccessful failback attempt due to primary server being down', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee20() {
|
|
934
|
+
return _regenerator.default.wrap(function _callee20$(_context20) {
|
|
935
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
936
|
+
case 0:
|
|
937
|
+
isPrimaryActiveSpy.mockReturnValue(false);
|
|
938
|
+
|
|
939
|
+
/* Wait for failback to be triggered. */
|
|
940
|
+
jest.advanceTimersByTime(reg.rehomingIntervalMax * _constants.MINUTES_TO_SEC_MFACTOR * _constants.SEC_TO_MSEC_MFACTOR);
|
|
941
|
+
_context20.next = 4;
|
|
942
|
+
return flushPromises();
|
|
943
|
+
case 4:
|
|
944
|
+
expect(infoSpy).toBeCalledWith("Active calls present or primary Mobius is down, deferring failback to next cycle.", {
|
|
945
|
+
method: 'executeFailback',
|
|
946
|
+
file: _constants.REGISTRATION_FILE
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
/* Active Url should still match backup url */
|
|
950
|
+
expect(deregisterSpy).not.toBeCalled();
|
|
951
|
+
expect(reg.getActiveMobiusUrl()).toStrictEqual(mobiusUris.backup[0]);
|
|
952
|
+
expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
|
|
953
|
+
case 8:
|
|
954
|
+
case "end":
|
|
955
|
+
return _context20.stop();
|
|
956
|
+
}
|
|
957
|
+
}, _callee20);
|
|
958
|
+
})));
|
|
927
959
|
});
|
|
928
960
|
|
|
929
961
|
// Keep-alive related test cases
|
|
930
962
|
describe('Keep-alive Tests', function () {
|
|
931
|
-
var logObj = {
|
|
932
|
-
file: _constants.REGISTRATION_FILE,
|
|
933
|
-
method: 'startKeepaliveTimer'
|
|
934
|
-
};
|
|
935
|
-
var mockKeepAliveBody = {
|
|
936
|
-
device: _registerFixtures.mockPostResponse.device
|
|
937
|
-
};
|
|
938
963
|
var beforeEachSetupForKeepalive = /*#__PURE__*/function () {
|
|
939
|
-
var
|
|
940
|
-
return _regenerator.default.wrap(function
|
|
941
|
-
while (1) switch (
|
|
964
|
+
var _ref21 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee21() {
|
|
965
|
+
return _regenerator.default.wrap(function _callee21$(_context21) {
|
|
966
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
942
967
|
case 0:
|
|
943
968
|
postRegistrationSpy.mockResolvedValueOnce(successPayload);
|
|
944
969
|
jest.useFakeTimers();
|
|
945
|
-
|
|
970
|
+
_context21.next = 4;
|
|
946
971
|
return reg.triggerRegistration();
|
|
947
972
|
case 4:
|
|
948
973
|
expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
|
|
949
|
-
|
|
974
|
+
expect(reg.webWorker).toBeDefined();
|
|
975
|
+
case 6:
|
|
950
976
|
case "end":
|
|
951
|
-
return
|
|
977
|
+
return _context21.stop();
|
|
952
978
|
}
|
|
953
|
-
},
|
|
979
|
+
}, _callee21);
|
|
954
980
|
}));
|
|
955
981
|
return function beforeEachSetupForKeepalive() {
|
|
956
|
-
return
|
|
982
|
+
return _ref21.apply(this, arguments);
|
|
957
983
|
};
|
|
958
984
|
}();
|
|
959
985
|
afterEach(function () {
|
|
960
986
|
jest.clearAllTimers();
|
|
961
987
|
jest.clearAllMocks();
|
|
962
|
-
|
|
963
|
-
clearInterval(reg.keepaliveTimer);
|
|
964
|
-
reg.keepaliveTimer = undefined;
|
|
965
|
-
}
|
|
988
|
+
reg.clearKeepaliveTimer();
|
|
966
989
|
reg.reconnectPending = false;
|
|
967
990
|
var calls = (0, _values.default)(reg.callManager.getActiveCalls());
|
|
968
991
|
calls.forEach(function (call) {
|
|
969
992
|
call.end();
|
|
970
993
|
});
|
|
971
994
|
});
|
|
972
|
-
it('verify successful keep-alive cases', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
973
|
-
var
|
|
974
|
-
return _regenerator.default.wrap(function _callee21$(_context21) {
|
|
975
|
-
while (1) switch (_context21.prev = _context21.next) {
|
|
976
|
-
case 0:
|
|
977
|
-
_context21.next = 2;
|
|
978
|
-
return beforeEachSetupForKeepalive();
|
|
979
|
-
case 2:
|
|
980
|
-
keepAlivePayload = {
|
|
981
|
-
statusCode: 200,
|
|
982
|
-
body: mockKeepAliveBody
|
|
983
|
-
};
|
|
984
|
-
webex.request.mockReturnValue(keepAlivePayload);
|
|
985
|
-
funcSpy = jest.spyOn(reg, 'postKeepAlive');
|
|
986
|
-
jest.advanceTimersByTime(2 * _registerFixtures.mockPostResponse.keepaliveInterval * _constants.SEC_TO_MSEC_MFACTOR);
|
|
987
|
-
_context21.next = 8;
|
|
988
|
-
return flushPromises();
|
|
989
|
-
case 8:
|
|
990
|
-
expect(funcSpy).toBeCalledTimes(2); // should be called 2 times: first try and after the interval.
|
|
991
|
-
|
|
992
|
-
expect(logSpy).toBeCalledWith('Sent Keepalive, status: 200', logObj);
|
|
993
|
-
expect(infoSpy).not.toBeCalledWith('Sent Keepalive, status: 200', logObj);
|
|
994
|
-
case 11:
|
|
995
|
-
case "end":
|
|
996
|
-
return _context21.stop();
|
|
997
|
-
}
|
|
998
|
-
}, _callee21);
|
|
999
|
-
})));
|
|
1000
|
-
it('verify failure keep-alive cases: Retry Success', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee22() {
|
|
1001
|
-
var failurePayload, successPayload, timer;
|
|
995
|
+
it('verify successful keep-alive cases', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee22() {
|
|
996
|
+
var postMessageSpy;
|
|
1002
997
|
return _regenerator.default.wrap(function _callee22$(_context22) {
|
|
1003
998
|
while (1) switch (_context22.prev = _context22.next) {
|
|
1004
999
|
case 0:
|
|
1005
|
-
|
|
1000
|
+
postMessageSpy = jest.spyOn(Worker.prototype, 'postMessage');
|
|
1001
|
+
_context22.next = 3;
|
|
1006
1002
|
return beforeEachSetupForKeepalive();
|
|
1007
|
-
case
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
case 10:
|
|
1023
|
-
expect(handleErrorSpy).toBeCalledOnceWith(failurePayload, expect.anything(), {
|
|
1024
|
-
method: 'startKeepaliveTimer',
|
|
1025
|
-
file: _constants.REGISTRATION_FILE
|
|
1003
|
+
case 3:
|
|
1004
|
+
expect(reg.webWorker).toBeDefined();
|
|
1005
|
+
expect(postMessageSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
1006
|
+
type: 'START_KEEPALIVE',
|
|
1007
|
+
accessToken: expect.any(String),
|
|
1008
|
+
deviceUrl: expect.any(String),
|
|
1009
|
+
interval: expect.any(Number),
|
|
1010
|
+
retryCountThreshold: expect.any(Number),
|
|
1011
|
+
url: expect.any(String)
|
|
1012
|
+
}));
|
|
1013
|
+
reg.webWorker.onmessage({
|
|
1014
|
+
data: {
|
|
1015
|
+
type: 'KEEPALIVE_SUCCESS',
|
|
1016
|
+
statusCode: 200
|
|
1017
|
+
}
|
|
1026
1018
|
});
|
|
1027
|
-
expect(
|
|
1028
|
-
|
|
1029
|
-
expect(lineEmitter).nthCalledWith(1, _types4.LINE_EVENTS.RECONNECTING);
|
|
1030
|
-
expect(lineEmitter).nthCalledWith(2, _types4.LINE_EVENTS.RECONNECTED);
|
|
1031
|
-
expect(lineEmitter).toBeCalledTimes(2);
|
|
1032
|
-
case 16:
|
|
1019
|
+
expect(lineEmitter).toBeCalledWith(_types4.LINE_EVENTS.RECONNECTED);
|
|
1020
|
+
case 7:
|
|
1033
1021
|
case "end":
|
|
1034
1022
|
return _context22.stop();
|
|
1035
1023
|
}
|
|
1036
1024
|
}, _callee22);
|
|
1037
1025
|
})));
|
|
1038
|
-
it('verify failure keep-alive cases:
|
|
1039
|
-
var
|
|
1026
|
+
it('verify failure keep-alive cases: Retry Success', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee23() {
|
|
1027
|
+
var worker;
|
|
1040
1028
|
return _regenerator.default.wrap(function _callee23$(_context23) {
|
|
1041
1029
|
while (1) switch (_context23.prev = _context23.next) {
|
|
1042
1030
|
case 0:
|
|
1043
1031
|
_context23.next = 2;
|
|
1044
1032
|
return beforeEachSetupForKeepalive();
|
|
1045
1033
|
case 2:
|
|
1046
|
-
|
|
1047
|
-
restartRegSpy = jest.spyOn(reg, 'restartRegistration');
|
|
1048
|
-
reconnectSpy = jest.spyOn(reg, 'reconnectOnFailure');
|
|
1049
|
-
failurePayload = {
|
|
1050
|
-
statusCode: 503,
|
|
1051
|
-
body: mockKeepAliveBody
|
|
1052
|
-
};
|
|
1053
|
-
clearIntervalSpy = jest.spyOn(global, 'clearInterval');
|
|
1034
|
+
worker = reg.webWorker;
|
|
1054
1035
|
lineEmitter.mockClear();
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
expect(
|
|
1071
|
-
|
|
1072
|
-
expect(warnSpy).toHaveBeenCalledWith('Keep-alive missed 1 times. Status -> 503 ', expect.objectContaining({
|
|
1073
|
-
file: _constants.REGISTRATION_FILE,
|
|
1074
|
-
method: 'startKeepaliveTimer'
|
|
1075
|
-
}));
|
|
1076
|
-
expect(webex.request).toBeCalledTimes(7);
|
|
1077
|
-
expect(reg.keepaliveTimer).toBe(undefined);
|
|
1078
|
-
expect(warnSpy).toHaveBeenCalledWith('Keep-alive missed 1 times. Status -> 503 ', expect.objectContaining({
|
|
1079
|
-
file: _constants.REGISTRATION_FILE,
|
|
1080
|
-
method: 'startKeepaliveTimer'
|
|
1081
|
-
}));
|
|
1082
|
-
expect(lineEmitter).nthCalledWith(1, _types4.LINE_EVENTS.RECONNECTING);
|
|
1083
|
-
expect(lineEmitter).nthCalledWith(4, _types4.LINE_EVENTS.RECONNECTING);
|
|
1084
|
-
expect(lineEmitter).nthCalledWith(5, _types4.LINE_EVENTS.UNREGISTERED);
|
|
1085
|
-
|
|
1086
|
-
/** there will be 2 registration attempts */
|
|
1087
|
-
expect(lineEmitter).nthCalledWith(6, _types4.LINE_EVENTS.CONNECTING);
|
|
1088
|
-
expect(lineEmitter).nthCalledWith(7, _types4.LINE_EVENTS.UNREGISTERED);
|
|
1089
|
-
expect(lineEmitter).nthCalledWith(8, _types4.LINE_EVENTS.CONNECTING);
|
|
1090
|
-
expect(lineEmitter).nthCalledWith(9, _types4.LINE_EVENTS.UNREGISTERED);
|
|
1091
|
-
expect(lineEmitter).toBeCalledTimes(9);
|
|
1092
|
-
case 33:
|
|
1036
|
+
worker.onmessage({
|
|
1037
|
+
data: {
|
|
1038
|
+
type: 'KEEPALIVE_FAILURE',
|
|
1039
|
+
err: {
|
|
1040
|
+
statusCode: 503
|
|
1041
|
+
},
|
|
1042
|
+
keepAliveRetryCount: 1
|
|
1043
|
+
}
|
|
1044
|
+
});
|
|
1045
|
+
worker.onmessage({
|
|
1046
|
+
data: {
|
|
1047
|
+
type: 'KEEPALIVE_SUCCESS',
|
|
1048
|
+
statusCode: 200
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.RECONNECTED);
|
|
1052
|
+
case 7:
|
|
1093
1053
|
case "end":
|
|
1094
1054
|
return _context23.stop();
|
|
1095
1055
|
}
|
|
1096
1056
|
}, _callee23);
|
|
1097
1057
|
})));
|
|
1098
|
-
it('verify failure keep-alive cases: Restore
|
|
1099
|
-
var
|
|
1058
|
+
it('verify failure keep-alive cases: Restore failure', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee24() {
|
|
1059
|
+
var reconnectSpy, restoreSpy, restartRegSpy, RETRY_COUNT_THRESHOLD, failureEvent;
|
|
1100
1060
|
return _regenerator.default.wrap(function _callee24$(_context24) {
|
|
1101
1061
|
while (1) switch (_context24.prev = _context24.next) {
|
|
1102
1062
|
case 0:
|
|
1103
1063
|
_context24.next = 2;
|
|
1104
1064
|
return beforeEachSetupForKeepalive();
|
|
1105
1065
|
case 2:
|
|
1106
|
-
restoreSpy = jest.spyOn(reg, 'restorePreviousRegistration');
|
|
1107
|
-
restartRegSpy = jest.spyOn(reg, 'restartRegistration');
|
|
1108
1066
|
reconnectSpy = jest.spyOn(reg, 'reconnectOnFailure');
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
};
|
|
1113
|
-
successPayload = {
|
|
1114
|
-
statusCode: 200,
|
|
1115
|
-
body: mockKeepAliveBody
|
|
1116
|
-
};
|
|
1117
|
-
clearIntervalSpy = jest.spyOn(global, 'clearInterval');
|
|
1118
|
-
webex.request.mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockResolvedValue(successPayload);
|
|
1119
|
-
|
|
1120
|
-
/* successful registration */
|
|
1121
|
-
// webex.request.mockResolvedValue(successPayload);
|
|
1067
|
+
restoreSpy = jest.spyOn(reg, 'restorePreviousRegistration');
|
|
1068
|
+
restartRegSpy = jest.spyOn(reg, 'restartRegistration'); // Clear previous event emissions
|
|
1069
|
+
lineEmitter.mockClear();
|
|
1122
1070
|
|
|
1071
|
+
// Assume registration is active
|
|
1123
1072
|
expect(reg.getStatus()).toEqual(_types.RegistrationStatus.ACTIVE);
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1073
|
+
|
|
1074
|
+
// Use fake timers to trigger keepalive initialization
|
|
1075
|
+
jest.useFakeTimers();
|
|
1076
|
+
jest.advanceTimersByTime(_registerFixtures.mockPostResponse.keepaliveInterval * _constants.SEC_TO_MSEC_MFACTOR);
|
|
1077
|
+
|
|
1078
|
+
// Simulate the worker sending a KEEPALIVE_FAILURE message with retry count at threshold.
|
|
1079
|
+
RETRY_COUNT_THRESHOLD = reg.isCCFlow ? 4 : 5;
|
|
1080
|
+
failureEvent = {
|
|
1081
|
+
data: {
|
|
1082
|
+
type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
|
|
1083
|
+
err: {
|
|
1084
|
+
statusCode: 503
|
|
1085
|
+
},
|
|
1086
|
+
keepAliveRetryCount: RETRY_COUNT_THRESHOLD
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
reg.webWorker.onmessage(failureEvent);
|
|
1090
|
+
_context24.next = 14;
|
|
1130
1091
|
return flushPromises();
|
|
1131
|
-
case
|
|
1132
|
-
expect(
|
|
1133
|
-
expect(
|
|
1134
|
-
expect(reg.getStatus()).toEqual(_types.RegistrationStatus.ACTIVE);
|
|
1092
|
+
case 14:
|
|
1093
|
+
expect(reg.getStatus()).toEqual(_types.RegistrationStatus.INACTIVE);
|
|
1094
|
+
expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
|
|
1135
1095
|
expect(reconnectSpy).toBeCalledOnceWith(_constants.KEEPALIVE_UTIL);
|
|
1136
1096
|
expect(restoreSpy).toBeCalledOnceWith(_constants.KEEPALIVE_UTIL);
|
|
1137
|
-
expect(restartRegSpy).
|
|
1138
|
-
|
|
1139
|
-
expect(
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1097
|
+
expect(restartRegSpy).toBeCalledOnceWith(_constants.KEEPALIVE_UTIL);
|
|
1098
|
+
jest.useRealTimers();
|
|
1099
|
+
expect(warnSpy).toHaveBeenCalledWith('Keep-alive missed 5 times. Status -> 503 ', expect.objectContaining({
|
|
1100
|
+
file: _constants.REGISTRATION_FILE,
|
|
1101
|
+
method: 'startKeepaliveTimer'
|
|
1102
|
+
}));
|
|
1103
|
+
case 21:
|
|
1143
1104
|
case "end":
|
|
1144
1105
|
return _context24.stop();
|
|
1145
1106
|
}
|
|
1146
1107
|
}, _callee24);
|
|
1147
1108
|
})));
|
|
1148
|
-
it('verify failure
|
|
1149
|
-
var
|
|
1109
|
+
it('verify failure keep-alive cases: Restore Success', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee25() {
|
|
1110
|
+
var reconnectSpy, url;
|
|
1150
1111
|
return _regenerator.default.wrap(function _callee25$(_context25) {
|
|
1151
1112
|
while (1) switch (_context25.prev = _context25.next) {
|
|
1152
1113
|
case 0:
|
|
1153
1114
|
_context25.next = 2;
|
|
1154
1115
|
return beforeEachSetupForKeepalive();
|
|
1155
1116
|
case 2:
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
jest.advanceTimersByTime(
|
|
1169
|
-
_context25.next =
|
|
1117
|
+
expect(reg.webWorker).toBeDefined();
|
|
1118
|
+
reconnectSpy = jest.spyOn(reg, 'reconnectOnFailure');
|
|
1119
|
+
url = 'https://mobius-dfw.webex.com/api/v1/calling/web/';
|
|
1120
|
+
reg.webWorker.onmessage({
|
|
1121
|
+
data: {
|
|
1122
|
+
type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
|
|
1123
|
+
err: {
|
|
1124
|
+
statusCode: 503
|
|
1125
|
+
},
|
|
1126
|
+
keepAliveRetryCount: 5
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
jest.advanceTimersByTime(1000);
|
|
1130
|
+
_context25.next = 9;
|
|
1131
|
+
return flushPromises();
|
|
1132
|
+
case 9:
|
|
1133
|
+
expect(reg.webWorker).toBeUndefined();
|
|
1134
|
+
expect(reconnectSpy).toBeCalledOnceWith(reg.startKeepaliveTimer.name);
|
|
1135
|
+
webex.request.mockResolvedValueOnce(successPayload);
|
|
1136
|
+
_context25.next = 14;
|
|
1137
|
+
return reg.triggerRegistration();
|
|
1138
|
+
case 14:
|
|
1139
|
+
_context25.next = 16;
|
|
1170
1140
|
return flushPromises();
|
|
1171
|
-
case 11:
|
|
1172
|
-
expect(webex.request).toBeCalledTimes(3);
|
|
1173
|
-
expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
|
|
1174
|
-
expect(handleErrorSpy).toBeCalledTimes(2);
|
|
1175
|
-
expect(clearIntervalSpy).not.toBeCalled();
|
|
1176
|
-
expect(reg.keepaliveTimer).toBe(timer);
|
|
1177
1141
|
case 16:
|
|
1142
|
+
expect(reg.webWorker).toBeDefined();
|
|
1143
|
+
reg.webWorker.onmessage({
|
|
1144
|
+
data: {
|
|
1145
|
+
type: _types.WorkerMessageType.KEEPALIVE_SUCCESS,
|
|
1146
|
+
statusCode: 200
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
// Advance timers and flush any remaining promises.
|
|
1151
|
+
jest.advanceTimersByTime(1000);
|
|
1152
|
+
_context25.next = 21;
|
|
1153
|
+
return flushPromises();
|
|
1154
|
+
case 21:
|
|
1155
|
+
expect(reg.getStatus()).toEqual(_types.RegistrationStatus.ACTIVE);
|
|
1156
|
+
// reconnectSpy should have been called only once.
|
|
1157
|
+
expect(reconnectSpy).toBeCalledTimes(1);
|
|
1158
|
+
expect(restoreSpy).toBeCalledOnceWith(reg.startKeepaliveTimer.name);
|
|
1159
|
+
expect(restartSpy).toBeCalledOnceWith(reg.startKeepaliveTimer.name);
|
|
1160
|
+
// Active Mobius URL should remain unchanged.
|
|
1161
|
+
expect(reg.getActiveMobiusUrl()).toStrictEqual(url);
|
|
1162
|
+
case 26:
|
|
1178
1163
|
case "end":
|
|
1179
1164
|
return _context25.stop();
|
|
1180
1165
|
}
|
|
1181
1166
|
}, _callee25);
|
|
1182
1167
|
})));
|
|
1183
|
-
it('
|
|
1184
|
-
var failurePayload, successPayload, clearIntervalSpy, timer;
|
|
1168
|
+
it('verify failure followed by recovery of keepalive', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee26() {
|
|
1185
1169
|
return _regenerator.default.wrap(function _callee26$(_context26) {
|
|
1186
1170
|
while (1) switch (_context26.prev = _context26.next) {
|
|
1187
1171
|
case 0:
|
|
1188
|
-
|
|
1189
|
-
setupRegistration(_objectSpread(_objectSpread({}, MockServiceData), {}, {
|
|
1190
|
-
indicator: _types.ServiceIndicator.CONTACT_CENTER
|
|
1191
|
-
}));
|
|
1192
|
-
_context26.next = 3;
|
|
1172
|
+
_context26.next = 2;
|
|
1193
1173
|
return beforeEachSetupForKeepalive();
|
|
1194
|
-
case
|
|
1195
|
-
failurePayload = {
|
|
1196
|
-
statusCode: 503,
|
|
1197
|
-
body: mockKeepAliveBody
|
|
1198
|
-
};
|
|
1199
|
-
successPayload = {
|
|
1200
|
-
statusCode: 200,
|
|
1201
|
-
body: mockKeepAliveBody
|
|
1202
|
-
};
|
|
1203
|
-
clearIntervalSpy = jest.spyOn(global, 'clearInterval');
|
|
1204
|
-
jest.spyOn(reg, 'postKeepAlive').mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockResolvedValue(successPayload);
|
|
1174
|
+
case 2:
|
|
1205
1175
|
expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1176
|
+
expect(reg.webWorker).toBeDefined();
|
|
1177
|
+
webex.request.mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockResolvedValue(successPayload);
|
|
1178
|
+
reg.webWorker.onmessage({
|
|
1179
|
+
data: {
|
|
1180
|
+
type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
|
|
1181
|
+
err: failurePayload,
|
|
1182
|
+
keepAliveRetryCount: reg.isCCFlow ? 4 : 5
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
_context26.next = 8;
|
|
1209
1186
|
return flushPromises();
|
|
1187
|
+
case 8:
|
|
1188
|
+
expect(reg.webWorker).toBeUndefined();
|
|
1189
|
+
expect(handleErrorSpy).toBeCalledTimes(3);
|
|
1190
|
+
_context26.next = 12;
|
|
1191
|
+
return reg.triggerRegistration();
|
|
1210
1192
|
case 12:
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1193
|
+
_context26.next = 14;
|
|
1194
|
+
return flushPromises();
|
|
1195
|
+
case 14:
|
|
1196
|
+
expect(reg.webWorker).toBeDefined();
|
|
1197
|
+
reg.webWorker.onmessage({
|
|
1198
|
+
data: {
|
|
1199
|
+
type: _types.WorkerMessageType.KEEPALIVE_SUCCESS,
|
|
1200
|
+
statusCode: 200
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
_context26.next = 18;
|
|
1204
|
+
return flushPromises();
|
|
1205
|
+
case 18:
|
|
1206
|
+
// In a complete failure‐then-recovery scenario, we expect another failure event to have been handled.
|
|
1207
|
+
// For that, simulate a second failure event on the new worker.
|
|
1208
|
+
reg.webWorker.onmessage({
|
|
1209
|
+
data: {
|
|
1210
|
+
type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
|
|
1211
|
+
err: failurePayload,
|
|
1212
|
+
keepAliveRetryCount: reg.isCCFlow ? 4 : 5
|
|
1213
|
+
}
|
|
1214
|
+
});
|
|
1215
|
+
_context26.next = 21;
|
|
1217
1216
|
return flushPromises();
|
|
1218
|
-
case 19:
|
|
1219
|
-
/* Active Url must match with the backup url as per the test */
|
|
1220
|
-
expect(reg.getActiveMobiusUrl()).toEqual(mobiusUris.backup[0]);
|
|
1221
|
-
expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
|
|
1222
1217
|
case 21:
|
|
1218
|
+
expect(handleErrorSpy).toBeCalledTimes(4);
|
|
1219
|
+
|
|
1220
|
+
// And then re-register successfully:
|
|
1221
|
+
_context26.next = 24;
|
|
1222
|
+
return reg.triggerRegistration();
|
|
1223
|
+
case 24:
|
|
1224
|
+
_context26.next = 26;
|
|
1225
|
+
return flushPromises();
|
|
1226
|
+
case 26:
|
|
1227
|
+
expect(reg.webWorker).toBeDefined();
|
|
1228
|
+
reg.webWorker.onmessage({
|
|
1229
|
+
data: {
|
|
1230
|
+
type: _types.WorkerMessageType.KEEPALIVE_SUCCESS,
|
|
1231
|
+
statusCode: 200
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
_context26.next = 30;
|
|
1235
|
+
return flushPromises();
|
|
1236
|
+
case 30:
|
|
1237
|
+
expect(reg.getStatus()).toEqual(_types.RegistrationStatus.ACTIVE);
|
|
1238
|
+
expect(reg.webWorker).toBeDefined();
|
|
1239
|
+
case 32:
|
|
1223
1240
|
case "end":
|
|
1224
1241
|
return _context26.stop();
|
|
1225
1242
|
}
|
|
1226
1243
|
}, _callee26);
|
|
1227
1244
|
})));
|
|
1228
|
-
it('verify
|
|
1229
|
-
var
|
|
1245
|
+
it('cc: verify failover to backup server after 4 keep alive failure with primary server', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee27() {
|
|
1246
|
+
var clearKeepaliveSpy, reconnectSpy;
|
|
1230
1247
|
return _regenerator.default.wrap(function _callee27$(_context27) {
|
|
1231
1248
|
while (1) switch (_context27.prev = _context27.next) {
|
|
1232
1249
|
case 0:
|
|
1233
|
-
|
|
1250
|
+
// Register with contact center service
|
|
1251
|
+
setupRegistration(_objectSpread(_objectSpread({}, MockServiceData), {}, {
|
|
1252
|
+
indicator: _types.ServiceIndicator.CONTACT_CENTER
|
|
1253
|
+
}));
|
|
1254
|
+
_context27.next = 3;
|
|
1234
1255
|
return beforeEachSetupForKeepalive();
|
|
1235
|
-
case
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
};
|
|
1243
|
-
clearIntervalSpy = jest.spyOn(global, 'clearInterval');
|
|
1244
|
-
webex.request.mockRejectedValue(failurePayload);
|
|
1245
|
-
expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
|
|
1256
|
+
case 3:
|
|
1257
|
+
webex.request.mockResolvedValueOnce(successPayload);
|
|
1258
|
+
_context27.next = 6;
|
|
1259
|
+
return reg.triggerRegistration();
|
|
1260
|
+
case 6:
|
|
1261
|
+
expect(reg.getStatus()).toEqual(_types.RegistrationStatus.ACTIVE);
|
|
1262
|
+
expect(reg.webWorker).toBeDefined();
|
|
1246
1263
|
|
|
1247
|
-
|
|
1248
|
-
jest.
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
expect(webex.request).toBeCalledOnceWith({
|
|
1259
|
-
headers: mockResponse.headers,
|
|
1260
|
-
uri: "".concat(mockKeepAliveBody.device.uri, "/status"),
|
|
1261
|
-
method: 'POST',
|
|
1262
|
-
service: mockResponse.service
|
|
1263
|
-
});
|
|
1264
|
-
expect(reg.keepaliveTimer).toBe(undefined);
|
|
1265
|
-
expect(handleErrorSpy).toBeCalledOnceWith(failurePayload, expect.anything(), {
|
|
1266
|
-
file: _constants.REGISTRATION_FILE,
|
|
1267
|
-
method: _constants.KEEPALIVE_UTIL
|
|
1264
|
+
// Spy on clearKeepaliveTimer and simulate reconnectOnFailure behavior
|
|
1265
|
+
clearKeepaliveSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
|
|
1266
|
+
reconnectSpy = jest.spyOn(reg, 'reconnectOnFailure'); // Simulate a KEEPALIVE_FAILURE message from the worker with a retry count equal to threshold (4 for CC)
|
|
1267
|
+
reg.webWorker.onmessage({
|
|
1268
|
+
data: {
|
|
1269
|
+
type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
|
|
1270
|
+
err: {
|
|
1271
|
+
statusCode: 503
|
|
1272
|
+
},
|
|
1273
|
+
keepAliveRetryCount: 4
|
|
1274
|
+
}
|
|
1268
1275
|
});
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
case
|
|
1276
|
+
|
|
1277
|
+
// Wait for any asynchronous actions to complete
|
|
1278
|
+
_context27.next = 13;
|
|
1279
|
+
return flushPromises();
|
|
1280
|
+
case 13:
|
|
1281
|
+
// Verify that the keepalive timer was cleared and reconnectOnFailure was triggered
|
|
1282
|
+
expect(clearKeepaliveSpy).toHaveBeenCalled();
|
|
1283
|
+
expect(reconnectSpy).toHaveBeenCalledWith(reg.startKeepaliveTimer.name);
|
|
1284
|
+
|
|
1285
|
+
// Verify that the active Mobius URL has been updated to the backup server and registration is active
|
|
1286
|
+
expect(reg.getActiveMobiusUrl()).toEqual(mobiusUris.backup[0]);
|
|
1287
|
+
expect(reg.getStatus()).toEqual(_types.RegistrationStatus.ACTIVE);
|
|
1288
|
+
case 17:
|
|
1274
1289
|
case "end":
|
|
1275
1290
|
return _context27.stop();
|
|
1276
1291
|
}
|
|
1277
1292
|
}, _callee27);
|
|
1278
1293
|
})));
|
|
1279
1294
|
it('verify failure keep-alive case with active call present: Restore Success after call ends', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee28() {
|
|
1280
|
-
var
|
|
1295
|
+
var reconnectSpy, restoreSpy, restartRegSpy, clearTimerSpy, threshold, failureEvent;
|
|
1281
1296
|
return _regenerator.default.wrap(function _callee28$(_context28) {
|
|
1282
1297
|
while (1) switch (_context28.prev = _context28.next) {
|
|
1283
1298
|
case 0:
|
|
1284
1299
|
_context28.next = 2;
|
|
1285
1300
|
return beforeEachSetupForKeepalive();
|
|
1286
1301
|
case 2:
|
|
1287
|
-
restoreSpy = jest.spyOn(reg, 'restorePreviousRegistration');
|
|
1288
|
-
restartRegSpy = jest.spyOn(reg, 'restartRegistration');
|
|
1289
1302
|
reconnectSpy = jest.spyOn(reg, 'reconnectOnFailure');
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
};
|
|
1294
|
-
successPayload = {
|
|
1295
|
-
statusCode: 200,
|
|
1296
|
-
body: mockKeepAliveBody
|
|
1297
|
-
};
|
|
1298
|
-
clearIntervalSpy = jest.spyOn(global, 'clearInterval');
|
|
1299
|
-
webex.request.mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockRejectedValueOnce(failurePayload).mockResolvedValue(successPayload);
|
|
1300
|
-
|
|
1301
|
-
// jest.spyOn(callingClient['registration'], 'createDevice').mockResolvedValue(successPayload);
|
|
1302
|
-
url = 'https://mobius.asydm-m-1.prod.infra.webex.com/api/v1';
|
|
1303
|
-
reg.setActiveMobiusUrl(url);
|
|
1304
|
-
expect(reg.reconnectPending).toStrictEqual(false);
|
|
1305
|
-
timer = reg.keepaliveTimer;
|
|
1306
|
-
/* add a call to the callManager */
|
|
1307
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1308
|
-
call = reg.callManager.createCall();
|
|
1303
|
+
restoreSpy = jest.spyOn(reg, 'restorePreviousRegistration');
|
|
1304
|
+
restartRegSpy = jest.spyOn(reg, 'restartRegistration'); // Simulate an active call.
|
|
1305
|
+
reg.callManager.createCall();
|
|
1309
1306
|
expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(1);
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1307
|
+
clearTimerSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
|
|
1308
|
+
threshold = reg.isCCFlow ? 4 : 5; // Simulate a KEEPALIVE_FAILURE event with a 503 error at threshold.
|
|
1309
|
+
failureEvent = {
|
|
1310
|
+
data: {
|
|
1311
|
+
type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
|
|
1312
|
+
err: {
|
|
1313
|
+
statusCode: 503
|
|
1314
|
+
},
|
|
1315
|
+
keepAliveRetryCount: threshold
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
reg.webWorker.onmessage(failureEvent);
|
|
1319
|
+
_context28.next = 13;
|
|
1314
1320
|
return flushPromises();
|
|
1315
|
-
case
|
|
1316
|
-
|
|
1317
|
-
expect(
|
|
1321
|
+
case 13:
|
|
1322
|
+
// At this point, clearKeepaliveTimer was called so the worker is terminated.
|
|
1323
|
+
expect(clearTimerSpy).toHaveBeenCalled();
|
|
1324
|
+
expect(reg.webWorker).toBeUndefined();
|
|
1325
|
+
expect(reg.getStatus()).toEqual(_types.RegistrationStatus.INACTIVE);
|
|
1326
|
+
expect(lineEmitter).lastCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
|
|
1318
1327
|
expect(reg.keepaliveTimer).toStrictEqual(undefined);
|
|
1319
1328
|
expect(reg.failbackTimer).toStrictEqual(undefined);
|
|
1320
|
-
expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
|
|
1321
|
-
expect(lineEmitter).lastCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
|
|
1322
1329
|
expect(reconnectSpy).toBeCalledOnceWith(_constants.KEEPALIVE_UTIL);
|
|
1323
1330
|
expect(restoreSpy).not.toBeCalled();
|
|
1324
1331
|
expect(restartRegSpy).not.toBeCalled();
|
|
@@ -1329,26 +1336,131 @@ describe('Registration Tests', function () {
|
|
|
1329
1336
|
});
|
|
1330
1337
|
reconnectSpy.mockClear();
|
|
1331
1338
|
|
|
1332
|
-
|
|
1339
|
+
// Now simulate call cleanup.
|
|
1333
1340
|
reg.callManager.callCollection = {};
|
|
1334
|
-
|
|
1341
|
+
webex.request.mockResolvedValueOnce(successPayload);
|
|
1342
|
+
|
|
1343
|
+
// Call reconnectOnFailure manually. With no active calls, this should trigger re-registration.
|
|
1344
|
+
_context28.next = 29;
|
|
1335
1345
|
return reg.reconnectOnFailure(_constants.CALLS_CLEARED_HANDLER_UTIL);
|
|
1336
|
-
case
|
|
1346
|
+
case 29:
|
|
1347
|
+
_context28.next = 31;
|
|
1348
|
+
return flushPromises();
|
|
1349
|
+
case 31:
|
|
1337
1350
|
expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(0);
|
|
1338
|
-
|
|
1351
|
+
// After re-registration, registration status becomes ACTIVE and a new worker is created.
|
|
1352
|
+
expect(reg.getStatus()).toEqual(_types.RegistrationStatus.ACTIVE);
|
|
1353
|
+
expect(reg.webWorker).toBeDefined();
|
|
1339
1354
|
expect(reconnectSpy).toBeCalledOnceWith(_constants.CALLS_CLEARED_HANDLER_UTIL);
|
|
1340
1355
|
expect(restoreSpy).toBeCalledOnceWith(_constants.CALLS_CLEARED_HANDLER_UTIL);
|
|
1341
1356
|
expect(restartRegSpy).not.toBeCalled();
|
|
1342
1357
|
expect(reg.reconnectPending).toStrictEqual(false);
|
|
1343
|
-
|
|
1344
|
-
expect(reg.keepaliveTimer).toBeTruthy();
|
|
1345
|
-
expect(reg.keepaliveTimer).not.toBe(timer);
|
|
1346
|
-
case 42:
|
|
1358
|
+
case 38:
|
|
1347
1359
|
case "end":
|
|
1348
1360
|
return _context28.stop();
|
|
1349
1361
|
}
|
|
1350
1362
|
}, _callee28);
|
|
1351
1363
|
})));
|
|
1364
|
+
it('checks for keep-alive failure with final error: 404', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee29() {
|
|
1365
|
+
var reconnectSpy, restoreSpy, restartRegSpy, clearTimerSpy;
|
|
1366
|
+
return _regenerator.default.wrap(function _callee29$(_context29) {
|
|
1367
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
1368
|
+
case 0:
|
|
1369
|
+
_context29.next = 2;
|
|
1370
|
+
return beforeEachSetupForKeepalive();
|
|
1371
|
+
case 2:
|
|
1372
|
+
reconnectSpy = jest.spyOn(reg, 'reconnectOnFailure');
|
|
1373
|
+
restoreSpy = jest.spyOn(reg, 'restorePreviousRegistration');
|
|
1374
|
+
restartRegSpy = jest.spyOn(reg, 'restartRegistration');
|
|
1375
|
+
clearTimerSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
|
|
1376
|
+
jest.spyOn(utils, 'handleRegistrationErrors').mockResolvedValue(true);
|
|
1377
|
+
reg.webWorker.onmessage({
|
|
1378
|
+
data: {
|
|
1379
|
+
type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
|
|
1380
|
+
err: {
|
|
1381
|
+
statusCode: 404
|
|
1382
|
+
},
|
|
1383
|
+
keepAliveRetryCount: 1
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1386
|
+
_context29.next = 10;
|
|
1387
|
+
return flushPromises();
|
|
1388
|
+
case 10:
|
|
1389
|
+
expect(warnSpy).toBeCalledWith('Keep-alive missed 1 times. Status -> 404 ', expect.objectContaining({
|
|
1390
|
+
file: _constants.REGISTRATION_FILE,
|
|
1391
|
+
method: 'startKeepaliveTimer'
|
|
1392
|
+
}));
|
|
1393
|
+
expect(handleErrorSpy).toBeCalledOnceWith({
|
|
1394
|
+
statusCode: 404
|
|
1395
|
+
}, expect.anything(), {
|
|
1396
|
+
file: _constants.REGISTRATION_FILE,
|
|
1397
|
+
method: _constants.KEEPALIVE_UTIL
|
|
1398
|
+
});
|
|
1399
|
+
expect(reg.getStatus()).toEqual(_types.RegistrationStatus.INACTIVE);
|
|
1400
|
+
expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
|
|
1401
|
+
expect(clearTimerSpy).toBeCalledTimes(1);
|
|
1402
|
+
expect(reconnectSpy).not.toHaveBeenCalled();
|
|
1403
|
+
expect(restoreSpy).not.toHaveBeenCalled();
|
|
1404
|
+
expect(restartRegSpy).not.toHaveBeenCalled();
|
|
1405
|
+
expect(reg.reconnectPending).toStrictEqual(false);
|
|
1406
|
+
expect(reg.keepaliveTimer).toBe(undefined);
|
|
1407
|
+
expect(reg.webWorker).toBeUndefined();
|
|
1408
|
+
case 21:
|
|
1409
|
+
case "end":
|
|
1410
|
+
return _context29.stop();
|
|
1411
|
+
}
|
|
1412
|
+
}, _callee29);
|
|
1413
|
+
})));
|
|
1414
|
+
});
|
|
1415
|
+
describe('Primary server status checks', function () {
|
|
1416
|
+
it('success: primary server status to be up', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee30() {
|
|
1417
|
+
var pingSuccessPayload, status;
|
|
1418
|
+
return _regenerator.default.wrap(function _callee30$(_context30) {
|
|
1419
|
+
while (1) switch (_context30.prev = _context30.next) {
|
|
1420
|
+
case 0:
|
|
1421
|
+
pingSuccessPayload = {
|
|
1422
|
+
statusCode: 200
|
|
1423
|
+
};
|
|
1424
|
+
webex.request.mockResolvedValue(pingSuccessPayload);
|
|
1425
|
+
_context30.next = 4;
|
|
1426
|
+
return reg.isPrimaryActive();
|
|
1427
|
+
case 4:
|
|
1428
|
+
status = _context30.sent;
|
|
1429
|
+
expect(webex.request).toBeCalledWith(_objectSpread({
|
|
1430
|
+
method: 'GET',
|
|
1431
|
+
uri: "https://mobius-dfw.webex.com/api/v1/ping"
|
|
1432
|
+
}, (0, _testUtil.getMockRequestTemplate)()));
|
|
1433
|
+
expect(status).toEqual(true);
|
|
1434
|
+
case 7:
|
|
1435
|
+
case "end":
|
|
1436
|
+
return _context30.stop();
|
|
1437
|
+
}
|
|
1438
|
+
}, _callee30);
|
|
1439
|
+
})));
|
|
1440
|
+
it('failed: primary server status to be down', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee31() {
|
|
1441
|
+
var pingFailurePayload, status;
|
|
1442
|
+
return _regenerator.default.wrap(function _callee31$(_context31) {
|
|
1443
|
+
while (1) switch (_context31.prev = _context31.next) {
|
|
1444
|
+
case 0:
|
|
1445
|
+
pingFailurePayload = {
|
|
1446
|
+
statusCode: 500
|
|
1447
|
+
};
|
|
1448
|
+
webex.request.mockResolvedValue(pingFailurePayload);
|
|
1449
|
+
_context31.next = 4;
|
|
1450
|
+
return reg.isPrimaryActive();
|
|
1451
|
+
case 4:
|
|
1452
|
+
status = _context31.sent;
|
|
1453
|
+
expect(webex.request).toBeCalledWith(_objectSpread({
|
|
1454
|
+
method: 'GET',
|
|
1455
|
+
uri: "https://mobius-dfw.webex.com/api/v1/ping"
|
|
1456
|
+
}, (0, _testUtil.getMockRequestTemplate)()));
|
|
1457
|
+
expect(status).toEqual(false);
|
|
1458
|
+
case 7:
|
|
1459
|
+
case "end":
|
|
1460
|
+
return _context31.stop();
|
|
1461
|
+
}
|
|
1462
|
+
}, _callee31);
|
|
1463
|
+
})));
|
|
1352
1464
|
});
|
|
1353
1465
|
});
|
|
1354
1466
|
//# sourceMappingURL=register.test.js.map
|