diff --git a/lib/report-portal-client.js b/lib/report-portal-client.js index e8fc193..659294b 100644 --- a/lib/report-portal-client.js +++ b/lib/report-portal-client.js @@ -53,8 +53,8 @@ class RPClient { }); this.statistics = new Statistics(EVENT_NAME, agentParams); this.launchUuid = ''; - this.executableItemMap = new Map(); - this.executableItemKeyMapByTempId = new Map(); + this.itemRetriesChainMap = new Map(); + this.itemRetriesChainKeyMapByTempId = new Map(); } // eslint-disable-next-line valid-jsdoc @@ -68,7 +68,7 @@ class RPClient { } } - calculateExecutableItemMapKey(launchId, parentId, name, itemId = '') { + calculateItemRetriesChainMapKey(launchId, parentId, name, itemId = '') { return `${launchId}__${parentId}__${name}__${itemId}`; } @@ -77,20 +77,15 @@ class RPClient { * * @Private */ - cleanExecutableItemKeyMapByTempId(ids) { - ids.forEach((id) => { - this.executableItemKeyMapByTempId.delete(id); - }); - } + cleanItemRetriesChain(tempIds) { + tempIds.forEach((id) => { + const key = this.itemRetriesChainKeyMapByTempId.get(id); - // eslint-disable-next-line valid-jsdoc - /** - * - * @Private - */ - cleanExecutableItemMap(ids) { - ids.forEach((id) => { - this.executableItemMap.delete(id); + if (key) { + this.itemRetriesChainMap.delete(key); + } + + this.itemRetriesChainKeyMapByTempId.delete(id); }); } @@ -511,13 +506,13 @@ class RPClient { parentPromise = parentObj.promiseStart; } - const itemKey = this.calculateExecutableItemMapKey( + const itemKey = this.calculateItemRetriesChainMapKey( launchTempId, parentTempId, testItemDataRQ.name, testItemDataRQ.uniqueId, ); - const executionItemPromise = testItemDataRQ.retry && this.executableItemMap.get(itemKey); + const executionItemPromise = testItemDataRQ.retry && this.itemRetriesChainMap.get(itemKey); const tempId = this.getUniqId(); this.map[tempId] = this.getNewItemObj((resolve, reject) => { @@ -550,8 +545,8 @@ class RPClient { ); }); this.map[parentMapId].children.push(tempId); - this.executableItemKeyMapByTempId.set(tempId, itemKey); - this.executableItemMap.set(itemKey, this.map[tempId].promiseStart); + this.itemRetriesChainKeyMapByTempId.set(tempId, itemKey); + this.itemRetriesChainMap.set(itemKey, this.map[tempId].promiseStart); return { tempId, @@ -619,13 +614,7 @@ class RPClient { } }); } - - const executableItemKeys = Array.from( - new Set(itemObj.children.map((tempId) => this.executableItemKeyMapByTempId.get(tempId))), - ); - - this.cleanExecutableItemMap(executableItemKeys); - this.cleanExecutableItemKeyMapByTempId(itemObj.children); + this.cleanItemRetriesChain(itemObj.children); this.cleanMap(itemObj.children); this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ); diff --git a/spec/report-portal-client.spec.js b/spec/report-portal-client.spec.js index fbf51c0..787d1a1 100644 --- a/spec/report-portal-client.spec.js +++ b/spec/report-portal-client.spec.js @@ -63,7 +63,7 @@ describe('ReportPortal javascript client', () => { }); }); - describe('calculateExecutableItemMapKey', () => { + describe('calculateItemRetriesChainMapKey', () => { it("should return correct parameter's string", () => { const client = new RPClient({ apiKey: 'test', @@ -71,7 +71,7 @@ describe('ReportPortal javascript client', () => { endpoint: 'https://abc.com', }); - const str = client.calculateExecutableItemMapKey('lId', 'pId', 'name', 'itemId'); + const str = client.calculateItemRetriesChainMapKey('lId', 'pId', 'name', 'itemId'); expect(str).toEqual('lId__pId__name__itemId'); }); @@ -83,7 +83,7 @@ describe('ReportPortal javascript client', () => { endpoint: 'https://abc.com', }); - const str = client.calculateExecutableItemMapKey('lId', 'pId', 'name'); + const str = client.calculateItemRetriesChainMapKey('lId', 'pId', 'name'); expect(str).toEqual('lId__pId__name__'); }); @@ -725,7 +725,7 @@ describe('ReportPortal javascript client', () => { promiseStart: Promise.resolve(), }, }; - spyOn(client.executableItemMap, 'get').and.resolveTo(); + spyOn(client.itemRetriesChainMap, 'get').and.resolveTo(); spyOn(client.restClient, 'create').and.resolveTo({}); spyOn(client, 'getUniqId').and.returnValue('4n5pxq24kpiob12og9'); @@ -735,7 +735,7 @@ describe('ReportPortal javascript client', () => { return expectAsync(result.promise).toBeResolved(); }); - it('should get previous try promise from executableItemMap if retry is true', () => { + it('should get previous try promise from itemRetriesChainMap if retry is true', () => { const client = new RPClient({ apiKey: 'startLaunchTest', endpoint: 'https://rp.us/api/v1', @@ -754,14 +754,14 @@ describe('ReportPortal javascript client', () => { promiseStart: Promise.resolve(), }, }; - spyOn(client, 'calculateExecutableItemMapKey').and.returnValue('id1__name__'); + spyOn(client, 'calculateItemRetriesChainMapKey').and.returnValue('id1__name__'); spyOn(client, 'getUniqId').and.returnValue('4n5pxq24kpiob12og9'); spyOn(client.map['4n5pxq24kpiob12og9'], 'promiseStart').and.resolveTo(); - spyOn(client.executableItemMap, 'get'); + spyOn(client.itemRetriesChainMap, 'get'); client.startTestItem({ retry: true }, 'id1'); - expect(client.executableItemMap.get).toHaveBeenCalledWith('id1__name__'); + expect(client.itemRetriesChainMap.get).toHaveBeenCalledWith('id1__name__'); }); });