@webex/plugin-meetings 3.12.0-next.50 → 3.12.0-next.52

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.
@@ -1,6 +1,7 @@
1
1
  import HashTreeParser, {
2
2
  LocusInfoUpdateType,
3
3
  MeetingEndedError,
4
+ LocusNotFoundError,
4
5
  } from '@webex/plugin-meetings/src/hashTree/hashTreeParser';
5
6
  import HashTree from '@webex/plugin-meetings/src/hashTree/hashTree';
6
7
  import {expect} from '@webex/test-helper-chai';
@@ -708,8 +709,11 @@ describe('HashTreeParser', () => {
708
709
  assert.notCalled(callback);
709
710
  });
710
711
 
711
- [404, 409].forEach((errorCode) => {
712
- it(`emits MeetingEndedError if getting visible datasets returns ${errorCode}`, async () => {
712
+ [
713
+ {errorCode: 404, expectedError: LocusNotFoundError},
714
+ {errorCode: 409, expectedError: MeetingEndedError},
715
+ ].forEach(({errorCode, expectedError}) => {
716
+ it(`throws ${expectedError.name} if getting visible datasets returns ${errorCode}`, async () => {
713
717
  const minimalInitialLocus = {
714
718
  dataSets: [],
715
719
  locus: null,
@@ -732,7 +736,6 @@ describe('HashTreeParser', () => {
732
736
  )
733
737
  .rejects(error);
734
738
 
735
- // initializeFromMessage should throw MeetingEndedError
736
739
  let thrownError;
737
740
  try {
738
741
  await parser.initializeFromMessage({
@@ -744,7 +747,7 @@ describe('HashTreeParser', () => {
744
747
  thrownError = e;
745
748
  }
746
749
 
747
- expect(thrownError).to.be.instanceOf(MeetingEndedError);
750
+ expect(thrownError).to.be.instanceOf(expectedError);
748
751
  });
749
752
  });
750
753
  });
@@ -1766,12 +1769,10 @@ describe('HashTreeParser', () => {
1766
1769
  });
1767
1770
  });
1768
1771
 
1769
- describe('emits MEETING_ENDED', () => {
1770
- [404, 409].forEach((statusCode) => {
1771
- it(`when /hashtree returns ${statusCode}`, async () => {
1772
+ describe('emits MEETING_ENDED when 409/2403004 is returned', () => {
1773
+ it('when /hashtree returns 409', async () => {
1772
1774
  const parser = createHashTreeParser();
1773
1775
 
1774
- // Send a message to trigger sync algorithm
1775
1776
  const message = {
1776
1777
  dataSets: [createDataSet('main', 16, 1100)],
1777
1778
  visibleDataSetsUrl,
@@ -1796,12 +1797,9 @@ describe('HashTreeParser', () => {
1796
1797
 
1797
1798
  const mainDataSetUrl = parser.dataSets.main.url;
1798
1799
 
1799
- // Mock getHashesFromLocus to reject with the sentinel error
1800
- const error: any = new Error(`Request failed with status ${statusCode}`);
1801
- error.statusCode = statusCode;
1802
- if (statusCode === 409) {
1803
- error.body = {errorCode: 2403004};
1804
- }
1800
+ const error: any = new Error('Request failed with status 409');
1801
+ error.statusCode = 409;
1802
+ error.body = {errorCode: 2403004};
1805
1803
  webexRequest
1806
1804
  .withArgs(
1807
1805
  sinon.match({
@@ -1811,13 +1809,10 @@ describe('HashTreeParser', () => {
1811
1809
  )
1812
1810
  .rejects(error);
1813
1811
 
1814
- // Trigger sync by advancing time
1815
1812
  await clock.tickAsync(1000);
1816
1813
 
1817
- // Verify callback was called with MEETING_ENDED
1818
1814
  assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.MEETING_ENDED});
1819
1815
 
1820
- // Verify all timers are stopped
1821
1816
  Object.values(parser.dataSets).forEach((ds: any) => {
1822
1817
  assert.isUndefined(ds.timer);
1823
1818
  assert.isUndefined(ds.heartbeatWatchdogTimer);
@@ -1827,10 +1822,9 @@ describe('HashTreeParser', () => {
1827
1822
  assert.notCalled(metricsStub);
1828
1823
  });
1829
1824
 
1830
- it(`when /sync returns ${statusCode}`, async () => {
1825
+ it('when /sync returns 409', async () => {
1831
1826
  const parser = createHashTreeParser();
1832
1827
 
1833
- // Send a message to trigger sync algorithm
1834
1828
  const message = {
1835
1829
  dataSets: [createDataSet('main', 16, 1100)],
1836
1830
  visibleDataSetsUrl,
@@ -1855,19 +1849,15 @@ describe('HashTreeParser', () => {
1855
1849
 
1856
1850
  const mainDataSetUrl = parser.dataSets.main.url;
1857
1851
 
1858
- // Mock getHashesFromLocus to succeed
1859
1852
  mockGetHashesFromLocusResponse(
1860
1853
  mainDataSetUrl,
1861
1854
  new Array(16).fill('00000000000000000000000000000000'),
1862
1855
  createDataSet('main', 16, 1101)
1863
1856
  );
1864
1857
 
1865
- // Mock sendSyncRequestToLocus to reject with the sentinel error
1866
- const error: any = new Error(`Request failed with status ${statusCode}`);
1867
- error.statusCode = statusCode;
1868
- if (statusCode === 409) {
1869
- error.body = {errorCode: 2403004};
1870
- }
1858
+ const error: any = new Error('Request failed with status 409');
1859
+ error.statusCode = 409;
1860
+ error.body = {errorCode: 2403004};
1871
1861
  webexRequest
1872
1862
  .withArgs(
1873
1863
  sinon.match({
@@ -1877,12 +1867,121 @@ describe('HashTreeParser', () => {
1877
1867
  )
1878
1868
  .rejects(error);
1879
1869
 
1880
- // Trigger sync by advancing time
1881
1870
  await clock.tickAsync(1000);
1882
1871
 
1883
- // Verify callback was called with MEETING_ENDED
1884
1872
  assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.MEETING_ENDED});
1885
1873
 
1874
+ Object.values(parser.dataSets).forEach((ds: any) => {
1875
+ assert.isUndefined(ds.timer);
1876
+ assert.isUndefined(ds.heartbeatWatchdogTimer);
1877
+ });
1878
+ });
1879
+ });
1880
+
1881
+ describe('emits LOCUS_NOT_FOUND and stops parser when 404 is returned', () => {
1882
+ it('when /hashtree returns 404', async () => {
1883
+ const parser = createHashTreeParser();
1884
+
1885
+ const message = {
1886
+ dataSets: [createDataSet('main', 16, 1100)],
1887
+ visibleDataSetsUrl,
1888
+ locusUrl,
1889
+ locusStateElements: [
1890
+ {
1891
+ htMeta: {
1892
+ elementId: {
1893
+ type: 'locus' as const,
1894
+ id: 0,
1895
+ version: 201,
1896
+ },
1897
+ dataSetNames: ['main'],
1898
+ },
1899
+ data: {info: {id: 'initial-update'}},
1900
+ },
1901
+ ],
1902
+ };
1903
+
1904
+ parser.handleMessage(message, 'initial message');
1905
+ callback.resetHistory();
1906
+
1907
+ const mainDataSetUrl = parser.dataSets.main.url;
1908
+
1909
+ const error: any = new Error('Request failed with status 404');
1910
+ error.statusCode = 404;
1911
+ webexRequest
1912
+ .withArgs(
1913
+ sinon.match({
1914
+ method: 'GET',
1915
+ uri: `${mainDataSetUrl}/hashtree`,
1916
+ })
1917
+ )
1918
+ .rejects(error);
1919
+
1920
+ await clock.tickAsync(1000);
1921
+
1922
+ assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.LOCUS_NOT_FOUND});
1923
+
1924
+ // Verify parser is stopped
1925
+ expect(parser.state).to.equal('stopped');
1926
+
1927
+ // Verify all timers are stopped
1928
+ Object.values(parser.dataSets).forEach((ds: any) => {
1929
+ assert.isUndefined(ds.timer);
1930
+ assert.isUndefined(ds.heartbeatWatchdogTimer);
1931
+ });
1932
+ });
1933
+
1934
+ it('when /sync returns 404', async () => {
1935
+ const parser = createHashTreeParser();
1936
+
1937
+ const message = {
1938
+ dataSets: [createDataSet('main', 16, 1100)],
1939
+ visibleDataSetsUrl,
1940
+ locusUrl,
1941
+ locusStateElements: [
1942
+ {
1943
+ htMeta: {
1944
+ elementId: {
1945
+ type: 'locus' as const,
1946
+ id: 0,
1947
+ version: 201,
1948
+ },
1949
+ dataSetNames: ['main'],
1950
+ },
1951
+ data: {info: {id: 'initial-update'}},
1952
+ },
1953
+ ],
1954
+ };
1955
+
1956
+ parser.handleMessage(message, 'initial message');
1957
+ callback.resetHistory();
1958
+
1959
+ const mainDataSetUrl = parser.dataSets.main.url;
1960
+
1961
+ mockGetHashesFromLocusResponse(
1962
+ mainDataSetUrl,
1963
+ new Array(16).fill('00000000000000000000000000000000'),
1964
+ createDataSet('main', 16, 1101)
1965
+ );
1966
+
1967
+ const error: any = new Error('Request failed with status 404');
1968
+ error.statusCode = 404;
1969
+ webexRequest
1970
+ .withArgs(
1971
+ sinon.match({
1972
+ method: 'POST',
1973
+ uri: `${mainDataSetUrl}/sync`,
1974
+ })
1975
+ )
1976
+ .rejects(error);
1977
+
1978
+ await clock.tickAsync(1000);
1979
+
1980
+ assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.LOCUS_NOT_FOUND});
1981
+
1982
+ // Verify parser is stopped
1983
+ expect(parser.state).to.equal('stopped');
1984
+
1886
1985
  // Verify all timers are stopped
1887
1986
  Object.values(parser.dataSets).forEach((ds: any) => {
1888
1987
  assert.isUndefined(ds.timer);
@@ -1892,7 +1991,6 @@ describe('HashTreeParser', () => {
1892
1991
  // Verify no sync failure metric was sent for end-meeting sentinel
1893
1992
  assert.notCalled(metricsStub);
1894
1993
  });
1895
- });
1896
1994
  });
1897
1995
 
1898
1996
  it('requests only mismatched hashes during sync', async () => {
@@ -2554,7 +2652,7 @@ describe('HashTreeParser', () => {
2554
2652
  expect(syncCalls[1].args[0].uri).to.equal(`${newAtdActiveDataSet.url}/sync`);
2555
2653
  });
2556
2654
 
2557
- it('emits MEETING_ENDED if async init of a new visible dataset fails with 404', async () => {
2655
+ it('emits LOCUS_NOT_FOUND if async init of a new visible dataset fails with 404', async () => {
2558
2656
  const parser = createHashTreeParser();
2559
2657
 
2560
2658
  // Stub updateItems on self hash tree to return true
@@ -2619,8 +2717,8 @@ describe('HashTreeParser', () => {
2619
2717
  // Wait for the async initialization (queueMicrotask) to complete
2620
2718
  await clock.tickAsync(0);
2621
2719
 
2622
- // Verify callback was called with MEETING_ENDED
2623
- assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.MEETING_ENDED});
2720
+ // Verify callback was called with LOCUS_NOT_FOUND (404 means locus URL is stale, not necessarily meeting ended)
2721
+ assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.LOCUS_NOT_FOUND});
2624
2722
  });
2625
2723
 
2626
2724
  it('handles removal of visible data set', async () => {
@@ -332,6 +332,7 @@ describe('plugin-meetings', () => {
332
332
  describe('should setup correct locusInfoUpdateCallback when creating HashTreeParser', () => {
333
333
  const OBJECTS_UPDATED = HashTreeParserModule.LocusInfoUpdateType.OBJECTS_UPDATED;
334
334
  const MEETING_ENDED = HashTreeParserModule.LocusInfoUpdateType.MEETING_ENDED;
335
+ const LOCUS_NOT_FOUND = HashTreeParserModule.LocusInfoUpdateType.LOCUS_NOT_FOUND;
335
336
 
336
337
  let locusInfoUpdateCallback;
337
338
  let onDeltaLocusStub;
@@ -1001,6 +1002,37 @@ describe('plugin-meetings', () => {
1001
1002
  assert.notCalled(destroyStub);
1002
1003
  });
1003
1004
 
1005
+ it('should handle LOCUS_NOT_FOUND by calling syncMeetings with skipHashTreeSync', () => {
1006
+ const syncMeetingsStub = sinon.stub(locusInfo.webex.meetings, 'syncMeetings').resolves();
1007
+
1008
+ locusInfoUpdateCallback({updateType: LOCUS_NOT_FOUND});
1009
+
1010
+ assert.calledOnceWithExactly(syncMeetingsStub, {keepOnlyLocusMeetings: false, skipHashTreeSync: true});
1011
+ });
1012
+
1013
+ it('should handle LOCUS_NOT_FOUND and log error if syncMeetings fails', async () => {
1014
+ const syncError = new Error('sync failed');
1015
+ const syncMeetingsStub = sinon.stub(locusInfo.webex.meetings, 'syncMeetings').rejects(syncError);
1016
+ const logErrorStub = LoggerProxy.logger.error?.isSinonProxy
1017
+ ? LoggerProxy.logger.error
1018
+ : sinon.stub(LoggerProxy.logger, 'error');
1019
+
1020
+ logErrorStub.resetHistory();
1021
+
1022
+ locusInfoUpdateCallback({updateType: LOCUS_NOT_FOUND});
1023
+
1024
+ assert.calledOnceWithExactly(syncMeetingsStub, {keepOnlyLocusMeetings: false, skipHashTreeSync: true});
1025
+
1026
+ // wait for the promise rejection to be handled
1027
+ await testUtils.flushPromises();
1028
+
1029
+ assert.calledOnce(logErrorStub);
1030
+ assert.match(
1031
+ logErrorStub.firstCall.args[0],
1032
+ /syncMeetings failed after LOCUS_NOT_FOUND/
1033
+ );
1034
+ });
1035
+
1004
1036
  it('should set forceReplaceMembers to true on the first update for a locusUrl (initializedFromHashTree is false)', () => {
1005
1037
  const createdHashTreeParser = locusInfo.hashTreeParsers.get('fake-locus-url');
1006
1038
  createdHashTreeParser.initializedFromHashTree = false;
@@ -1714,6 +1714,40 @@ describe('plugin-meetings', () => {
1714
1714
  });
1715
1715
  });
1716
1716
 
1717
+ describe('skipHashTreeSync parameter', () => {
1718
+ it('should skip syncAllHashTreeDatasets when skipHashTreeSync is true', async () => {
1719
+ const mockLocusInfo = {
1720
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
1721
+ };
1722
+
1723
+ webex.meetings.request.getActiveMeetings = sinon.stub().resolves({loci: []});
1724
+ webex.meetings.meetingCollection.getAll = sinon.stub().returns({
1725
+ meeting1: {locusInfo: mockLocusInfo},
1726
+ });
1727
+
1728
+ await webex.meetings.syncMeetings({keepOnlyLocusMeetings: false, skipHashTreeSync: true});
1729
+
1730
+ assert.calledOnce(webex.meetings.request.getActiveMeetings);
1731
+ assert.notCalled(mockLocusInfo.syncAllHashTreeDatasets);
1732
+ });
1733
+
1734
+ it('should call syncAllHashTreeDatasets when skipHashTreeSync is false (default)', async () => {
1735
+ const mockLocusInfo = {
1736
+ syncAllHashTreeDatasets: sinon.stub().resolves(),
1737
+ };
1738
+
1739
+ webex.meetings.request.getActiveMeetings = sinon.stub().resolves({loci: []});
1740
+ webex.meetings.meetingCollection.getAll = sinon.stub().returns({
1741
+ meeting1: {locusInfo: mockLocusInfo},
1742
+ });
1743
+
1744
+ await webex.meetings.syncMeetings({keepOnlyLocusMeetings: false, skipHashTreeSync: false});
1745
+
1746
+ assert.calledOnce(webex.meetings.request.getActiveMeetings);
1747
+ assert.calledOnce(mockLocusInfo.syncAllHashTreeDatasets);
1748
+ });
1749
+ });
1750
+
1717
1751
  describe('syncAllHashTreeDatasets in syncMeetings', () => {
1718
1752
  it('should call syncAllHashTreeDatasets for multiple meetings, skipping those without locusInfo', async () => {
1719
1753
  const mockLocusInfo1 = {